Jump to content

Ajuda KillTimer


Recommended Posts

function pedro(frontLeft, rearLeft, frontRight, rearRight)
	if localPlayer == getLocalPlayer() then
		local theVehicle = getPedOccupiedVehicle ( localPlayer )
		for i, vehiclea in ipairs(getElementsByType("vehicle")) do 
			local speedX, speedY, speedZ = getElementVelocity ( vehiclea  )
			local actualSpeed = (speedX^2 + speedY^2 + speedZ^2)^(0.5) 
			local KMH = math.floor(actualSpeed*180)	
			local frontLeft, rearLeft, frontRight, rearRight = getVehicleWheelStates ( theVehicle ) 
			if frontLeft == 1 and theVehicle and KMH > 29 then
				outputChatBox(""..frontLeft)
				timer_Varible = setTimer(function()triggerServerEvent ( "someRoda1", root)end,5000,1)
				outputChatBox(KMH)
			else
				if frontLeft == 1 and theVehicle and KMH < 29 then
					if isTimer(timer_Varible) then
						killTimer(timer_Varible)
						timer_Varible=nil
						outputChatBox("AFF")
					end	
				end	
			end	
		end	
	end	
end
..

O evento é "onClientRender".

não esta dando kill no timer, me ajuda pfvr.

Link to comment
  • Moderators

Verifique se o timer já está ativo, na linha 9. Fora isso, também tem um loop em todos veículo - a velocidade verificada será dos veículos do server e não do veículo do jogador local (se é isso que você quer fazer).

  • Like 1
Link to comment

Como assim meu xará setTimer dentro de onClientRender?

 

o correto seria crie um setTimer dentro da função onde esta ligado o evento someRoda1

após isso criar um outro evento dando kill no timer, tipo esse:

addEvent("eventName",true)
addEventHandler("eventName",root,
function()
	timers = getTimers ( 5000 ) -- obtém os milissegundo (ms) existentes 
	for timerKey, timerValue in ipairs(timers) do
        killTimer ( timerValue )
        outputChatBox("tempo cancelado!")
	end
end)

e ai sim chamar quando você quiser cancelar o tempo.

Edited by Pedro861
  • Like 1
Link to comment
19 hours ago, Pedro861 said:

Como assim meu xará setTimer dentro de onClientRender?

 

o correto seria crie um setTimer dentro da função onde esta ligado o evento someRoda1

após isso criar um outro evento dando kill no timer, tipo esse:


addEvent("eventName",true)
addEventHandler("eventName",root,
function()
	timers = getTimers ( 5000 ) -- obtém os milissegundo (ms) existentes 
	for timerKey, timerValue in ipairs(timers) do
        killTimer ( timerValue )
        outputChatBox("tempo cancelado!")
	end
end)

e ai sim chamar quando você quiser cancelar o tempo.

Obrigado, consegui dar killtimer pelo server, não esta exatamente desses jeito que vc quis dizer mas pelo menos me ajudou a refazer a parte server e funcionou. Muito obrigado mesmo @Pedro861 e @DNL291.

  • Like 1
Link to comment
  • Moderators
22 hours ago, Pedro861 said:

Como assim meu xará setTimer dentro de onClientRender?

 

o correto seria crie um setTimer dentro da função onde esta ligado o evento someRoda1

após isso criar um outro evento dando kill no timer, tipo esse:


addEvent("eventName",true)
addEventHandler("eventName",root,
function()
	timers = getTimers ( 5000 ) -- obtém os milissegundo (ms) existentes 
	for timerKey, timerValue in ipairs(timers) do
        killTimer ( timerValue )
        outputChatBox("tempo cancelado!")
	end
end)

e ai sim chamar quando você quiser cancelar o tempo.

Dependendo do que ele quer fazer, deixaria mais complicado fazer com o timer noutro lado. Mas pra obtê-lo como você disse é só usar getTimers(5000).

O timer dentro desse evento que é chamado múltiplas vezes por segundo, não é problema porque não vai ser executado continuamente (vai ter a variável do timer pra checar antes que a função seja chamada). Aquele loop em todos os veículo que eu não entendi - isso sim causa impacto pra performance dentro desse evento.

Edited by DNL291
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...