1
0
Fork 0
forked from Simnation/Main

Update functions.lua

This commit is contained in:
Nordi98 2025-06-12 22:03:04 +02:00
parent de099cd6d5
commit 9789a8fd12

View file

@ -106,36 +106,65 @@ function Sling:WeaponThread()
Sling.cachedAttachments[weaponName] = {} Sling.cachedAttachments[weaponName] = {}
end end
-- Check if player is in vehicle -- Erweiterte Checks für Spielerzustände
local isInVehicle = IsPedInAnyVehicle(playerPed, false) local isInVehicle = IsPedInAnyVehicle(playerPed, false)
local isSitting = IsPedUsingScenario(playerPed, "PROP_HUMAN_SEAT_CHAIR")
local isRagdoll = IsPedRagdoll(playerPed)
local shouldHideWeapons = isInVehicle or isSitting or isRagdoll
if weapon == weaponVal.name or isInVehicle then if weapon == weaponVal.name or shouldHideWeapons then
if DoesEntityExist(Sling.cachedAttachments[weaponName].obj) then if DoesEntityExist(Sling.cachedAttachments[weaponName].obj) then
Utils:DeleteWeapon(weaponName) Utils:DeleteWeapon(weaponName)
if shouldHideWeapons then
Sling:SyncWeaponAttachment(weaponName, nil, nil, 'detach')
end
end end
else else
if not DoesEntityExist(Sling.cachedAttachments[weaponName].obj) then if not DoesEntityExist(Sling.cachedAttachments[weaponName].obj) then
local coords = Sling.cachedPositions[weaponName] or Sling.cachedPresets[weaponName] or 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 } { 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)
if not shouldHideWeapons then
Sling:SyncWeaponAttachment(weaponName, weaponVal, coords, 'attach')
end
else else
if not IsEntityAttachedToAnyPed(Sling.cachedAttachments[weaponName].placeholder) then if not IsEntityAttachedToEntity(Sling.cachedAttachments[weaponName].placeholder, playerPed) then
Utils:DeleteWeapon(weaponName) Utils:DeleteWeapon(weaponName)
Sling:SyncWeaponAttachment(weaponName, nil, nil, 'detach')
end end
end end
end end
end end
CreateThread(function() CreateThread(function()
local lastVehicleState = false local lastState = {
inVehicle = false,
sitting = false,
ragdoll = false
}
while true do while true do
local weapon = GetSelectedPedWeapon(cache.ped) local playerPed = cache.ped
local isInVehicle = IsPedInAnyVehicle(cache.ped, false) local weapon = GetSelectedPedWeapon(playerPed)
local currentState = {
inVehicle = IsPedInAnyVehicle(playerPed, false),
sitting = IsPedUsingScenario(playerPed, "PROP_HUMAN_SEAT_CHAIR"),
ragdoll = IsPedRagdoll(playerPed)
}
if lastVehicleState ~= isInVehicle then -- Überprüfe, ob sich der Zustand geändert hat
lastVehicleState = isInVehicle local stateChanged = lastState.inVehicle ~= currentState.inVehicle or
if isInVehicle then 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 for weaponName, _ in pairs(Sling.cachedAttachments) do
if DoesEntityExist(Sling.cachedAttachments[weaponName].obj) then if DoesEntityExist(Sling.cachedAttachments[weaponName].obj) then
Utils:DeleteWeapon(weaponName) Utils:DeleteWeapon(weaponName)
@ -143,11 +172,12 @@ function Sling:WeaponThread()
end end
end end
else else
-- Füge Waffen wieder hinzu
for weaponName, weaponVal in pairs(Sling.cachedWeapons) do for weaponName, weaponVal in pairs(Sling.cachedWeapons) do
if not DoesEntityExist(Sling.cachedAttachments[weaponName]?.obj) then if not DoesEntityExist(Sling.cachedAttachments[weaponName]?.obj) then
local coords = Sling.cachedPositions[weaponName] or Sling.cachedPresets[weaponName] or 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 } { 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) Utils:CreateAndAttachWeapon(weaponName, weaponVal, coords, playerPed)
Sling:SyncWeaponAttachment(weaponName, weaponVal, coords, 'attach') Sling:SyncWeaponAttachment(weaponName, weaponVal, coords, 'attach')
end end
end end
@ -158,17 +188,18 @@ function Sling:WeaponThread()
Wait(1000) Wait(1000)
end end
if not isInVehicle then if not (currentState.inVehicle or currentState.sitting or currentState.ragdoll) 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, playerPed, weapon)
end end
end end
Wait(1000) Wait(500)
end end
end) end)
end end
function Sling:OnPositioningDone(coords, selectData) function Sling:OnPositioningDone(coords, selectData)
lib.hideTextUI() lib.hideTextUI()
Sling.inPositioning = false Sling.inPositioning = false