diff --git a/resources/[jobs]/[weapons]/force-sling/client/events.lua b/resources/[jobs]/[weapons]/force-sling/client/events.lua index 1debd244c..6f60c1999 100644 --- a/resources/[jobs]/[weapons]/force-sling/client/events.lua +++ b/resources/[jobs]/[weapons]/force-sling/client/events.lua @@ -12,7 +12,6 @@ local function cleanupEntities() return false end - -- Sicherheitsprüfung für Sling if Sling then if Sling.object then safeDelete(Sling.object) @@ -32,23 +31,19 @@ local function cleanupEntities() Sling.currentAttachedAmount = 0 end - -- Cleanup other players weapons - 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 + 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 - otherPlayersWeapons[playerId] = nil end + otherPlayersWeapons[playerId] = nil end collectgarbage("collect") end --- Verzögere die Registrierung der Events bis Sling initialisiert ist CreateThread(function() while not Sling do Wait(100) @@ -85,9 +80,7 @@ AddEventHandler('force-sling:client:syncWeapons', function(playerId, weaponData, local targetPed = GetPlayerPed(GetPlayerFromServerId(playerId)) if not targetPed or not DoesEntityExist(targetPed) then return end - if not otherPlayersWeapons[playerId] then - otherPlayersWeapons[playerId] = {} - end + otherPlayersWeapons[playerId] = otherPlayersWeapons[playerId] or {} Utils:CreateAndAttachWeapon( weaponData.weaponName, diff --git a/resources/[jobs]/[weapons]/force-sling/fxmanifest.lua b/resources/[jobs]/[weapons]/force-sling/fxmanifest.lua index 75fd39f39..b8d6b361f 100644 --- a/resources/[jobs]/[weapons]/force-sling/fxmanifest.lua +++ b/resources/[jobs]/[weapons]/force-sling/fxmanifest.lua @@ -13,7 +13,7 @@ dependencies { shared_scripts { '@ox_lib/init.lua', - 'client/shared.lua', -- Moved here to be loaded first + "shared/variables.lua", -- Add this line "shared/*.lua", "config.lua", } @@ -29,7 +29,7 @@ server_scripts { client_scripts { "client/utils.lua", - "client/functions.lua", -- Moved before events + "client/functions.lua", "client/events.lua", "client/main.lua", "client/custom/frameworks/*.lua", diff --git a/resources/[jobs]/[weapons]/force-sling/shared/variables.lua b/resources/[jobs]/[weapons]/force-sling/shared/variables.lua new file mode 100644 index 000000000..c0642eb39 --- /dev/null +++ b/resources/[jobs]/[weapons]/force-sling/shared/variables.lua @@ -0,0 +1 @@ +otherPlayersWeapons = {}