Skip to content

Instantly share code, notes, and snippets.

@Randolio
Created September 26, 2024 19:55
Show Gist options
  • Save Randolio/907366210d9574feaf5d58ab2ce5d022 to your computer and use it in GitHub Desktop.
Save Randolio/907366210d9574feaf5d58ab2ce5d022 to your computer and use it in GitHub Desktop.
Vehicle Wipe
local wipeTimer = 60 -- Every hour
local function canDeleteVehicle(veh)
local ped = GetPedInVehicleSeat(veh, -1)
return not Entity(veh)?.state.keepVehicle and (ped == 0 or not IsPedAPlayer(ped))
end
local function clearAllVehicles()
TriggerClientEvent('ox_lib:notify', -1, {
title = 'Vehicle wipe in 30 seconds. Please sit in the driver seat of your vehicle.',
showDuration = true, duration = 10000, position = 'top',
style = { backgroundColor = '#c20808', color = '#ffffff', width = 'fit-content', height = 'fit-content' },
icon = 'car', iconColor = '#ffffff'
})
SetTimeout(30000, function()
local vehicles = GetGamePool('CVehicle')
for i = 1, #vehicles do
local veh = vehicles[i]
if DoesEntityExist(veh) and canDeleteVehicle(veh) then
DeleteEntity(veh)
end
end
TriggerClientEvent('ox_lib:notify', -1, {
title = 'Vehicle wipe complete.',
showDuration = true, duration = 5000, position = 'top',
style = { backgroundColor = '#048c3b', color = '#ffffff', width = 'fit-content', height = 'fit-content'},
icon = 'car', iconColor = '#ffffff'
})
end)
end
SetInterval(clearAllVehicles, wipeTimer * 60000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment