Matevsz Posted September 10, 2014 Share Posted September 10, 2014 Hi, can someone tell me how to use the timer when the player is in the car this August timer stops, and when the player does not have a car it is 10 min timer and respawn your car to x, y, z Sorry for my english. Google Translate: D Link to comment
crismar Posted September 10, 2014 Share Posted September 10, 2014 If the vehicle does have a spawnpoint, you can use the function respawnVehicle. Either way, there are some factors you need to take in consideration: - Someone else might enter the vehicle while the timer runs - The person can spam timers, so you'd be better of having an array with all vehicles and their corresponding timers. local vehicleTimers function assignVehicleToTimer() for i, v in ipairs(getElementsByType("vehicle")) do vehicleTimers[i] = 0 end end addEventHandler("onResourceStart", resourceRoot, assignVehicleToTimer) function startTimerOnVehicleExit(thePlayer, theSeat, theJacker) if theSeat == 0 and not theJacker then if not isTimer(vehicleTimers[source]) then vehicleTimers[source] = setTimer(respawnIdleVehicle, 10*6000, 1, source) end end end function cancelTimerOnVehicleEnter(thePlayer) if isTimer(vehicleTimers[source]) then killTimer(vehicleTimers[source]) vehicleTimers[source] = 0 end end function respawnIdleVehicle(theVehicle) respawnVehicle(theVehicle) end Untested example, might have bugs. Link to comment
Matevsz Posted September 10, 2014 Author Share Posted September 10, 2014 just proof, if it works, and one more question how do you do when a player enters a marker that moves it to the car? Link to comment
crismar Posted September 10, 2014 Share Posted September 10, 2014 I don't see why my code won't work, I don't have the time to test it, I guess you can do that yourself. If you want to attach the marker to a car you just use createVehicle createMarker attachElements Link to comment
tosfera Posted September 10, 2014 Share Posted September 10, 2014 If the vehicle does have a spawnpoint, you can use the function respawnVehicle. Either way, there are some factors you need to take in consideration:- Someone else might enter the vehicle while the timer runs - The person can spam timers, so you'd be better of having an array with all vehicles and their corresponding timers. local vehicleTimers function assignVehicleToTimer() for i, v in ipairs(getElementsByType("vehicle")) do vehicleTimers[i] = 0 end end addEventHandler("onResourceStart", resourceRoot, assignVehicleToTimer) function startTimerOnVehicleExit(thePlayer, theSeat, theJacker) if theSeat == 0 and not theJacker then if not isTimer(vehicleTimers[source]) then vehicleTimers[source] = setTimer(respawnIdleVehicle, 10*6000, 1, source) end end end function cancelTimerOnVehicleEnter(thePlayer) if isTimer(vehicleTimers[source]) then killTimer(vehicleTimers[source]) vehicleTimers[source] = 0 end end function respawnIdleVehicle(theVehicle) respawnVehicle(theVehicle) end Untested example, might have bugs. this part is quite an overkill; function assignVehicleToTimer() for i, v in ipairs(getElementsByType("vehicle")) do vehicleTimers[i] = 0 end end addEventHandler("onResourceStart", resourceRoot, assignVehicleToTimer) just check if there is something filled in for the vehicle as an element. If so, there is an timer ( also check if the timer didn't run out of time etc ). You did so in this part; function startTimerOnVehicleExit(thePlayer, theSeat, theJacker) if theSeat == 0 and not theJacker then if not isTimer(vehicleTimers[source]) then vehicleTimers[source] = setTimer(respawnIdleVehicle, 10*6000, 1, source) end end end Link to comment
Matevsz Posted September 13, 2014 Author Share Posted September 13, 2014 What to do if your car is battered is how you zrespawni it will be repaired? and how to do to prevent exploding cars up to black smoke then stops the car in and can not go. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now