Jump to content

killTimer


pz1

Recommended Posts

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

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 by Lord Henry
  • Thanks 1
Link to comment
  • Moderators

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

 

  • Thanks 1
Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...