Jump to content

Ajuda KillTimer


Recommended Posts

Posted
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.

Posted

Quantas vezes sai no chat a msg da linha 12? Deve ser porque o código executa setTimer várias vezes durante o onClientRender.

Please do not PM me with scripting related question nor support, use the forums instead.

Posted

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

Please do not PM me with scripting related question nor support, use the forums instead.

Posted (edited)

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
Posted
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
Posted (edited)
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

Please do not PM me with scripting related question nor support, use the forums instead.

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...