Jump to content

HELP| Timer doesn't stop!


Recommended Posts

Hey guys. I tried to killTimer after a player gets back to his jobcar. But it doesn't work for me. there isn't even a outputChatBox (I tried it out but deleted it for this showing)

 

 local Timer= setTimer( function () JobIcon=createBlip(1611.9,-1891.8,13.60,40, 1, 0, 0, 0, 255, 0, 99999.0)
            outputChatBox("Der Job wurde beendet!",myPlayer,255,0,0)

            destroyElement(jobcar)
            destroyElement(markers1)

       end,5000,0)

end


addEventHandler("onPlayerVehicleEnter",getRootElement(), function(vehicleID,leftSeat,jackerPlayer)
local vehicleJ=getPedOccupiedVehicle(thePlayer)
--jobcar is defined at the top of my script as 'createVehicle(512,....)--
if vehicleJ == jobcar     and
isTimer(Timer) then
    killTimer(Timer)      
end
          outputChatBox("Du bist rechtzeitig zurückgekehrt!",myPlayer,0,255,0,true)
      outputChatBox("Drücke 'B' um die Warnleuchte einzuschalten!",myPlayer,255,135,10,true)    

end)   

 local Timer= setTimer( function () JobIcon=createBlip(1611.9,-1891.8,13.60,40, 1, 0, 0, 0, 255, 0, 99999.0)
			outputChatBox("Der Job wurde beendet!",myPlayer,255,0,0)

			destroyElement(jobcar)
			destroyElement(markers1)

	   end,5000,0)

end


addEventHandler("onPlayerVehicleEnter",getRootElement(), function(vehicleID,leftSeat,jackerPlayer)
local vehicleJ=getPedOccupiedVehicle(player)
--jobcar is defined at the top of my script as 'createVehicle(512,....)--
if vehicleJ == jobcar	 and
isTimer(Timer) then
	killTimer(Timer)	  
end
		  outputChatBox("Du bist rechtzeitig zurückgekehrt!",myPlayer,0,255,0,true) --translation: You came back in time! --
	  outputChatBox("Drücke 'B' um die Warnleuchte einzuschalten!",myPlayer,255,135,10,true)	

end)	

 

Link to comment

First of all, the second argument in outputChatBox 'myPlayer' isn't valid and not defined anywhere in the timer 'Timer'.

Also, onPlayerVehicleEnter first parameter is the vehicle being entered and not the VehicleID. So no need for 'getPedOccupiedVehicle' to get the vehicle element. Even using it this way wouldn't be correct I supose.

Link to comment
On 3/19/2018 at 22:17, GGR|Takashi said:

Okay thanks...actually I tried to apply this function on my created Vehicle "jobcar" but I don't know how to do that...could u please help me? P.S. the 'jobcar' = Baggage / ID =512


Try this.

addEventHandler("onPlayerVehicleEnter",getRootElement(), function(vehicleID,leftSeat,jackerPlayer)
local vehicleJ=getPedOccupiedVehicle(player)
--jobcar is defined at the top of my script as 'createVehicle(512,....)--
if getElementModel(vehicleJ) == jobcar and
isTimer(Timer) then
	killTimer(Timer)	  
end
	outputChatBox("Du bist rechtzeitig zurückgekehrt!",myPlayer,0,255,0,true) --translation: You came back in time! --
	outputChatBox("Drücke 'B' um die Warnleuchte einzuschalten!",myPlayer,255,135,10,true)	
end)

Just have to add getElementModel to check what the ID of vehicleJ is and if it is the same as the ID of jobcar.

Edited by Skully
Link to comment

Hey Debug: Bad argument @'getElementModel' [expected element at argument 1, got Boolean]
Bad argument @'getPedOccupiedVehicle' [expected ped at argument 1, got nil]

....

       end
       setTimer(jobfin,30000,0)
end

addEventHandler("onPlayerVehicleEnter",getRootElement(), function(vehicleID,leftSeat,jackerPlayer)
local carjob=getPedOccupiedVehicle(player)
    if getElementModel(carjob) ==jobcar and isTimer(jobfin) then
      killTimer (jobfin)
      outputChatBox("Du bist rechtzeitig zurückgekehrt!",player,0,255,0,true)
    end
        
end)       

 

any solution thanks?!

Link to comment

No I thought 'player' is global known. how do I do that?

local player=getLocalPlayer(player)

is it right? And do I need to add it to the serverside script or do I need to trigger it client side and if so, how do I do that?

Edited by GGR|Takashi
Link to comment
6 hours ago, WorthlessCynomys said:

On client side, you can point to the local player with the word localPlayer. Like:


getPedOccupiedVehicle(localPlayer) 

 

Do I understand right?!: I write to the serverside script :

local vehicleJ= getPedOccupiedVehicle(localPlayer)

sorry. :/ ^^

Link to comment
Just now, WorthlessCynomys said:

No. That only works on client. Sorry

Well but how can I do it that the timer only stops when the player enters a jobcar...currently the timer stops for each vehicle.... currently players could cheat...just leave the jobcar and start to use their private car like infernus. Can you help me with that?

Link to comment
6 minutes ago, GGR|Takashi said:

Do I understand right?!: I write to the serverside script :


local vehicleJ= getPedOccupiedVehicle(localPlayer)

sorry. :/ ^^

You can only use localPlayer on a clientside script, if it is serverside you should use source.

source will be defined by onPlayerVehicleEnter as the player who is the one entering a vehicle. Because you are trying to check if the vehicle the player is entering is the same as "jobcar" which you have defined as 512, you do not need to get the player, onPlayerVehicleEnter will forward the theVehicle which is the vehicle element itself, and you can just check the vehicle's ID.

This is the finished code:

	addEventHandler("onPlayerVehicleEnter", getRootElement(), function(theVehicle, leftSeat, jackerPlayer)
	--jobcar is defined at the top of my script as 'createVehicle(512,....)--
	if getElementModel(theVehicle) == jobcar and isTimer(Timer) then
		killTimer(Timer)	  
	end
	outputChatBox("Du bist rechtzeitig zurückgekehrt!",myPlayer,0,255,0,true) --translation: You came back in time! --
	outputChatBox("Drücke 'B' um die Warnleuchte einzuschalten!",myPlayer,255,135,10,true)	
end)

 

Edited by Skully
Link to comment
12 minutes ago, Skully said:

You can only use localPlayer on a clientside script, if it is serverside you should use source.

source will be defined by onPlayerVehicleEnter as the player who is the one entering a vehicle. Because you are trying to check if the vehicle the player is entering is the same as "jobcar" which you have defined as 512, you do not need to get the player, onPlayerVehicleEnter will forward the theVehicle which is the vehicle element itself, and you can just check the vehicle's ID.

This is the finished code:


	addEventHandler("onPlayerVehicleEnter", getRootElement(), function(theVehicle, leftSeat, jackerPlayer)
	--jobcar is defined at the top of my script as 'createVehicle(512,....)--
	if getElementModel(theVehicle) == jobcar and isTimer(Timer) then
		killTimer(Timer)	  
	end
	outputChatBox("Du bist rechtzeitig zurückgekehrt!",myPlayer,0,255,0,true) --translation: You came back in time! --
	outputChatBox("Drücke 'B' um die Warnleuchte einzuschalten!",myPlayer,255,135,10,true)	
end)

 

I just copied your code to try it out but the problem is, that the output still comes on each vehicle (even 3 times in a row) and the timer doesn't stop (after x seconds the jobcar despawns. :/) thanks for ur constant help.

Link to comment
10 minutes ago, GGR|Takashi said:

I just copied your code to try it out but the problem is, that the output still comes on each vehicle (even 3 times in a row) and the timer doesn't stop (after x seconds the jobcar despawns. :/) thanks for ur constant help.

What are you trying to do? Kill a timer when a player gets into the jobcar vehicle?

Link to comment
Just now, Skully said:

What are you trying to do? Kill a timer when a player gets into the jobcar vehicle?

yes. when you get out of the jobcar there comes a message that the player needs to get back within 30 seconds otherwise the job stops and the idea is that the timer stops after the player gets back to his jobcar. :)

Link to comment
Just now, GGR|Takashi said:

yes. when you get out of the jobcar there comes a message that the player needs to get back within 30 seconds otherwise the job stops and the idea is that the timer stops after the player gets back to his jobcar. :)

Then this code should work. Can you show me the code which defines jobcar?

Link to comment
3 minutes ago, GGR|Takashi said:

	jobcar= createVehicle(485, 1655.03, -1837.87, 13.58, 0, 0, 90)

 

There is the issue, jobcar is not a vehicle ID, it is a vehicle element and we are trying to compare the vehicleID with a element.

So in our original eventHandler, we don't need to get the element model at all, we can just compare the two elements to see if it is the same vehicle.

	addEventHandler("onPlayerVehicleEnter", getRootElement(), function(theVehicle, leftSeat, jackerPlayer)

	if (theVehicle == jobcar) and isTimer(Timer) then -- Check to see if theVehicle is the jobcar, and if timer is exists.
		killTimer(Timer)	  
	end
	outputChatBox("Du bist rechtzeitig zurückgekehrt!",myPlayer,0,255,0,true) --translation: You came back in time! --
	outputChatBox("Drücke 'B' um die Warnleuchte einzuschalten!",myPlayer,255,135,10,true)	
end)

 

Edited by Skully
Link to comment
13 minutes ago, Skully said:

There is the issue, jobcar is not a vehicle ID, it is a vehicle element and we are trying to compare the vehicleID with a element.

So in our original eventHandler, we don't need to get the element model at all, we can just compare the two elements to see if it is the same vehicle.


	addEventHandler("onPlayerVehicleEnter", getRootElement(), function(theVehicle, leftSeat, jackerPlayer)

	if (theVehicle == jobcar) and isTimer(Timer) then -- Check to see if theVehicle is the jobcar, and if timer is exists.
		killTimer(Timer)	  
	end
	outputChatBox("Du bist rechtzeitig zurückgekehrt!",myPlayer,0,255,0,true) --translation: You came back in time! --
	outputChatBox("Drücke 'B' um die Warnleuchte einzuschalten!",myPlayer,255,135,10,true)	
end)

 

I hoped so that it work but it doesn't work.... the output is shown on each vehicle like before and the timer still runs out ....the timer doesn't stop. :/ sorry for the inconvenience... I copied ur code completely... I don't know whaats wrong there. ... I reply tomorrow need to lay me down now.

Link to comment
5 minutes ago, GGR|Takashi said:

I hoped so that it work but it doesn't work.... the output is shown on each vehicle like before and the timer still runs out ....the timer doesn't stop. :/ sorry for the inconvenience... I copied ur code completely... I don't know whaats wrong there. ... I reply tomorrow need to lay me down now.

Then I don't think the timer exists. isTimer might be returning false. You should test it with some outputDebugString's and see if the timer is being made or not.

Also, if you don't want the messages to appear every time when a player gets in a car, just move them into the vehicle and timer check.

if (theVehicle == jobcar) and isTimer(Timer) then -- Check to see if theVehicle is the jobcar, and if timer is exists.
    killTimer(Timer)
    outputChatBox("Du bist rechtzeitig zurückgekehrt!", myPlayer, 0, 255, 0) --translation: You came back in time! --
    outputChatBox("Drücke 'B' um die Warnleuchte einzuschalten!", myPlayer, 255, 135, 10)	
end

 

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