OrbTanT Posted February 7, 2015 Share Posted February 7, 2015 como posso fazer esse dxDrawRectangle funcionar com um timer no server side, por exemplo a cada 1s ele aumenta + 1 no tamanho do rectangle. tentei fazer da seguinte forma. mais nada acontence. teria que fazer um triggerClientEvent pra funcionar? client: addEventHandler("onClientRender", root, function() dxDrawRectangle(55, 478, atack, 20, tocolor(255, 100, 0, 255), false) dxDrawLine(54, 478, 304, 478, tocolor(255, 255, 255, 255), 1, false) dxDrawLine(304, 478, 304, 498, tocolor(255, 255, 255, 255), 1, false) dxDrawLine(54, 498, 304, 498, tocolor(255, 255, 255, 255), 1, false) dxDrawLine(54, 478, 54, 498, tocolor(255, 255, 255, 255), 1, false) dxDrawText("atacando territorio!", 53, 478, 304, 498, tocolor(255, 255, 255, 255), 0.65, "bankgothic", "center", "center", false, false, false, false, false) end ) server: processChecks = function() atack = atack + 1 end function startChecks() if(not isTimer(checkTimer)) then checkTimer = setTimer( processChecks, 1000, 0) end end Link to comment
n3wage Posted February 7, 2015 Share Posted February 7, 2015 Qual o problema em criar o timer do lado do cliente ? Link to comment
OrbTanT Posted February 7, 2015 Author Share Posted February 7, 2015 é que eu preciso de alguma forma verificar se o o dxRectangle tem um tamanho igual a 250, e se chegar a 250, killTimer e domina o territorio. o evento de dominar vai estar do lado do server. Link to comment
n3wage Posted February 7, 2015 Share Posted February 7, 2015 Faz alguma coisa Assim, Deve funcionar: Server: function iniciar__ ( ) triggerClientEvent ( root, "dominar_start", root ) outputChatBox ( "iniciando..." ) end addCommandHandler ( "dominar", iniciar__ ) Client: seg = 0 function dominar_start ( ) timer_ = setTimer ( function() seg = seg +1 end, 1000, 0 ) addEventHandler ( "onClientRender", root, dominar_render ) end addEvent ( "dominar_start", true ) addEventHandler ( "dominar_start", root, dominar_start ) function dominar_render () if seg >= 250 then removeEventHandler ( "onClientRender", root, dominar_render ) dominar_end() if isTimer ( timer_ ) then killTimer ( timer_ ) end end dxDrawRectangle(55, 478, seg, 20, tocolor(255, 100, 0, 255), false) dxDrawLine(54, 478, 304, 478, tocolor(255, 255, 255, 255), 1, false) dxDrawLine(304, 478, 304, 498, tocolor(255, 255, 255, 255), 1, false) dxDrawLine(54, 498, 304, 498, tocolor(255, 255, 255, 255), 1, false) dxDrawLine(54, 478, 54, 498, tocolor(255, 255, 255, 255), 1, false) dxDrawText("atacando territorio!", 53, 478, 304, 498, tocolor(255, 255, 255, 255), 0.65, "bankgothic", "center", "center", false, false, false, false, false) end function dominar_end ( ) outputChatBox ( "area dominada !!" ) --[[ aqui vc pode usar triggerServerEvent pra terminar de dominar; --]] seg = 0 end Link to comment
OrbTanT Posted February 7, 2015 Author Share Posted February 7, 2015 obrigado =), mesmo com timer e triggerServerEvent, não vai funcionar muito bem. teria que funcionar da seguinte forma, quando está aqui no server, quando fica >= 250 então domina, e pelo server msm add +1 no seg. mais não funciona. client: function dominar_start ( ) addEventHandler ( "onClientRender", root, dominar_render ) end addEvent ( "dominar_start", true ) addEventHandler ( "dominar_start", root, dominar_start ) function dominar_stop ( ) removeEventHandler ( "onClientRender", root, dominar_render ) end addEvent ( "dominar_stop", true ) addEventHandler ( "dominar_stop", root, dominar_stop ) function dominar_render () local seg = 0 dxDrawRectangle(55, 478, seg, 20, tocolor(255, 100, 0, 255), false) dxDrawLine(54, 478, 304, 478, tocolor(255, 255, 255, 255), 1, false) dxDrawLine(304, 478, 304, 498, tocolor(255, 255, 255, 255), 1, false) dxDrawLine(54, 498, 304, 498, tocolor(255, 255, 255, 255), 1, false) dxDrawLine(54, 478, 54, 498, tocolor(255, 255, 255, 255), 1, false) dxDrawText("atacando territorio!", 53, 478, 304, 498, tocolor(255, 255, 255, 255), 0.65, "bankgothic", "center", "center", false, false, false, false, false) end server: turf[id] = { } turf[id].col = col turf[id].area = radar turf[id].owner = owner or "server" turf[id].attackers = nil turf[id].seg = 0 setElementData ( turf[id].col, "turfId", id ) setElementData ( turf[id].col, "TurffingTable", turf[id] ) addEventHandler ( "onColShapeHit", turf[id].col, onColShapeHit ) addEventHandler ( "onColShapeLeave", turf[id].col, onColShapeLeave ) return turf[id] setTimer( function ( ) for id, data in pairs ( turf ) do if ( data.attackers ) then local players = { attackers = { }, owners = { } } local isGangInTurf = false local isOwnerInTurf = false for i, v in pairs ( getElementsWithinColShape ( data.col, "player") ) do local g = getPlayerTeam ( v ) if ( g == data.attackers ) then isGangInTurf = true table.insert ( players.attackers, v) elseif ( g == data.owner ) then isOwnerInTurf = true table.insert( players.owners, v ) end end local x, y, z = getElementPosition( data.col ) if ( isGangInTurf ) then if ( turf[id].owner == "server" ) then turf[id].seg = turf[id].seg + 1 if ( turf[id].seg >= 250 ) then outputChatBox( "A gang "..getTeamName(turf[id].attackers).." dominou o territorio "..getZoneName( x, y, z).."!.", root, 0, 255, 0) setTurfOwner( id, turf[id].attackers ) end end end for i, v in pairs ( players ) do for k, p in pairs ( v ) do end end end end end, 1000, 0) Link to comment
manawydan Posted February 9, 2015 Share Posted February 9, 2015 tente algo assim: local seg = 0 local oldTick = getTickCount() function dominar_start ( ) seg = 0 oldTick = getTickCount() addEventHandler ( "onClientRender", root, dominar_render ) end addEvent ( "dominar_start", true ) addEventHandler ( "dominar_start", root, dominar_start ) function dominar_stop ( ) removeEventHandler ( "onClientRender", root, dominar_render ) end addEvent ( "dominar_stop", true ) addEventHandler ( "dominar_stop", root, dominar_stop ) function dominar_render () if(getTickCount() - oldTick >=1000)then seg = seg+1 oldTick = getTickCount() end if(seg==225)then seg = 0 removeEventHandler ( "onClientRender", root, dominar_render ) else dxDrawRectangle(55, 478, seg, 20, tocolor(255, 100, 0, 255), false) dxDrawLine(54, 478, 304, 478, tocolor(255, 255, 255, 255), 1, false) dxDrawLine(304, 478, 304, 498, tocolor(255, 255, 255, 255), 1, false) dxDrawLine(54, 498, 304, 498, tocolor(255, 255, 255, 255), 1, false) dxDrawLine(54, 478, 54, 498, tocolor(255, 255, 255, 255), 1, false) dxDrawText("atacando territorio!", 53, 478, 304, 498, tocolor(255, 255, 255, 255), 0.65, "bankgothic", "center", "center", false, false, false, false, false) end end Link to comment
OrbTanT Posted February 9, 2015 Author Share Posted February 9, 2015 mais se eu deixar assim como no server side vou poder verificar se o dxRectangle está 250 de tamanho? Link to comment
manawydan Posted February 9, 2015 Share Posted February 9, 2015 voce pode usar triggers Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now