Tails Posted November 5, 2012 Share Posted November 5, 2012 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. Link to comment
Castillo Posted November 5, 2012 Share Posted November 5, 2012 'vehicles' is a table, you must loop it to get the vehicle elements. Like this: for _, vehicle in ipairs ( vehicles ) do -- Your code end Link to comment
Tails Posted November 5, 2012 Author Share Posted November 5, 2012 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) Link to comment
Castillo Posted November 5, 2012 Share Posted November 5, 2012 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 ) Link to comment
Tails Posted November 5, 2012 Author Share Posted November 5, 2012 Thank you very very much! Link to comment
Tails Posted November 6, 2012 Author Share Posted November 6, 2012 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? Link to comment
Tete omar Posted November 6, 2012 Share Posted November 6, 2012 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) Link to comment
Tails Posted November 6, 2012 Author Share Posted November 6, 2012 It doesn't respawn it to its original spawn location. Link to comment
Tete omar Posted November 6, 2012 Share Posted November 6, 2012 It doesn't respawn it to its original spawn location. But i tested it , and it works with me , try copy the code again. Link to comment
Tails Posted November 6, 2012 Author Share Posted November 6, 2012 No it works, but the vehicle doesn't respawn at say the parking lot where it was originally parked. Link to comment
Tete omar Posted November 6, 2012 Share Posted November 6, 2012 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 ? Link to comment
Tails Posted November 6, 2012 Author Share Posted November 6, 2012 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. Link to comment
TAPL Posted November 6, 2012 Share Posted November 6, 2012 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. Link to comment
Tails Posted November 6, 2012 Author Share Posted November 6, 2012 Because I need them on a different timer. Exploded vehicles should spawn after ~30 seconds, vehicles that haven't should respawn after x minutes. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now