This commit is contained in:
Nordi98 2025-06-12 00:25:14 +02:00
parent 90cf348723
commit 619c6d40f6
4 changed files with 86 additions and 8 deletions

View file

@ -29,7 +29,6 @@ local function cleanupEntities()
collectgarbage("collect")
end

-- Add these event handlers
AddEventHandler('onResourceStart', function(resourceName)
if resourceName == GetCurrentResourceName() then
cleanupEntities()
@ -51,3 +50,43 @@ AddEventHandler('playerDropped', function()
cleanupEntities()
end)

RegisterNetEvent('force-sling:client:syncWeapons')
AddEventHandler('force-sling:client:syncWeapons', function(playerId, weaponData, action)
if playerId == cache.serverId then return end
if action == 'attach' then
local targetPed = GetPlayerPed(GetPlayerFromServerId(playerId))
if not targetPed or not DoesEntityExist(targetPed) then return end
if not otherPlayersWeapons[playerId] then
otherPlayersWeapons[playerId] = {}
end
Utils:CreateAndAttachWeapon(
weaponData.weaponName,
weaponData.weaponVal,
weaponData.coords,
targetPed
)
otherPlayersWeapons[playerId][weaponData.weaponName] = true
elseif action == 'detach' then
if otherPlayersWeapons[playerId] and otherPlayersWeapons[playerId][weaponData.weaponName] then
Utils:DeleteWeapon(weaponData.weaponName)
otherPlayersWeapons[playerId][weaponData.weaponName] = nil
end
end
end)

RegisterNetEvent('force-sling:client:cleanupPlayerWeapons')
AddEventHandler('force-sling:client:cleanupPlayerWeapons', function(playerId)
if otherPlayersWeapons[playerId] then
for weaponName, _ in pairs(otherPlayersWeapons[playerId]) do
Utils:DeleteWeapon(weaponName)
end
otherPlayersWeapons[playerId] = nil
end
end)