sling
This commit is contained in:
parent
6cee7331d1
commit
6e5993916b
2 changed files with 54 additions and 39 deletions
|
|
@ -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)
|
|||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue