pz1 Posted February 20, 2018 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 )
Moderators Lord Henry Posted February 21, 2018 Moderators 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 Eu te ajudei ou achou meu comentário útil? Não esqueça de deixar um Thanks! Minhas contribuições para a comunidade: LordHenry - MTA Wiki Profile Inscreva-se no meu canal do YouTube: Lord Henry - Entertainment Discord Oficial do MTA: https://mtasa.com/discord Blacklist e Whitelist de Scripters: Planilha Por favor, não me envie mensagens privadas solicitando suporte. Crie um tópico no fórum em vez disso.
pz1 Posted February 21, 2018 Author 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.
DNL291 Posted February 22, 2018 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 Please do not PM me with scripting related question nor support, use the forums instead.
pz1 Posted February 22, 2018 Author Posted February 22, 2018 DNL291, continuou com o mesmo problema, irei mandar o código completo no seu pm.
pz1 Posted February 23, 2018 Author Posted February 23, 2018 Status: Concluído Obrigado à #Roots, Lord Henry e DNL291.
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