forked from Simnation/Main
Update functions.lua
This commit is contained in:
parent
de099cd6d5
commit
9789a8fd12
1 changed files with 44 additions and 13 deletions
|
@ -106,36 +106,65 @@ function Sling:WeaponThread()
|
|||
Sling.cachedAttachments[weaponName] = {}
|
||||
end
|
||||
|
||||
-- Check if player is in vehicle
|
||||
-- Erweiterte Checks für Spielerzustände
|
||||
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
|
||||
Utils:DeleteWeapon(weaponName)
|
||||
if shouldHideWeapons then
|
||||
Sling:SyncWeaponAttachment(weaponName, nil, nil, 'detach')
|
||||
end
|
||||
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 IsEntityAttachedToAnyPed(Sling.cachedAttachments[weaponName].placeholder) then
|
||||
if not IsEntityAttachedToEntity(Sling.cachedAttachments[weaponName].placeholder, playerPed) then
|
||||
Utils:DeleteWeapon(weaponName)
|
||||
Sling:SyncWeaponAttachment(weaponName, nil, nil, 'detach')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
CreateThread(function()
|
||||
local lastVehicleState = false
|
||||
local lastState = {
|
||||
inVehicle = false,
|
||||
sitting = false,
|
||||
ragdoll = false
|
||||
}
|
||||
|
||||
while true do
|
||||
local weapon = GetSelectedPedWeapon(cache.ped)
|
||||
local isInVehicle = IsPedInAnyVehicle(cache.ped, false)
|
||||
local playerPed = cache.ped
|
||||
local weapon = GetSelectedPedWeapon(playerPed)
|
||||
local currentState = {
|
||||
inVehicle = IsPedInAnyVehicle(playerPed, false),
|
||||
sitting = IsPedUsingScenario(playerPed, "PROP_HUMAN_SEAT_CHAIR"),
|
||||
ragdoll = IsPedRagdoll(playerPed)
|
||||
}
|
||||
|
||||
if lastVehicleState ~= isInVehicle then
|
||||
lastVehicleState = isInVehicle
|
||||
if isInVehicle then
|
||||
-- Ü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
|
||||
Utils:DeleteWeapon(weaponName)
|
||||
|
@ -143,11 +172,12 @@ function Sling:WeaponThread()
|
|||
end
|
||||
end
|
||||
else
|
||||
-- Füge Waffen wieder hinzu
|
||||
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)
|
||||
Utils:CreateAndAttachWeapon(weaponName, weaponVal, coords, playerPed)
|
||||
Sling:SyncWeaponAttachment(weaponName, weaponVal, coords, 'attach')
|
||||
end
|
||||
end
|
||||
|
@ -158,17 +188,18 @@ function Sling:WeaponThread()
|
|||
Wait(1000)
|
||||
end
|
||||
|
||||
if not isInVehicle then
|
||||
if not (currentState.inVehicle or currentState.sitting or currentState.ragdoll) then
|
||||
for weaponName, weaponVal in pairs(Sling.cachedWeapons) do
|
||||
handleWeaponAttachment(weaponName, weaponVal, cache.ped, weapon)
|
||||
handleWeaponAttachment(weaponName, weaponVal, playerPed, weapon)
|
||||
end
|
||||
end
|
||||
|
||||
Wait(1000)
|
||||
Wait(500)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
|
||||
function Sling:OnPositioningDone(coords, selectData)
|
||||
lib.hideTextUI()
|
||||
Sling.inPositioning = false
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue