pz1 Posted February 20, 2018 Share Posted February 20, 2018 Galera estou com um problema nesse script, quando o jogador está com 29 - de vida e ele recupera sua vida para 30+ ou timer continua rodando e mata o jogador. function Anim() local life = getElementHealth(localPlayer) if (tonumber (life) <= 30) then outputChatBox("Sua vida é:"..life) setPedAnimation(localPlayer, "CRACK", "crckdeth2") addEventHandler("onClientRender", root, deadRender) setElementData(getLocalPlayer(), "pubg:time", getTickCount() + 120000) unbindKey ( "lshift", "both", Anim ) TIMER = setTimer( function() setElementHealth(localPlayer, 0) removeEventHandler("onClientRender", root, deadRender) end, 120000, 1) if life < 1 then if isTimer (TIMER) then killTimer (TIMER) end end elseif isTimer (TIMER) then killTimer(TIMER) end end addEventHandler ( "onClientPlayerDamage", root, Anim ) Link to comment
Other Languages Moderators Lord Henry Posted February 21, 2018 Other Languages Moderators Share Posted February 21, 2018 (edited) Não entendi o objetivo deste script, ele deve matar o jogador após o tempo enquanto ele estiver com menos de 30HP e cancelar esse timer quando o jogador tem 30HP ou mais? Se for isso, faça assim: function Anim() if not getElementData (source, "timeDeath") then local life = getElementHealth (source) if (life <= 30) then outputChatBox ("Sua vida é: "..life) setPedAnimation (source, "CRACK", "crckdeth2") addEventHandler("onClientRender", root, deadRender) -- Supondo que essa função exista e esteja correta. -- setElementData (localPlayer, "pubg:time", getTickCount() + 120000) -- Não entendi a utilidade disto, então removi. setElementData (source, "timeDeath", true) -- unbindKey ("lshift", "both", Anim) -- Não entendi a utilidade disto, então removi. theTimer = setTimer (function() local life = getElementHealth (source) if (life <= 30) then -- setElementHealth (localPlayer, 0) -- Isso é o mesmo que killPed. killPed (source) removeEventHandler ("onClientRender", root, deadRender) setElementData (source, "timeDeath", false) end end, 120000, 1) elseif (life > 30) then -- Se a vida for maior que 30, então: if isTimer (theTimer) then -- Se existe o Timer, então: killTimer (theTimer) -- Cancela o Timer e não mata o jogador. end end end end addEventHandler ("onClientPlayerDamage", root, Anim) Edited February 21, 2018 by Lord Henry 1 Link to comment
pz1 Posted February 21, 2018 Author Share Posted February 21, 2018 Está funcionando, mas se o jogador estiver com 30- e recuperar seu hp até 30+ e seguida cair de uma altura que o deixe com 30- de hp, o timer continua aonde parou. Link to comment
DNL291 Posted February 22, 2018 Share Posted February 22, 2018 Tente (não testei): local TIMER = false local eventAdded function Anim() local life = getElementHealth(source) if (life < 31) then if isTimer(TIMER) then return end; setPedAnimation(source, "CRACK", "crckdeth2") addEventHandler("onClientRender", root, deadRender) eventAdded = true --setElementData(getLocalPlayer(), "pubg:time", getTickCount() + 120000) --unbindKey ( "lshift", "both", Anim ) TIMER = setTimer( function(player) if isElement(player) then killPed(player) end removeEventHandler("onClientRender", root, deadRender) eventAdded = nil end, 120000, 1, source) elseif life > 30 then check_reset() end end addEventHandler ( "onClientPlayerDamage", root, Anim ) addEventHandler( "onClientPedWasted", root, function() check_reset() end ) function check_reset() if isTimer(TIMER) then killTimer(TIMER) end if eventAdded then removeEventHandler("onClientRender", root, deadRender) eventAdded = nil end end 1 Link to comment
pz1 Posted February 22, 2018 Author Share Posted February 22, 2018 DNL291, continuou com o mesmo problema, irei mandar o código completo no seu pm. Link to comment
pz1 Posted February 23, 2018 Author Share Posted February 23, 2018 Status: Concluído Obrigado à #Roots, Lord Henry e DNL291. 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