This commit is contained in:
Nordi98 2025-06-12 00:07:24 +02:00
parent 857f210323
commit 90cf348723
2 changed files with 49 additions and 9 deletions

View file

@ -4,6 +4,7 @@ local function cleanupEntities()
if IsEntityAttachedToAnyPed(entity) then
DetachEntity(entity, true, true)
end
NetworkUnregisterNetworkedEntity(entity)
DeleteObject(entity)
SetEntityAsNoLongerNeeded(entity)
return true
@ -28,17 +29,25 @@ local function cleanupEntities()
collectgarbage("collect")
end

AddEventHandler("onResourceStop", function(resource)
if resource ~= GetCurrentResourceName() then
return
-- Add these event handlers
AddEventHandler('onResourceStart', function(resourceName)
if resourceName == GetCurrentResourceName() then
cleanupEntities()
end
end)

Debug("info", "Resource stopping: " .. resource)
RegisterNetEvent('QBCore:Client:OnPlayerLoaded')
AddEventHandler('QBCore:Client:OnPlayerLoaded', function()
cleanupEntities()
Debug("info", "Resource stopped: " .. resource)
end)

AddEventHandler('onResourceStop', function(resourceName)
if resourceName == GetCurrentResourceName() then
cleanupEntities()
end
end)

AddEventHandler('playerDropped', function()
cleanupEntities()
Debug("info", "Player dropped")
end)