Jump to content

Vehicle Respawning


Tails

Recommended Posts

Posted

Hey there, me again in need of your expertise...

Trying to create a vehicle respawn script for freeroam but can't manage to get it to work:

function respawnAllVehicles() 
vehicles = getElementsByType ( "vehicle" ) 
    if ( vehicles ) then 
    toggleVehicleRespawn ( vehicles, true ) -- enable vehicle respawn as it is necessary for the idle respawn to function 
    setVehicleIdleRespawnDelay ( vehicles, 20000 ) -- tell the server to respawn the vehicle 20 seconds after it's been left. 
    end 
end 
addEventHandler("onResourceStart", root, respawnAllVehicles) 

Debugging tells me it has bad arguments. Any ideas?

Any help is greatly appreciated.

Discord: its.tails

Posted

'vehicles' is a table, you must loop it to get the vehicle elements.

Like this:

for _, vehicle in ipairs ( vehicles ) do 
     -- Your code 
end 

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

I'm not sure how to add that piece of code:

function respawnAllVehicles() 
    for _, vehicle in ipairs ( vehicles ) do 
    vehicles = getElementsByType ( "vehicle" ) 
        if ( vehicles ) then 
        toggleVehicleRespawn ( vehicles, true ) -- enable vehicle respawn as it is necessary for the idle respawn to function 
        setVehicleIdleRespawnDelay ( vehicles, 20000 ) -- tell the server to respawn the vehicle 20 seconds after it's been left. 
        end 
    end 
end 
addEventHandler("onResourceStart", root, respawnAllVehicles) 

[03:05:59] ERROR: [freeroam scripts]\markers\vehicles.lua:7: bad argument #1 to

'ipairs' (table expected, got nil)

Discord: its.tails

Posted
function respawnAllVehicles ( ) 
    local vehicles = getElementsByType ( "vehicle" ) 
    for _, vehicle in ipairs ( vehicles ) do 
        if ( vehicles ) then 
            toggleVehicleRespawn ( vehicle, true ) -- enable vehicle respawn as it is necessary for the idle respawn to function 
            setVehicleIdleRespawnDelay ( vehicle, 20000 ) -- tell the server to respawn the vehicle 20 seconds after it's been left. 
        end 
    end 
end 
addEventHandler ( "onResourceStart", resourceRoot, respawnAllVehicles ) 

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

You're welcome.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

Hey there the script is working perfectly fine. However, the timer in the script below won't work properly alongside the above script.

function respawnExplodedVehicle() 
    setTimer(respawnVehicle, 20000, 1, source) -- The time it takes to respawn a vehicle (in ms) after it has exploded. 
end 
addEventHandler("onVehicleExplode", getRootElement(), respawnExplodedVehicle) 

Any ideas?

Discord: its.tails

Posted
Hey there the script is working perfectly fine. However, the timer in the script below won't work properly alongside the above script.
function respawnExplodedVehicle() 
    setTimer(respawnVehicle, 20000, 1, source) -- The time it takes to respawn a vehicle (in ms) after it has exploded. 
end 
addEventHandler("onVehicleExplode", getRootElement(), respawnExplodedVehicle) 

Any ideas?

Try this one

function respawnExplodedVehicle() 
    setTimer(destroyElement,5000,1,source) 
    local model=getElementModel(source) 
    local x, y, z = getElementPosition(source) 
    setTimer(createVehicle,20000,1,model,x,y,z) 
end 
addEventHandler("onVehicleExplode",root,respawnExplodedVehicle) 

F4MZM4.gif

Posted
No it works, but the vehicle doesn't respawn at say the parking lot where it was originally parked.

I didn't understand , you meant you wanna spawn the vehicle at a specified position after exploding ?

F4MZM4.gif

Posted

Exactly. Me and my team are running a freeroam map but we need a script that makes the vehicles respawn after they've been used or exploded. The two scripts above your posts work fine. It's just that the respawn timer for exploded vehicles won't work properly if I use both of the scripts at the same time. They'll respawn after a couple of seconds, 10 at most, while I've set the timer at 30 seconds.

Discord: its.tails

Posted
Hey there the script is working perfectly fine. However, the timer in the script below won't work properly alongside the above script.
function respawnExplodedVehicle() 
    setTimer(respawnVehicle, 20000, 1, source) -- The time it takes to respawn a vehicle (in ms) after it has exploded. 
end 
addEventHandler("onVehicleExplode", getRootElement(), respawnExplodedVehicle) 

Any ideas?

Why do you need this? setVehicleIdleRespawnDelay is already do the same thing.

CiTLh.png
Posted

Because I need them on a different timer. Exploded vehicles should spawn after ~30 seconds, vehicles that haven't should respawn after x minutes.

Discord: its.tails

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