Jump to content

[HELP] respawnVehicle


opnaiC

Recommended Posts

Posted
function respawnTimer ( source ) 
    for _, veh in ipairs (getElementsByType("vehicle", resourceRoot)) do 
     if getVehicleOccupant (veh) then 
       ourVehicle = getPedOccupiedVehicle (source)  
     end   
    end 
end 
setTimer (respawnTimer, 500, 0) 
  
function respawnOnExplode ( ) 
    for _, veh in ipairs (getElementsByType("vehicle", resourceRoot)) do 
      if veh == ourVehicle then 
        respawnVehicle (veh) 
        end 
    end 
end 
addEventHandler ("onVehicleExplode", root, respawnOnExplode) 

The vehicle that the player occupied should respawn on explode.

Posted

veh would be selecting all vehicles existing which would probably return the function because some elements may not be exploding, sync issues.

Try respawnVehicle(source) instead of "veh"

Posted

Also, you don't need an infinite loop to run above. It's pointless doing such, since it'll only use quite some CPU and not do much.

You can set the timer once inside the 'onVehicleExplode', would be better

Posted

Use this:

addEventHandler("onVehicleExplode", root, 
     function () 
          local time_ = 5 --in seconds. 
          setTimer(respawnVehicle, time_*1000, 1, source) 
     end 
) 

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