Jump to content

[HELP] function


Matevsz

Recommended Posts

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

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