toxicsmoke11 Posted March 29, 2014 Share 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 Link to comment
WhoAmI Posted March 29, 2014 Share 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. Link to comment
toxicsmoke11 Posted March 29, 2014 Author Share Posted March 29, 2014 doesn't work WARNING:test\emptyveh.lua:3: Bad argument @ 'setTimer' [Expected function at argument 1, got number '60000'] Link to comment
Weii. Posted March 29, 2014 Share 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) Link to comment
Castillo Posted March 29, 2014 Share 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 Link to comment
toxicsmoke11 Posted March 29, 2014 Author Share 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? Link to comment
Castillo Posted March 29, 2014 Share 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 Link to comment
toxicsmoke11 Posted March 29, 2014 Author Share Posted March 29, 2014 Thank you Solidsnake14 ! 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