From 6fb9161ecc139a81eba7c0321137687fa22e8e28 Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Wed, 2 Aug 2023 00:59:46 -0500 Subject: [PATCH] Medical Engine - Fix unloading dead units in vehicles and handle deleted units vehicles (#9283) * Medical Engine - Unlock when dead * Update fnc_unloadPersonLocal.sqf * Update addons/common/functions/fnc_unloadPersonLocal.sqf Co-authored-by: Grim <69561145+LinkIsGrim@users.noreply.github.com> * fix actually unloading people to found emptyPos * handle deleted units * handle dead units ref https://github.com/LinkIsGrim/ACE3/commit/179957c39d76850ac6021358302d59da340b18c5 * vehicle -> objectParent --------- Co-authored-by: Grim <69561145+LinkIsGrim@users.noreply.github.com> --- .../functions/fnc_unloadPersonLocal.sqf | 41 +++++++++++-------- addons/medical_engine/XEH_postInit.sqf | 20 ++++++++- .../functions/fnc_lockUnconsciousSeat.sqf | 4 ++ .../functions/fnc_unlockUnconsciousSeat.sqf | 1 + 4 files changed, 47 insertions(+), 19 deletions(-) diff --git a/addons/common/functions/fnc_unloadPersonLocal.sqf b/addons/common/functions/fnc_unloadPersonLocal.sqf index 21c16f8f6d..3a48ae2b10 100644 --- a/addons/common/functions/fnc_unloadPersonLocal.sqf +++ b/addons/common/functions/fnc_unloadPersonLocal.sqf @@ -19,7 +19,7 @@ #define GROUP_SWITCH_ID QFUNC(loadPerson) -params ["_unit", "_vehicle", ["_unloader", objNull]]; +params ["_unit", ["_vehicle", objNull], ["_unloader", objNull]]; TRACE_3("unloadpersonLocal",_unit,_vehicle,_unloader); //This covers testing vehicle stability and finding a safe position @@ -46,16 +46,20 @@ if (count _emptyPos != 3) exitwith { unassignVehicle _unit; [_unit] orderGetIn false; -TRACE_1("Ejecting", alive _unit); -private _vehicle = vehicle _unit; +TRACE_2("Ejecting",alive _unit,local _vehicle); + if (local _vehicle) then { _unit action ["Eject", _vehicle]; // Failsafe - sometimes eject alone doesn't work, but moveOut does [{ params ["_unit"]; - if (vehicle _unit != _unit) then { - WARNING_1("UnloadPersonLocal [%1] did not eject normally",_unit); + if (!isNull objectParent _unit) then { + if ([_unit] call FUNC(isAwake)) then { + WARNING_1("UnloadPersonLocal [%1] did not eject normally",_unit); + } else { + TRACE_1("UnloadPersonLocal dead/uncon did not eject normally",_unit); + }; moveOut _unit; }; }, [_unit], 1] call CBA_fnc_waitAndExecute; @@ -64,18 +68,21 @@ if (local _vehicle) then { moveOut _unit; }; -[{ - params ["_unit", "_emptyPos"]; - (alive _unit) && {(vehicle _unit) != _unit} -}, { - params ["_unit", "_emptyPos"]; - TRACE_2("success",_unit,_emptyPos); - _unit setPosASL AGLToASL _emptyPos; -}, [_unit, _emptyPos], 2, { - params ["_unit", "_emptyPos"]; - if (!alive _unit) exitWith {}; - WARNING_2("timeout %1->%2",_unit,vehicle _unit); -}] call CBA_fnc_waitUntilAndExecute; +// Wait until unit has actually exited vehicle and then move them to the unload position +if (alive _unit) then { + [{ + params ["_unit", "_emptyPos"]; + (alive _unit) && {isNull objectParent _unit} + }, { + params ["_unit", "_emptyPos"]; + TRACE_2("unload success",_unit,_emptyPos); + _unit setPosASL AGLToASL _emptyPos; + }, [_unit, _emptyPos], 2, { + params ["_unit", "_emptyPos"]; + if (!alive _unit) exitWith {}; + WARNING_2("timeout %1->%2",_unit,objectParent _unit); + }] call CBA_fnc_waitUntilAndExecute; +}; [_unit, false, GROUP_SWITCH_ID, side group _unit] call FUNC(switchToGroupSide); diff --git a/addons/medical_engine/XEH_postInit.sqf b/addons/medical_engine/XEH_postInit.sqf index f1f1780fa8..64f8bab83b 100644 --- a/addons/medical_engine/XEH_postInit.sqf +++ b/addons/medical_engine/XEH_postInit.sqf @@ -85,8 +85,8 @@ ["ace_unconscious", { params ["_unit", "_unconscious"]; - - if (vehicle _unit != _unit && {local vehicle _unit}) then { + TRACE_3("unit uncon",_unit,objectParent _unit,local _unit); + if (!isNull objectParent _unit && {local objectParent _unit}) then { if (_unconscious) then { [_unit] call FUNC(lockUnconsciousSeat); } else { @@ -94,3 +94,19 @@ }; }; }] call CBA_fnc_addEventHandler; + +["ace_killed", { // global event + params ["_unit"]; + TRACE_3("unit Killed",_unit,objectParent _unit,local _unit); + if (!isNull objectParent _unit && {local objectParent _unit}) exitWith { + [_unit] call FUNC(lockUnconsciousSeat); + }; +}] call CBA_fnc_addEventHandler; + +["CAManBase", "deleted", { + params ["_unit"]; + TRACE_3("unit deleted",_unit,objectParent _unit,local _unit); + if ((!isNull objectParent _unit) && {local objectParent _unit}) then { + [_unit] call FUNC(unlockUnconsciousSeat); + }; +}, true, []] call CBA_fnc_addClassEventHandler; diff --git a/addons/medical_engine/functions/fnc_lockUnconsciousSeat.sqf b/addons/medical_engine/functions/fnc_lockUnconsciousSeat.sqf index 97d514278e..dc748426b7 100644 --- a/addons/medical_engine/functions/fnc_lockUnconsciousSeat.sqf +++ b/addons/medical_engine/functions/fnc_lockUnconsciousSeat.sqf @@ -11,10 +11,13 @@ * * Public: No */ +if (missionNamespace getVariable [QGVAR(disableSeatLocking), false]) exitWith {}; params ["_unit"]; private _vehicle = objectParent _unit; +TRACE_3("lockUnconsciousSeat",_unit,_vehicle,lifeState _unit); +if (isNull _vehicle) exitWith {}; if (alive _unit && {lifeState _unit != "INCAPACITATED"}) exitWith {}; switch (true) do { @@ -35,3 +38,4 @@ switch (true) do { _unit setVariable [QGVAR(lockedSeat), [_vehicle, "turret", _turretPath], true]; }; }; +TRACE_1("locked",_unit getVariable QGVAR(lockedSeat)); diff --git a/addons/medical_engine/functions/fnc_unlockUnconsciousSeat.sqf b/addons/medical_engine/functions/fnc_unlockUnconsciousSeat.sqf index 6c772b5c24..858442d1d3 100644 --- a/addons/medical_engine/functions/fnc_unlockUnconsciousSeat.sqf +++ b/addons/medical_engine/functions/fnc_unlockUnconsciousSeat.sqf @@ -16,6 +16,7 @@ params ["_unit"]; private _seat = _unit getVariable [QGVAR(lockedSeat), []]; _seat params ["_vehicle", "_type", "_position"]; +TRACE_2("unlockUnconsciousSeat",_unit,_seat); if (_seat isEqualTo []) exitWith {}; switch (_type) do {