orcun99 Posted July 26, 2017 Share Posted July 26, 2017 (edited) I'm using manuel respawn script but I need auto respawn vehicles addEvent("respawnVehicle",true) function respawnVehicleAdmin(player,sec) if tonumber(sec) then setTimer(function(player) local vehicles = getElementsByType("vehicle") for i,v in ipairs(vehicles) do if not getVehicleOccupant(v,0) and not getVehicleOccupant(v,1) and not getVehicleOccupant(v,2) and not getVehicleOccupant(v,3) then respawnVehicle (v) end end end,sec * 1000 , 1 ,player ) --end end end addCommandHandler("vh",respawnVehicleAdmin) addEventHandler("respawnVehicle",getRootElement(),respawnVehicleAdmin) I need every 5min auto respawn empty car I'm using this resource : Edited July 26, 2017 by orcun99 Link to comment
myonlake Posted July 27, 2017 Share Posted July 27, 2017 (edited) You should make a timer using setTimer and then have that set to 1000 * 60 * 5 so it runs every 5 minutes. In there you can basically just copy paste the code from the manual respawn script like so: local vehicles = getElementsByType( "vehicle" ) for i, v in ipairs( vehicles ) do local _, occupant = next( getVehicleOccupants( v ) ) if ( not occupant ) then respawnVehicle( v ) end end Edited July 27, 2017 by myonlake 1 Link to comment
orcun99 Posted July 27, 2017 Author Share Posted July 27, 2017 (edited) 4 hours ago, myonlake said: You should make a timer using setTimer and then have that set to 1000 * 60 * 5 so it runs every 5 minutes. In there you can basically just copy paste the code from the manual respawn script like so: local vehicles = getElementsByType( "vehicle" ) for i, v in ipairs( vehicles ) do local _, occupant = next( getVehicleOccupants( v ) ) if ( not occupant ) then respawnVehicle( v ) end end okay I changed code but still don't work don't like this? addEvent("respawnVehicle",true) function respawnVehicleAdmin(player,sec) if tonumber(sec) then setTimer(function(player) local vehicles = getElementsByType( "vehicle" ) for i, v in ipairs( vehicles ) do local _, occupant = next( getVehicleOccupants( v ) ) if ( not occupant ) then respawnVehicle( v ) end end end,sec * 1000 * 60 * 5 , 1 ,player ) --end end end addCommandHandler("vh",respawnVehicleAdmin) addEventHandler("respawnVehicle",getRootElement(),respawnVehicleAdmin) Edited July 27, 2017 by orcun99 Link to comment
myonlake Posted July 27, 2017 Share Posted July 27, 2017 (edited) No. You need to make a new timer. Completely separate from the other one. addEventHandler( "onResourceStart", resourceRoot, function( ) setTimer( function( ) -- Function to execute -- Put the code in here end, 1000 * 60 * 5, -- Time in milliseconds (5 minutes) 0 -- Times to repeat (0 = forever) ) end ) Edited July 27, 2017 by myonlake onResourceStart 1 Link to comment
orcun99 Posted July 27, 2017 Author Share Posted July 27, 2017 3 minutes ago, myonlake said: No. You need to make a new timer. Completely separate from the other one. setTimer( function( ) -- Function to execute -- Put the code in here end, 1000 * 60 * 5, -- Time in milliseconds 0 -- Times to repeat ) thank you very much bro works 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