forked from Simnation/Main
sling
This commit is contained in:
parent
6cee7331d1
commit
6e5993916b
2 changed files with 54 additions and 39 deletions
|
@ -12,11 +12,14 @@ local function cleanupEntities()
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Sicherheitsprüfung für Sling
|
||||||
|
if Sling then
|
||||||
if Sling.object then
|
if Sling.object then
|
||||||
safeDelete(Sling.object)
|
safeDelete(Sling.object)
|
||||||
Sling.object = nil
|
Sling.object = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if Sling.cachedAttachments then
|
||||||
for weaponName, attachment in pairs(Sling.cachedAttachments) do
|
for weaponName, attachment in pairs(Sling.cachedAttachments) do
|
||||||
if attachment then
|
if attachment then
|
||||||
safeDelete(attachment.obj)
|
safeDelete(attachment.obj)
|
||||||
|
@ -24,45 +27,58 @@ local function cleanupEntities()
|
||||||
Sling.cachedAttachments[weaponName] = nil
|
Sling.cachedAttachments[weaponName] = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
Sling.currentAttachedAmount = 0
|
||||||
|
end
|
||||||
|
|
||||||
-- Cleanup other players weapons
|
-- Cleanup other players weapons
|
||||||
|
if otherPlayersWeapons then
|
||||||
for playerId, weapons in pairs(otherPlayersWeapons) do
|
for playerId, weapons in pairs(otherPlayersWeapons) do
|
||||||
for weaponName, _ in pairs(weapons) do
|
for weaponName, _ in pairs(weapons) do
|
||||||
if Sling.cachedAttachments[weaponName] then
|
if Sling and Sling.cachedAttachments and Sling.cachedAttachments[weaponName] then
|
||||||
safeDelete(Sling.cachedAttachments[weaponName].obj)
|
safeDelete(Sling.cachedAttachments[weaponName].obj)
|
||||||
safeDelete(Sling.cachedAttachments[weaponName].placeholder)
|
safeDelete(Sling.cachedAttachments[weaponName].placeholder)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
otherPlayersWeapons[playerId] = nil
|
otherPlayersWeapons[playerId] = nil
|
||||||
end
|
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
|
||||||
|
CreateThread(function()
|
||||||
|
while not Sling do
|
||||||
|
Wait(100)
|
||||||
|
end
|
||||||
|
|
||||||
|
AddEventHandler('onResourceStart', function(resourceName)
|
||||||
if resourceName == GetCurrentResourceName() then
|
if resourceName == GetCurrentResourceName() then
|
||||||
cleanupEntities()
|
cleanupEntities()
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
RegisterNetEvent('QBCore:Client:OnPlayerLoaded')
|
RegisterNetEvent('QBCore:Client:OnPlayerLoaded')
|
||||||
AddEventHandler('QBCore:Client:OnPlayerLoaded', function()
|
AddEventHandler('QBCore:Client:OnPlayerLoaded', function()
|
||||||
cleanupEntities()
|
cleanupEntities()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
AddEventHandler('onResourceStop', function(resourceName)
|
AddEventHandler('onResourceStop', function(resourceName)
|
||||||
if resourceName == GetCurrentResourceName() then
|
if resourceName == GetCurrentResourceName() then
|
||||||
cleanupEntities()
|
cleanupEntities()
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
AddEventHandler('playerDropped', function()
|
AddEventHandler('playerDropped', function()
|
||||||
cleanupEntities()
|
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)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue