This commit is contained in:
Nordi98 2025-06-12 16:37:41 +02:00
parent 6cee7331d1
commit 6e5993916b
2 changed files with 54 additions and 39 deletions

View file

@ -12,57 +12,73 @@ local function cleanupEntities()
return false return false
end end
if Sling.object then -- Sicherheitsprüfung für Sling
safeDelete(Sling.object) if Sling then
Sling.object = nil if Sling.object then
end safeDelete(Sling.object)
Sling.object = nil
for weaponName, attachment in pairs(Sling.cachedAttachments) do
if attachment then
safeDelete(attachment.obj)
safeDelete(attachment.placeholder)
Sling.cachedAttachments[weaponName] = nil
end end
if Sling.cachedAttachments then
for weaponName, attachment in pairs(Sling.cachedAttachments) do
if attachment then
safeDelete(attachment.obj)
safeDelete(attachment.placeholder)
Sling.cachedAttachments[weaponName] = nil
end
end
end
Sling.currentAttachedAmount = 0
end end
-- Cleanup other players weapons -- Cleanup other players weapons
for playerId, weapons in pairs(otherPlayersWeapons) do if otherPlayersWeapons then
for weaponName, _ in pairs(weapons) do for playerId, weapons in pairs(otherPlayersWeapons) do
if Sling.cachedAttachments[weaponName] then for weaponName, _ in pairs(weapons) do
safeDelete(Sling.cachedAttachments[weaponName].obj) if Sling and Sling.cachedAttachments and Sling.cachedAttachments[weaponName] then
safeDelete(Sling.cachedAttachments[weaponName].placeholder) safeDelete(Sling.cachedAttachments[weaponName].obj)
safeDelete(Sling.cachedAttachments[weaponName].placeholder)
end
end end
otherPlayersWeapons[playerId] = nil
end end
otherPlayersWeapons[playerId] = nil
end end
Sling.currentAttachedAmount = 0
collectgarbage("collect") collectgarbage("collect")
end end
AddEventHandler('onResourceStart', function(resourceName) -- Verzögere die Registrierung der Events bis Sling initialisiert ist
if resourceName == GetCurrentResourceName() then CreateThread(function()
cleanupEntities() while not Sling do
end Wait(100)
end) end
RegisterNetEvent('QBCore:Client:OnPlayerLoaded') AddEventHandler('onResourceStart', function(resourceName)
AddEventHandler('QBCore:Client:OnPlayerLoaded', function() if resourceName == GetCurrentResourceName() then
cleanupEntities() cleanupEntities()
end) end
end)
AddEventHandler('onResourceStop', function(resourceName) RegisterNetEvent('QBCore:Client:OnPlayerLoaded')
if resourceName == GetCurrentResourceName() then AddEventHandler('QBCore:Client:OnPlayerLoaded', function()
cleanupEntities() cleanupEntities()
end end)
end)
AddEventHandler('playerDropped', function() AddEventHandler('onResourceStop', function(resourceName)
cleanupEntities() if resourceName == GetCurrentResourceName() then
cleanupEntities()
end
end)
AddEventHandler('playerDropped', function()
cleanupEntities()
end)
end) end)
RegisterNetEvent('force-sling:client:syncWeapons') RegisterNetEvent('force-sling:client:syncWeapons')
AddEventHandler('force-sling:client:syncWeapons', function(playerId, weaponData, action) AddEventHandler('force-sling:client:syncWeapons', function(playerId, weaponData, action)
if not Sling then return end
if playerId == cache.serverId then return end if playerId == cache.serverId then return end
if action == 'attach' then if action == 'attach' then
@ -91,6 +107,7 @@ end)
RegisterNetEvent('force-sling:client:cleanupPlayerWeapons') RegisterNetEvent('force-sling:client:cleanupPlayerWeapons')
AddEventHandler('force-sling:client:cleanupPlayerWeapons', function(playerId) AddEventHandler('force-sling:client:cleanupPlayerWeapons', function(playerId)
if not Sling then return end
if otherPlayersWeapons[playerId] then if otherPlayersWeapons[playerId] then
for weaponName, _ in pairs(otherPlayersWeapons[playerId]) do for weaponName, _ in pairs(otherPlayersWeapons[playerId]) do
Utils:DeleteWeapon(weaponName) Utils:DeleteWeapon(weaponName)
@ -101,3 +118,4 @@ end)

View file

@ -13,31 +13,28 @@ dependencies {
shared_scripts { shared_scripts {
'@ox_lib/init.lua', '@ox_lib/init.lua',
'client/shared.lua', -- Moved here to be loaded first
"shared/*.lua", "shared/*.lua",
"config.lua", "config.lua",
} }
server_scripts { server_scripts {
'version.lua', 'version.lua',
"server/events.lua", "server/events.lua",
"server/functions.lua", "server/functions.lua",
"server/main.lua", "server/main.lua",
"server/misc/*.lua", "server/misc/*.lua",
"server/callbacks.lua" "server/callbacks.lua"
} }
client_scripts { client_scripts {
"client/utils.lua", "client/utils.lua",
"client/functions.lua", -- Moved before events
"client/events.lua", "client/events.lua",
"client/functions.lua",
"client/main.lua", "client/main.lua",
"client/custom/frameworks/*.lua", "client/custom/frameworks/*.lua",
"client/custom/*.lua", "client/custom/*.lua",
"client/misc/*.lua", "client/misc/*.lua"
'client/shared.lua',
} }
files { files {