This commit is contained in:
Nordi98 2025-06-12 22:21:39 +02:00
parent f9b8f9ccad
commit 495d74e4dc
3 changed files with 113 additions and 59 deletions

View file

@ -106,7 +106,6 @@ function Sling:WeaponThread()
Sling.cachedAttachments[weaponName] = {}
end
-- Erweiterte Checks für Spielerzustände
local isInVehicle = IsPedInAnyVehicle(playerPed, false)
local isSitting = IsPedUsingScenario(playerPed, "PROP_HUMAN_SEAT_CHAIR")
local isRagdoll = IsPedRagdoll(playerPed)
@ -115,23 +114,14 @@ function Sling:WeaponThread()
if weapon == weaponVal.name or shouldHideWeapons then
if DoesEntityExist(Sling.cachedAttachments[weaponName].obj) then
Utils:DeleteWeapon(weaponName)
if shouldHideWeapons then
Sling:SyncWeaponAttachment(weaponName, nil, nil, 'detach')
end
Sling:SyncWeaponAttachment(weaponName, nil, nil, 'detach')
end
else
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, playerPed)
if not shouldHideWeapons then
Sling:SyncWeaponAttachment(weaponName, weaponVal, coords, 'attach')
end
else
if not IsEntityAttachedToEntity(Sling.cachedAttachments[weaponName].placeholder, playerPed) then
Utils:DeleteWeapon(weaponName)
Sling:SyncWeaponAttachment(weaponName, nil, nil, 'detach')
end
Utils:CreateAndAttachWeapon(weaponName, weaponVal, coords, playerPed, false)
Sling:SyncWeaponAttachment(weaponName, weaponVal, coords, 'attach')
end
end
end
@ -152,43 +142,34 @@ function Sling:WeaponThread()
ragdoll = IsPedRagdoll(playerPed)
}
-- Überprüfe, ob sich der Zustand geändert hat
local stateChanged = lastState.inVehicle ~= currentState.inVehicle or
lastState.sitting ~= currentState.sitting or
lastState.ragdoll ~= currentState.ragdoll
if stateChanged then
-- Aktualisiere den letzten Status
lastState = Utils:DeepCopy(currentState)
local shouldHideWeapons = currentState.inVehicle or currentState.sitting or currentState.ragdoll
if shouldHideWeapons then
-- Entferne alle Waffen
for weaponName, _ in pairs(Sling.cachedAttachments) do
if DoesEntityExist(Sling.cachedAttachments[weaponName].obj) then
-- Nur eigene Waffen verarbeiten
for weaponName, weaponVal in pairs(Sling.cachedWeapons) do
if shouldHideWeapons then
if DoesEntityExist(Sling.cachedAttachments[weaponName]?.obj) then
Utils:DeleteWeapon(weaponName)
Sling:SyncWeaponAttachment(weaponName, nil, nil, 'detach')
end
end
else
-- Füge Waffen wieder hinzu
for weaponName, weaponVal in pairs(Sling.cachedWeapons) do
else
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, playerPed)
Utils:CreateAndAttachWeapon(weaponName, weaponVal, coords, playerPed, false)
Sling:SyncWeaponAttachment(weaponName, weaponVal, coords, 'attach')
end
end
end
end
while Sling.inPositioning do
Wait(1000)
end
if not (currentState.inVehicle or currentState.sitting or currentState.ragdoll) then
-- Nur eigene Waffen verarbeiten
for weaponName, weaponVal in pairs(Sling.cachedWeapons) do
handleWeaponAttachment(weaponName, weaponVal, playerPed, weapon)
end