Jump to content

[HELP] function


Matevsz

Recommended Posts

Posted

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

Posted

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.

Posted

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 
  

Posted
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 

Posted

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.

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