local function getEntities(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, enumerator) local next = true repeat coroutine.yield(id) next, id = moveFunc(iter) until not next enum.destructor, enum.handle = nil, nil disposeFunc(iter) end) end CreateThread(function() while true do Citizen.Wait(600) theVehicles = getEntities(FindFirstVehicle, FindNextVehicle, EndFindVehicle) for entity in theVehicles do local veh = entity local health = GetEntityHealth(veh) NetworkRequestControlOfEntity(veh) SetEntityAsMissionEntity(veh, true, true) if DoesEntityExist(veh) then if GetEntityModel(veh) ~= GetHashKey("rubble") then if not IsEntityAttached(veh) then if health <= 0 then Citizen.InvokeNative(0xEA386986E786A54F, Citizen.PointerValueIntInitialized(veh)) if DoesEntityExist(veh) then DeleteEntity(veh) end end end end end end end end)