Jump to content

[Solved]Respawn empty vehicles


ManeXi

Recommended Posts

I would like to know the script to make a empty vehicle respawn, the conditions are that the vehicle should be empty during 60 seconds (60000 ms) this is the actual script i use to respawn exploted vehicles:

function respawnexploredcrs() 
    setTimer(respawnVehicle,15000,1,source) 
end 
addEventHandler("onVehicleExplode", getRootElement(), respawnexploredcrs) 

Edited by Guest
Link to comment

Create a loop to get all vehicles, use the loop to define whether any seat within such vehicle has been taken or not, then initiate the respawn, with setElementPosition or whatever you want. Then for the function handler, use the timer to handle it.

Link to comment

Use this function:

setVehicleIdleRespawnDelay(vehicle theVehicle, int timeDelay) 

Check the syntax on wiki for more details, this will respawn any vehicle that has been idle for the amount of time you set, apply it after the vehicle is created or in a loop upon start if all vehicles on your server is constant.

Important Note: toggleVehicleRespawn must be set to true for this function to have any effect
Link to comment
Use this function:
setVehicleIdleRespawnDelay(vehicle theVehicle, int timeDelay) 

Check the syntax on wiki for more details, this will respawn any vehicle that has been idle for the amount of time you set, apply it after the vehicle is created or in a loop upon start if all vehicles on your server is constant.

Important Note: toggleVehicleRespawn must be set to true for this function to have any effect

It works, but, how can i add various vehicles for example this vehicles:

( 400, 1552.552734375, -1624.3525390625, 13.3828125 ) 
( 400, 1577.2568359375, -1612.421875, 13.3828125 ) 

Link to comment
local veh = { 
    { 400, 1552.552734375, -1624.3525390625, 13.3828125 }, 
    { 400, 1577.2568359375, -1612.421875, 13.3828125 }, 
} 
  
for k,v in pairs(veh) do 
    local new_veh = createVehicle(v[1],v[2],v[3],v[4]) 
    toggleVehicleRespawn(new_veh, true) 
    setVehicleIdleRespawnDelay(new_veh, 60*1000) 
end 

Like that for instance, all vehicles in the table "veh" will spawn upon load and get instructions to re-spawn after 60 seconds when idle after used. It should be able to handle a large amount of vehicles without using any noticeable amount of system resources.

Edited by Guest
Link to comment

Thank you much walrus for efforing in helping me but i still not get succesful :/

If you could do it for me with this conditions:

  • The resource containing vehicles will be known as "VehMap"
    Respawn each 10000

Really if you do it, i will thank you much.

If you want i can make you any 3D model with Autodesk 3ds max(preferable for GTA San Andreas).

Link to comment

Finally i get it, i've put map file in the same resource of script file, and used this code:

for _ , vehicles in ipairs ( getElementsByType ("vehicle"), resourceRoot) do 
    toggleVehicleRespawn(vehicles, true) 
    setVehicleIdleRespawnDelay(vehicles, 10000) 
end 

And it works perfectly thank you much for helping Walrus :):):):)

#Solved

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