forked from Simnation/Main
all
This commit is contained in:
parent
857f210323
commit
90cf348723
2 changed files with 49 additions and 9 deletions
|
@ -4,6 +4,7 @@ local function cleanupEntities()
|
||||||
if IsEntityAttachedToAnyPed(entity) then
|
if IsEntityAttachedToAnyPed(entity) then
|
||||||
DetachEntity(entity, true, true)
|
DetachEntity(entity, true, true)
|
||||||
end
|
end
|
||||||
|
NetworkUnregisterNetworkedEntity(entity)
|
||||||
DeleteObject(entity)
|
DeleteObject(entity)
|
||||||
SetEntityAsNoLongerNeeded(entity)
|
SetEntityAsNoLongerNeeded(entity)
|
||||||
return true
|
return true
|
||||||
|
@ -28,17 +29,25 @@ local function cleanupEntities()
|
||||||
collectgarbage("collect")
|
collectgarbage("collect")
|
||||||
end
|
end
|
||||||
|
|
||||||
AddEventHandler("onResourceStop", function(resource)
|
-- Add these event handlers
|
||||||
if resource ~= GetCurrentResourceName() then
|
AddEventHandler('onResourceStart', function(resourceName)
|
||||||
return
|
if resourceName == GetCurrentResourceName() then
|
||||||
end
|
|
||||||
|
|
||||||
Debug("info", "Resource stopping: " .. resource)
|
|
||||||
cleanupEntities()
|
cleanupEntities()
|
||||||
Debug("info", "Resource stopped: " .. resource)
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
RegisterNetEvent('QBCore:Client:OnPlayerLoaded')
|
||||||
|
AddEventHandler('QBCore:Client:OnPlayerLoaded', function()
|
||||||
|
cleanupEntities()
|
||||||
|
end)
|
||||||
|
|
||||||
|
AddEventHandler('onResourceStop', function(resourceName)
|
||||||
|
if resourceName == GetCurrentResourceName() then
|
||||||
|
cleanupEntities()
|
||||||
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
AddEventHandler('playerDropped', function()
|
AddEventHandler('playerDropped', function()
|
||||||
cleanupEntities()
|
cleanupEntities()
|
||||||
Debug("info", "Player dropped")
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
|
@ -95,7 +95,10 @@ function Sling:WeaponThread()
|
||||||
Sling.cachedAttachments[weaponName] = {}
|
Sling.cachedAttachments[weaponName] = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
if weapon == weaponVal.name then
|
-- Check if player is in vehicle
|
||||||
|
local isInVehicle = IsPedInAnyVehicle(playerPed, false)
|
||||||
|
|
||||||
|
if weapon == weaponVal.name or isInVehicle then
|
||||||
if DoesEntityExist(Sling.cachedAttachments[weaponName].obj) then
|
if DoesEntityExist(Sling.cachedAttachments[weaponName].obj) then
|
||||||
Utils:DeleteWeapon(weaponName)
|
Utils:DeleteWeapon(weaponName)
|
||||||
end
|
end
|
||||||
|
@ -113,15 +116,43 @@ function Sling:WeaponThread()
|
||||||
end
|
end
|
||||||
|
|
||||||
CreateThread(function()
|
CreateThread(function()
|
||||||
|
local lastVehicleState = false
|
||||||
|
|
||||||
while true do
|
while true do
|
||||||
local weapon = GetSelectedPedWeapon(cache.ped)
|
local weapon = GetSelectedPedWeapon(cache.ped)
|
||||||
|
local isInVehicle = IsPedInAnyVehicle(cache.ped, false)
|
||||||
|
|
||||||
|
-- Check for vehicle state change
|
||||||
|
if lastVehicleState ~= isInVehicle then
|
||||||
|
lastVehicleState = isInVehicle
|
||||||
|
if isInVehicle then
|
||||||
|
-- Remove all weapons when entering vehicle
|
||||||
|
for weaponName, _ in pairs(Sling.cachedAttachments) do
|
||||||
|
if DoesEntityExist(Sling.cachedAttachments[weaponName].obj) then
|
||||||
|
Utils:DeleteWeapon(weaponName)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
-- Reattach weapons when exiting vehicle
|
||||||
|
for weaponName, weaponVal in pairs(Sling.cachedWeapons) do
|
||||||
|
if not DoesEntityExist(Sling.cachedAttachments[weaponName]?.obj) then
|
||||||
|
local coords = Sling.cachedPositions[weaponName] or Sling.cachedPresets[weaponName] or
|
||||||
|
{ coords = { x = 0.0, y = -0.15, z = 0.0 }, rot = { x = 0.0, y = 0.0, z = 0.0 }, boneId = DEFAULT_BONE }
|
||||||
|
Utils:CreateAndAttachWeapon(weaponName, weaponVal, coords, cache.ped)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
while Sling.inPositioning do
|
while Sling.inPositioning do
|
||||||
Wait(1000)
|
Wait(1000)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if not isInVehicle then
|
||||||
for weaponName, weaponVal in pairs(Sling.cachedWeapons) do
|
for weaponName, weaponVal in pairs(Sling.cachedWeapons) do
|
||||||
handleWeaponAttachment(weaponName, weaponVal, cache.ped, weapon)
|
handleWeaponAttachment(weaponName, weaponVal, cache.ped, weapon)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
Wait(1000)
|
Wait(1000)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue