fix(client): onCache('ped') haengt Props an den neuen Ped
Lint / Lint Resource (push) Has been cancelled
Lint / Lint Resource (push) Has been cancelled
ox_lib feuert die onCache-Callbacks ueber Citizen.CreateThreadNow, bevor der neue Wert in den Cache geschrieben wird (ox_lib/init.lua:188-199). cache.ped zeigt im Callback also noch auf den alten, bereits verschwundenen Ped - die Props waeren an genau den Ped gegangen, dessen Verschwinden der Handler abfangen soll. enableScuba, disableScuba, attachProp und attachGear nehmen den Ped jetzt als Parameter (default cache.ped), der onCache-Handler reicht den Callback-Wert durch. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
+25
-14
@@ -13,15 +13,19 @@ local TANK_MODEL = `p_s_scuba_tank_s`
|
|||||||
local MASK_BONE = 12844
|
local MASK_BONE = 12844
|
||||||
local TANK_BONE = 24818
|
local TANK_BONE = 24818
|
||||||
|
|
||||||
local function enableScuba()
|
--- @param ped number? default cache.ped - beim Model-Wechsel muss der neue Ped explizit rein
|
||||||
SetEnableScuba(cache.ped, true)
|
local function enableScuba(ped)
|
||||||
SetPedMaxTimeUnderwater(cache.ped, 2000.00)
|
ped = ped or cache.ped
|
||||||
|
SetEnableScuba(ped, true)
|
||||||
|
SetPedMaxTimeUnderwater(ped, 2000.00)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- @param outOfAir boolean? true wenn die Flasche leer ist statt die Ausrüstung abgelegt wurde
|
--- @param outOfAir boolean? true wenn die Flasche leer ist statt die Ausrüstung abgelegt wurde
|
||||||
local function disableScuba(outOfAir)
|
--- @param ped number? default cache.ped
|
||||||
SetEnableScuba(cache.ped, false)
|
local function disableScuba(outOfAir, ped)
|
||||||
SetPedMaxTimeUnderwater(cache.ped, outOfAir and config.maxTimeUnderwaterOutOfAir or config.maxTimeUnderwater)
|
ped = ped or cache.ped
|
||||||
|
SetEnableScuba(ped, false)
|
||||||
|
SetPedMaxTimeUnderwater(ped, outOfAir and config.maxTimeUnderwaterOutOfAir or config.maxTimeUnderwater)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function deleteGear()
|
local function deleteGear()
|
||||||
@@ -41,12 +45,12 @@ end
|
|||||||
--- Hängt ein Prop hart an einen Ped-Bone.
|
--- Hängt ein Prop hart an einen Ped-Bone.
|
||||||
--- useSoftPinning bleibt bewusst false: mit true darf die Physik-Engine die
|
--- useSoftPinning bleibt bewusst false: mit true darf die Physik-Engine die
|
||||||
--- Attachment bei Ragdoll und harten Anim-Übergängen lösen, dann fliegt das Prop weg.
|
--- Attachment bei Ragdoll und harten Anim-Übergängen lösen, dann fliegt das Prop weg.
|
||||||
local function attachProp(model, bone, offset, rotation)
|
local function attachProp(ped, model, bone, offset, rotation)
|
||||||
lib.requestModel(model)
|
lib.requestModel(model)
|
||||||
|
|
||||||
local prop = CreateObject(model, 1.0, 1.0, 1.0, true, true, false)
|
local prop = CreateObject(model, 1.0, 1.0, 1.0, true, true, false)
|
||||||
SetEntityCollision(prop, false, false) --- Disable collision so it doesn't block bullets
|
SetEntityCollision(prop, false, false) --- Disable collision so it doesn't block bullets
|
||||||
AttachEntityToEntity(prop, cache.ped, GetPedBoneIndex(cache.ped, bone),
|
AttachEntityToEntity(prop, ped, GetPedBoneIndex(ped, bone),
|
||||||
offset.x, offset.y, offset.z,
|
offset.x, offset.y, offset.z,
|
||||||
rotation.x, rotation.y, rotation.z,
|
rotation.x, rotation.y, rotation.z,
|
||||||
false, -- p9
|
false, -- p9
|
||||||
@@ -61,9 +65,11 @@ local function attachProp(model, bone, offset, rotation)
|
|||||||
return prop
|
return prop
|
||||||
end
|
end
|
||||||
|
|
||||||
local function attachGear()
|
--- @param ped number? default cache.ped
|
||||||
currentGear.tank = attachProp(TANK_MODEL, TANK_BONE, vec3(-0.25, -0.25, 0.0), vec3(180.0, 90.0, 0.0))
|
local function attachGear(ped)
|
||||||
currentGear.mask = attachProp(MASK_MODEL, MASK_BONE, vec3(0.0, 0.0, 0.0), vec3(180.0, 90.0, 0.0))
|
ped = ped or cache.ped
|
||||||
|
currentGear.tank = attachProp(ped, TANK_MODEL, TANK_BONE, vec3(-0.25, -0.25, 0.0), vec3(180.0, 90.0, 0.0))
|
||||||
|
currentGear.mask = attachProp(ped, MASK_MODEL, MASK_BONE, vec3(0.0, 0.0, 0.0), vec3(180.0, 90.0, 0.0))
|
||||||
end
|
end
|
||||||
|
|
||||||
local function isPropIntact(prop)
|
local function isPropIntact(prop)
|
||||||
@@ -228,14 +234,19 @@ end)
|
|||||||
|
|
||||||
--- Beim Model-Wechsel (Kleiderladen, Skin-Change) ist der Ped ein anderer -
|
--- Beim Model-Wechsel (Kleiderladen, Skin-Change) ist der Ped ein anderer -
|
||||||
--- alle attached Props sind weg und die Scuba-Flags gelten für den alten Ped.
|
--- alle attached Props sind weg und die Scuba-Flags gelten für den alten Ped.
|
||||||
lib.onCache('ped', function()
|
---
|
||||||
|
--- Der neue Ped kommt zwingend aus dem Callback-Parameter: ox_lib feuert die
|
||||||
|
--- onCache-Callbacks über Citizen.CreateThreadNow, *bevor* der neue Wert in den
|
||||||
|
--- Cache geschrieben wird (ox_lib/init.lua). cache.ped zeigt hier also noch auf
|
||||||
|
--- den alten, bereits verschwundenen Ped.
|
||||||
|
lib.onCache('ped', function(ped)
|
||||||
if not currentGear.enabled then return end
|
if not currentGear.enabled then return end
|
||||||
|
|
||||||
deleteGear()
|
deleteGear()
|
||||||
attachGear()
|
attachGear(ped)
|
||||||
|
|
||||||
if oxygenLevel > 0 then
|
if oxygenLevel > 0 then
|
||||||
enableScuba()
|
enableScuba(ped)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user