toxicsmoke11 Posted March 29, 2014 Posted March 29, 2014 how would i make a script which would always destroy empty vehicles? please help,and please i dont want it to be laggy cause in some cases it can be laggy like if theres a check for it with setTimer i dont know how to do this
WhoAmI Posted March 29, 2014 Posted March 29, 2014 local minutes = 5 --here change how many u want setTimer ( minutes * 60000, 0, function ( ) local vehicles = getElementsByType ( "vehicle" ) if ( #vehicles > 0 ) then for _, vehicle in ipairs ( vehicles ) do local player = getPedOccupiedVehicle ( vehicle ) if ( not player ) then destroyElement ( vehicle ) end end end end ) Serverside.
toxicsmoke11 Posted March 29, 2014 Author Posted March 29, 2014 doesn't work WARNING:test\emptyveh.lua:3: Bad argument @ 'setTimer' [Expected function at argument 1, got number '60000']
Weii. Posted March 29, 2014 Posted March 29, 2014 local minutes = 5 --here change how many u want setTimer ( function ( ) local vehicles = getElementsByType ( "vehicle" ) if ( #vehicles > 0 ) then for _, vehicle in ipairs ( vehicles ) do local player = getPedOccupiedVehicle ( vehicle ) if ( not player ) then destroyElement ( vehicle ) end end end end , minutes * 60000, 0)
Castillo Posted March 29, 2014 Posted March 29, 2014 getPedOccupiedVehicle is used to get the vehicle out of a PLAYER/PED. To see if it's empty or not, use getVehicleOccupants. Or you can simply use this function: https://wiki.multitheftauto.com/wiki/IsVehicleEmpty San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
toxicsmoke11 Posted March 29, 2014 Author Posted March 29, 2014 getPedOccupiedVehicle is used to get the vehicle out of a PLAYER/PED.To see if it's empty or not, use getVehicleOccupants. Or you can simply use this function: https://wiki.multitheftauto.com/wiki/IsVehicleEmpty ive tried using isVehicleEmpty before and i've made a script which didnt work at all, but how can i make this script with getVehicleOccupants?
Castillo Posted March 29, 2014 Posted March 29, 2014 local minutes = 5 --here change how many u want setTimer ( function ( ) local vehicles = getElementsByType ( "vehicle" ) if ( #vehicles > 0 ) then for _, vehicle in ipairs ( vehicles ) do if isVehicleEmpty ( vehicle ) then destroyElement ( vehicle ) end end end end , minutes * 60000, 0) 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 San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
Castillo Posted March 29, 2014 Posted March 29, 2014 You're welcome. San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
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