crazyde21 Posted February 27, 2014 Share Posted February 27, 2014 When the vehicle nobody, then setTimer 1 minute respawn vehicles, within 1 minute if someone on the bus on killTimer. otherwise one minute after the respawn of the vehicle! How to do that? Link to comment
Anubhav Posted February 27, 2014 Share Posted February 27, 2014 setTimer killTimer isPedInVehicle isTimer Link to comment
Jacobob14 Posted February 27, 2014 Share Posted February 27, 2014 this is what you mean? function respawnVehicles() outputChatBox("#FFFF00*Reiniciando vehiculos vacios en 30 segundos*", root, 255, 255, 255, true) outputChatBox("#0040FF*Empty vehicles will be respawned in 30 seconds*", root, 255, 255, 255, true) setTimer(function () local vehicles = getElementsByType ( "vehicle" ) outputChatBox("#0EF629*Vehiculos vacios han sido reiniciados*", root, 255, 255, 255, true) outputChatBox("#00ccFf*Empty Vehicles has been respawned*", root, 255, 255, 255, true) for k, vehicle in ipairs ( vehicles ) do if isEmpty( vehicle ) then respawnVehicle ( vehicle ) end end end, 30000, 1) end setTimer(respawnVehicles, 100000, 0) function isEmpty( vehicle ) local passengers = getVehicleMaxPassengers( vehicle ) if (type( passengers ) == 'number') then for seat = 0, passengers do if getVehicleOccupant( vehicle, seat ) then return false end end end return true end Link to comment
Moderators Citizen Posted February 27, 2014 Moderators Share Posted February 27, 2014 this is what you mean? function respawnVehicles() outputChatBox("#FFFF00*Reiniciando vehiculos vacios en 30 segundos*", root, 255, 255, 255, true) outputChatBox("#0040FF*Empty vehicles will be respawned in 30 seconds*", root, 255, 255, 255, true) setTimer(function () local vehicles = getElementsByType ( "vehicle" ) outputChatBox("#0EF629*Vehiculos vacios han sido reiniciados*", root, 255, 255, 255, true) outputChatBox("#00ccFf*Empty Vehicles has been respawned*", root, 255, 255, 255, true) for k, vehicle in ipairs ( vehicles ) do if isEmpty( vehicle ) then respawnVehicle ( vehicle ) end end end, 30000, 1) end setTimer(respawnVehicles, 100000, 0) function isEmpty( vehicle ) local passengers = getVehicleMaxPassengers( vehicle ) if (type( passengers ) == 'number') then for seat = 0, passengers do if getVehicleOccupant( vehicle, seat ) then return false end end end return true end Not really, when the last player of a vehicle just left it, the timer should be created to respawn that vehicle if nobody has entered in it after 1 minute: function isVehicleEmpty( vehicle ) if not isElement( vehicle ) or getElementType( vehicle ) ~= "vehicle" then return true end local passengers = getVehicleMaxPassengers( vehicle ) if type( passengers ) == 'number' then for seat = 0, passengers do if getVehicleOccupant( vehicle, seat ) then return false end end end return true end local RESPAWN_TIME = 1 --Time in minutes function watchForEmptyVehicle() for k, veh in ipairs (getElementsByType("vehicle")) do local respawnTimer = getElementData(veh, "respawnTimer") local isEmpty = isVehicleEmpty(veh) if isEmpty and not respawnTimer then local respawnTimer = setTimer(respawnVehicle, RESPAWN_TIME*60*1000, 1, veh) setElementData(veh, "respawnTimer", respawnTimer) elseif not isEmpty and respawnTimer then killTimer(respawnTimer) setElementData(veh, "respawnTimer", false) end end end setTimer(watchForEmptyVehicle, 5000, 0) (I didn't use the events onPlayerVehicle(Exit/Enter) because I didn't know what would return isVehicleEmpty if someone carjack partially (just kicking the driver out) or completly (really stole the car). So I used a setTimer) 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