Jump to content

Remove timer


Recommended Posts

Olá, então. Estou fazendo um script de assalto, eu preciso com que quando a pessoa saia do marker cancele um timer que no caso é o Timer que irá dar o dinheiro pra ele.

 

function Entrou(thePlayer)
 outputChatBox("Entrou",255,0,0)
 
    setTimer(function()
		 outputChatBox("timer",255,0,0)
		end,5000,1)
end
addEventHandler("onClientMarkerHit", marker ,Entrou)


function Saiu()
 outputChatBox("Saiu",255,0,0)
end

addEventHandler("onClientMarkerLeave", marker ,())

Esse é meu código atual, eu preciso de ajuda pra cancelar aquele setTimer que tem dentro da função Entrou,  que no caso é pra quando ele sair do marker o tempo cancelar e ele não ganhar a grana do assalto fora da loja.

Link to comment
  • Other Languages Moderators

Coloque o timer em uma variável e depois dê killTimer nessa variável. Use também o isTimer para verificar se o timer existe antes de tentar dar killTimer nele.

function Entrou (hitPlayer)
	outputChatBox ("Entrou", 255, 0, 0)
	tempo = setTimer (function()
		outputChatBox ("timer", 255, 0, 0)
	end, 5000, 1)
end
addEventHandler ("onClientMarkerHit", marker, Entrou)

function Saiu (leavePlayer)
	if isTimer (tempo) then -- Verifica se o timer está ativo. Se estiver, então:
		killTimer (tempo) -- Cancela o timer.
		outputChatBox ("Saiu", 255, 0, 0)
	end
end
addEventHandler ("onClientMarkerLeave", marker, Saiu)

 

Edited by Lord Henry
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...