Files
Elite-Gaming-FiveM/resources/CarWipe/client/entityiter.lua
T
Jacob 8e00e0890f Automatic server cleanup every hour.
+ Added CarWipe which automatically clears all the vehicles in the server every hour.
+ Can also use /delall to manually initiate it.
2022-04-23 18:36:49 +01:00

37 lines
818 B
Lua

local entityEnumerator = {
__gc = function(enum)
if enum.destructor and enum.handle then
enum.destructor(enum.handle)
end
enum.destructor = nil
enum.handle = nil
end
}
local function EnumerateEntities(initFunc, moveFunc, disposeFunc)
return coroutine.wrap(function()
local iter, id = initFunc()
if not id or id == 0 then
disposeFunc(iter)
return
end
local enum = {handle = iter, destructor = disposeFunc}
setmetatable(enum, entityEnumerator)
local next = true
repeat
coroutine.yield(id)
next, id = moveFunc(iter)
until not next
enum.destructor, enum.handle = nil, nil
disposeFunc(iter)
end)
end
function EnumerateVehicles()
return EnumerateEntities(FindFirstVehicle, FindNextVehicle, EndFindVehicle)
end