From a48db2699602159372a5da0729139fcef65a01be Mon Sep 17 00:00:00 2001 From: jonpas Date: Wed, 27 Sep 2017 22:41:05 +0200 Subject: [PATCH] Fix Load Patient/Captive actions (#5544) * Disable (un)load patient action if unit is dead but was uncoscious before * Remove handcuffs on death (prevents stand-up ragoll restart), Don't show load patient and captive at the same time * Only allow unloading from outside - fix #5525 as discussed * Also prevent unloading captives from inside * Add debug logging --- addons/captives/CfgEventHandlers.hpp | 8 +++++++ addons/captives/XEH_PREP.hpp | 2 +- .../captives/functions/fnc_canLoadCaptive.sqf | 3 +++ .../functions/fnc_canUnloadCaptive.sqf | 3 ++- .../captives/functions/fnc_handleKilled.sqf | 24 +++++++++++++++++++ .../captives/functions/fnc_handleRespawn.sqf | 1 + addons/medical/CfgVehicles.hpp | 4 ++-- 7 files changed, 41 insertions(+), 4 deletions(-) create mode 100644 addons/captives/functions/fnc_handleKilled.sqf diff --git a/addons/captives/CfgEventHandlers.hpp b/addons/captives/CfgEventHandlers.hpp index e2e8df28f1..95453fe5d1 100644 --- a/addons/captives/CfgEventHandlers.hpp +++ b/addons/captives/CfgEventHandlers.hpp @@ -63,3 +63,11 @@ class Extended_Local_EventHandlers { }; }; }; + +class Extended_Killed_EventHandlers { + class CAManBase { + class ADDON { + killed = QUOTE(_this call FUNC(handleKilled)); + }; + }; +}; diff --git a/addons/captives/XEH_PREP.hpp b/addons/captives/XEH_PREP.hpp index bfb1ade5e0..9ce78e438a 100644 --- a/addons/captives/XEH_PREP.hpp +++ b/addons/captives/XEH_PREP.hpp @@ -1,4 +1,3 @@ - PREP(canApplyHandcuffs); PREP(canEscortCaptive); PREP(canFriskPerson); @@ -18,6 +17,7 @@ PREP(handleAnimChangedHandcuffed); PREP(handleAnimChangedSurrendered); PREP(handleGetIn); PREP(handleGetOut); +PREP(handleKilled); PREP(handleLocal); PREP(handleOnUnconscious); PREP(handlePlayerChanged); diff --git a/addons/captives/functions/fnc_canLoadCaptive.sqf b/addons/captives/functions/fnc_canLoadCaptive.sqf index a59c2e3be6..b968f1754a 100644 --- a/addons/captives/functions/fnc_canLoadCaptive.sqf +++ b/addons/captives/functions/fnc_canLoadCaptive.sqf @@ -19,6 +19,9 @@ params ["_unit", "_target","_vehicle"]; +// Don't show "Load Captive" if unit is unconscious (already has "Load Patient") +if (_target getVariable ["ACE_isUnconscious", false]) exitWith {false}; + if ((isNull _target) && {_unit getVariable [QGVAR(isEscorting), false]}) then { //Looking at a vehicle while escorting, get target from attached objects: { diff --git a/addons/captives/functions/fnc_canUnloadCaptive.sqf b/addons/captives/functions/fnc_canUnloadCaptive.sqf index 82fc0a8429..0d8ec81b07 100644 --- a/addons/captives/functions/fnc_canUnloadCaptive.sqf +++ b/addons/captives/functions/fnc_canUnloadCaptive.sqf @@ -18,4 +18,5 @@ params ["_player", "_unit"]; -((vehicle _unit) != _unit) && {_unit getVariable [QGVAR(isHandcuffed), false]} +// Don't show "Unload Captive" if unit is unconscious (already has "Unload Patient") +(vehicle _unit != _unit) && {vehicle _player == _player} && {_unit getVariable [QGVAR(isHandcuffed), false]} && {!(_unit getVariable ["ACE_isUnconscious", false])} diff --git a/addons/captives/functions/fnc_handleKilled.sqf b/addons/captives/functions/fnc_handleKilled.sqf new file mode 100644 index 0000000000..27963e460d --- /dev/null +++ b/addons/captives/functions/fnc_handleKilled.sqf @@ -0,0 +1,24 @@ +/* + * Author: Jonpas + * Called when a unit dies. + * + * Arguments: + * 0: Unit + * + * Return Value: + * None + * + * Example: + * [bob] call ace_captives_fnc_handleKilled + * + * Public: No + */ +#include "script_component.hpp" + +params ["_unit"]; +TRACE_1("handleKilled",_unit); + +// Remove handcuffs on a dead unit, removing them after unit goes into ragdoll causes a stand-up twitch and restarts the ragdoll +if (_unit getVariable [QGVAR(isHandcuffed), false]) then { + [_unit, false] call FUNC(setHandcuffed); +}; diff --git a/addons/captives/functions/fnc_handleRespawn.sqf b/addons/captives/functions/fnc_handleRespawn.sqf index 98672798fd..2d6618c6d1 100644 --- a/addons/captives/functions/fnc_handleRespawn.sqf +++ b/addons/captives/functions/fnc_handleRespawn.sqf @@ -17,6 +17,7 @@ #include "script_component.hpp" params ["_unit","_dead"]; +TRACE_2("handleRespawn",_unit,_dead); if (!local _unit) exitWith {}; diff --git a/addons/medical/CfgVehicles.hpp b/addons/medical/CfgVehicles.hpp index 3d868e74ae..936ea976ef 100644 --- a/addons/medical/CfgVehicles.hpp +++ b/addons/medical/CfgVehicles.hpp @@ -545,7 +545,7 @@ class CfgVehicles { class GVAR(loadPatient) { displayName = CSTRING(LoadPatient); distance = 5; - condition = QUOTE(_target getVariable[ARR_2(QUOTE(QUOTE(ACE_isUnconscious)),false)] && vehicle _target == _target); + condition = QUOTE(_target getVariable [ARR_2(QUOTE(QUOTE(ACE_isUnconscious)), false)] && {alive _target} && {vehicle _target == _target}); statement = QUOTE([ARR_2(_player, _target)] call DFUNC(actionLoadUnit)); showDisabled = 0; priority = 2; @@ -555,7 +555,7 @@ class CfgVehicles { class GVAR(UnLoadPatient) { displayName = CSTRING(UnloadPatient); distance = 5; - condition = QUOTE(_target getVariable[ARR_2(QUOTE(QUOTE(ACE_isUnconscious)),false)] && vehicle _target != _target); + condition = QUOTE(_target getVariable [ARR_2(QUOTE(QUOTE(ACE_isUnconscious)), false)] && {vehicle _target != _target} && {vehicle _player == _player}); statement = QUOTE([ARR_2(_player, _target)] call DFUNC(actionUnloadUnit)); showDisabled = 0; priority = 2;