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

View file

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