Despawn safes via server onResourceStop instead of client-side stop

onClientResourceStop doesn't fire reliably for a resource's own
client scripts when it stops itself, so props never got cleaned up.
The server now broadcasts safe:despawn (the same path already used
for pickup) for every known safe on onResourceStop, right before the
resource actually goes down.

Bump to 1.1.6.
This commit is contained in:
Bxio 2026-08-03 12:01:58 +00:00
parent d21d04f606
commit cfe36cb3b2
4 changed files with 15 additions and 21 deletions

View File

@ -286,22 +286,3 @@ AddEventHandler('onClientResourceStart', function(resourceName)
if resourceName ~= GetCurrentResourceName() then return end
TriggerServerEvent('safe:requestSync')
end)
-- Roda ANTES do ambiente do script ser destruído, diferente de onClientResourceStart
-- (nesse ponto spawnedSafes já estaria vazio, pois o script já teria reiniciado)
AddEventHandler('onClientResourceStop', function(resourceName)
if resourceName ~= GetCurrentResourceName() then return end
dbg('onClientResourceStop disparado, limpando', tostring(next(spawnedSafes) and 'safes existentes' or 'nenhum safe'))
for id, ent in pairs(spawnedSafes) do
dbg('safe', id, 'entity', ent, 'DoesEntityExist antes:', DoesEntityExist(ent))
if ent and DoesEntityExist(ent) then
pcall(function() ox_target:removeLocalEntity(ent) end)
FreezeEntityPosition(ent, false)
DeleteObject(ent)
dbg('safe', id, 'DoesEntityExist depois do DeleteObject:', DoesEntityExist(ent))
end
spawnedSafes[id] = nil
end
end)

View File

@ -4,7 +4,7 @@ lua54 'yes'
author 'SeuNome'
description 'Sistema de safes com ox_inventory e ox_target'
version '1.1.5'
version '1.1.6'
-- Dependências
dependencies {

View File

@ -78,6 +78,19 @@ AddEventHandler('onResourceStart', function(resourceName)
end)
end)
-------------------------------------------------------
-- DESPAWNAR PARA TODOS ANTES DO RESOURCE PARAR
-- onClientResourceStop não é confiável para o próprio resource
-- se limpar sozinho no cliente, então avisamos daqui.
-------------------------------------------------------
AddEventHandler('onResourceStop', function(resourceName)
if resourceName ~= GetCurrentResourceName() then return end
for id in pairs(safes) do
TriggerClientEvent('safe:despawn', -1, id)
end
end)
-------------------------------------------------------

View File

@ -1,3 +1,3 @@
{
"version": "1.1.5"
"version": "1.1.6"
}