Klesh Posted January 25, 2012 Posted January 25, 2012 Hello, how i can set every time a function, for example i have a respawn vehicle script but i want to set it every 1 hour by itselft, setTimer dont work for it, added addEventHandler("onResourceStart", getRootElement(getThisResource()),respawnVehicles) setTimer(1800000, 1, respawnVehicles) No works, only works when the resource starts. Any recomendation? My resources : playerpartFromName: Exported function.
Castillo Posted January 25, 2012 Posted January 25, 2012 addEventHandler("onResourceStart", getRootElement(getThisResource()),respawnVehicles) setTimer(respawnVehicles, 1800000, 0) -- 0 = infinite. San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
Klesh Posted January 25, 2012 Author Posted January 25, 2012 local rElement = getRootElement() function respawnVehicles(player) outputChatBox("*In 60 seconds the system will returns the empty vehicles to the start.", rElement, 0, 220, 20, true) setTimer(function (player) local vehicles = getElementsByType ( "vehicle" ) outputChatBox("*Empty Vehicles has been respawned.", rElement, 0, 220, 20, true) outputDebugString(getPlayerName(player) .. " respawned vehicles.") for k, vehicle in ipairs ( vehicles ) do if isEmpty( vehicle ) then respawnVehicle ( vehicle ) end end end,180000, 0) end addEventHandler("onResourceStart", getRootElement(getThisResource()), respawnVehicles) 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 Why dont work. My resources : playerpartFromName: Exported function.
Castillo Posted January 25, 2012 Posted January 25, 2012 function respawnVehicles() local vehicles = getElementsByType ( "vehicle" ) outputChatBox("*Empty Vehicles has been respawned.", root, 0, 220, 20, true) for k, vehicle in ipairs ( vehicles ) do if isEmpty( vehicle ) then respawnVehicle ( vehicle ) end end end setTimer(respawnVehicles, 180000, 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 San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
Klesh Posted January 25, 2012 Author Posted January 25, 2012 Like always i have little but big mistakes, thanks a lot. My resources : playerpartFromName: Exported function.
Castillo Posted January 25, 2012 Posted January 25, 2012 You're welcome. San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
BorderLine Posted January 25, 2012 Posted January 25, 2012 and how you can put outputChatBox before to respawn to warnnin about this respawn i mean, if some player leave the car for kill or do something and while he is walking he will loose his car.. Actual Nick: [XGN]BorderLine Actual Clan: XLatino Actual Status: Staff, Mod Level 1 (BOSS)Yakuza - [vS]Yakuza - [sXE]Yakuza - [uG]Yakuza - [FTLS]Racing - [XGN]Borderline
Castillo Posted January 25, 2012 Posted January 25, 2012 Well, he could add a timer of like 10 seconds into the respawnVehicles function. San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
Klesh Posted January 26, 2012 Author Posted January 26, 2012 Do you mean set a timer warining to to warn the player, empty vehicles will be respawned? Also, i must set the timer with it? My resources : playerpartFromName: Exported function.
Castillo Posted January 26, 2012 Posted January 26, 2012 I meant this: function respawnVehicles() outputChatBox("*Empty vehicles will be respawned in 10 seconds.", root, 255, 255, 0) setTimer(function () local vehicles = getElementsByType ( "vehicle" ) outputChatBox("*Empty Vehicles has been respawned.", root, 0, 220, 20, true) for k, vehicle in ipairs ( vehicles ) do if isEmpty( vehicle ) then respawnVehicle ( vehicle ) end end end, 10000, 1) end setTimer(respawnVehicles, 180000, 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 San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
Klesh Posted January 26, 2012 Author Posted January 26, 2012 Thanks for making that edited code. My resources : playerpartFromName: Exported function.
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