diff --git a/addons/captives/CfgEventHandlers.hpp b/addons/captives/CfgEventHandlers.hpp index 916990f1b5..e2e8df28f1 100644 --- a/addons/captives/CfgEventHandlers.hpp +++ b/addons/captives/CfgEventHandlers.hpp @@ -55,3 +55,11 @@ class Extended_Respawn_EventHandlers { }; }; }; + +class Extended_Local_EventHandlers { + class CAManBase { + class ADDON { + local = QUOTE(call FUNC(handleLocal)); + }; + }; +}; diff --git a/addons/captives/XEH_PREP.hpp b/addons/captives/XEH_PREP.hpp index 2722214e1b..bfb1ade5e0 100644 --- a/addons/captives/XEH_PREP.hpp +++ b/addons/captives/XEH_PREP.hpp @@ -14,8 +14,11 @@ PREP(doLoadCaptive); PREP(doRemoveHandcuffs); PREP(doUnloadCaptive); PREP(findEmptyNonFFVCargoSeat); +PREP(handleAnimChangedHandcuffed); +PREP(handleAnimChangedSurrendered); PREP(handleGetIn); PREP(handleGetOut); +PREP(handleLocal); PREP(handleOnUnconscious); PREP(handlePlayerChanged); PREP(handleRespawn); diff --git a/addons/captives/functions/fnc_handleAnimChangedHandcuffed.sqf b/addons/captives/functions/fnc_handleAnimChangedHandcuffed.sqf new file mode 100644 index 0000000000..2f55d51fc3 --- /dev/null +++ b/addons/captives/functions/fnc_handleAnimChangedHandcuffed.sqf @@ -0,0 +1,37 @@ +/* + * Author: Nic547, commy2 + * Restart the handcuffing animation if it got interrupted. Called from a AnimChanged EH. + * + * Arguments: + * 0: The Unit + * 1: New animation + * + * ReturnValue: + * None + * + * Public: No + */ + + +#include "script_component.hpp" + +params ["_unit", "_newAnimation"]; +TRACE_2("AnimChanged",_unit,_newAnimation); +if (_unit == (vehicle _unit)) then { + if ((_newAnimation != "ACE_AmovPercMstpSsurWnonDnon") && {!(_unit getVariable ["ACE_isUnconscious", false])}) then { + TRACE_1("Handcuff animation interrupted",_newAnimation); + [_unit, "ACE_AmovPercMstpScapWnonDnon", 1] call EFUNC(common,doAnimation); + }; +} else { + _turretPath = []; + { + _x params ["_xUnit", "", "", "_xTurretPath"]; + if (_unit == _xUnit) exitWith {_turretPath = _xTurretPath}; + } forEach (fullCrew (vehicle _unit)); + TRACE_1("turret Path",_turretPath); + if (_turretPath isEqualTo []) exitWith {}; + + TRACE_1("Handcuff (FFV) animation interrupted",_newAnimation); + [_unit, "ACE_HandcuffedFFV", 2] call EFUNC(common,doAnimation); + [_unit, "ACE_HandcuffedFFV", 1] call EFUNC(common,doAnimation); +}; diff --git a/addons/captives/functions/fnc_handleAnimChangedSurrendered.sqf b/addons/captives/functions/fnc_handleAnimChangedSurrendered.sqf new file mode 100644 index 0000000000..cf17d8b873 --- /dev/null +++ b/addons/captives/functions/fnc_handleAnimChangedSurrendered.sqf @@ -0,0 +1,24 @@ +/* + * Author: Nic547, commy2 + * Restart the surrendering animation if it got interrupted. Called from a AnimChanged EH. + * + * Arguments: + * 0: The Unit + * 1: New animation + * + * ReturnValue: + * None + * + * Public: No + */ + + +#include "script_component.hpp" + +params ["_unit", "_newAnimation"]; + +TRACE_2("AnimChanged",_unit,_newAnimation); +if ((_newAnimation != "ACE_AmovPercMstpSsurWnonDnon") && {!(_unit getVariable ["ACE_isUnconscious", false])}) then { + TRACE_1("Surrender animation interrupted",_newAnimation); + [_unit, "ACE_AmovPercMstpSsurWnonDnon", 1] call EFUNC(common,doAnimation); +}; diff --git a/addons/captives/functions/fnc_handleLocal.sqf b/addons/captives/functions/fnc_handleLocal.sqf new file mode 100644 index 0000000000..693eb844fd --- /dev/null +++ b/addons/captives/functions/fnc_handleLocal.sqf @@ -0,0 +1,63 @@ +/* + * Author: esteldunedain + * Called when a unit switched locality + * + * Arguments: + * 0: The Unit + * 1: Is local + * + * ReturnValue: + * None + * + * Public: No + */ + + +#include "script_component.hpp" + +params ["_unit", "_local"]; + +// Make sure that if the unit is captive or surrendered it has a AnimChanged EH running ONLY on the machine that owns it +if (_local) then { + + // If the unit is handcuffed + if (_unit getVariable [QGVAR(isHandcuffed), false]) then { + // If the unit already has an AnimChanged EH here then there's nothing to do either + if (_unit getVariable [QGVAR(handcuffAnimEHID), -1] != -1) exitWith {}; + + // Otherwise, restart the AnimChanged EH in the new machine + private _animChangedEHID = _unit addEventHandler ["AnimChanged", DFUNC(handleAnimChangedHandcuffed)]; + TRACE_2("Adding animChangedEH",_unit,_animChangedEHID); + _unit setVariable [QGVAR(handcuffAnimEHID), _animChangedEHID]; + }; + + // If the unit is surrendering + if (_unit getVariable [QGVAR(isSurrendering), false]) then { + // If the unit already has an AnimChanged EH here then there's nothing to do either + if (_unit getVariable [QGVAR(surrenderAnimEHID), -1] != -1) exitWith {}; + + // Otherwise, restart the AnimChanged EH in the new machine + private _animChangedEHID = _unit addEventHandler ["AnimChanged", DFUNC(handleAnimChangedSurrendered)]; + TRACE_2("Adding animChangedEH",_unit,_animChangedEHID); + _unit setVariable [QGVAR(surrenderAnimEHID), _animChangedEHID]; + }; + +} else { + + private _animChangedEHID = _unit getVariable [QGVAR(handcuffAnimEHID), -1]; + if (_animChangedEHID != -1) then { + // If the unit had a AnimChanged EH for handcuffing in the old machine then remove it + TRACE_1("Removing animChanged EH",_animChangedEHID); + _unit removeEventHandler ["AnimChanged", _animChangedEHID]; + _unit setVariable [QGVAR(handcuffAnimEHID), -1]; + }; + + _animChangedEHID = _unit getVariable [QGVAR(surrenderAnimEHID), -1]; + if (_animChangedEHID != -1) then { + // If the unit had a AnimChanged EH for handcuffing in the old machine then remove it + TRACE_1("Removing animChanged EH",_animChangedEHID); + _unit removeEventHandler ["AnimChanged", _animChangedEHID]; + _unit setVariable [QGVAR(surrenderAnimEHID), -1]; + }; + +}; diff --git a/addons/captives/functions/fnc_setHandcuffed.sqf b/addons/captives/functions/fnc_setHandcuffed.sqf index 4fbedaef87..1859bfb0b1 100644 --- a/addons/captives/functions/fnc_setHandcuffed.sqf +++ b/addons/captives/functions/fnc_setHandcuffed.sqf @@ -73,28 +73,7 @@ if (_state) then { TRACE_1("removing animChanged EH",_animChangedEHID); _unit removeEventHandler ["AnimChanged", _animChangedEHID]; }; - _animChangedEHID = _unit addEventHandler ["AnimChanged", { - params ["_unit", "_newAnimation"]; - TRACE_2("AnimChanged",_unit,_newAnimation); - if (_unit == (vehicle _unit)) then { - if ((_newAnimation != "ACE_AmovPercMstpSsurWnonDnon") && {!(_unit getVariable ["ACE_isUnconscious", false])}) then { - TRACE_1("Handcuff animation interrupted",_newAnimation); - [_unit, "ACE_AmovPercMstpScapWnonDnon", 1] call EFUNC(common,doAnimation); - }; - } else { - _turretPath = []; - { - _x params ["_xUnit", "", "", "_xTurretPath"]; - if (_unit == _xUnit) exitWith {_turretPath = _xTurretPath}; - } forEach (fullCrew (vehicle _unit)); - TRACE_1("turret Path",_turretPath); - if (_turretPath isEqualTo []) exitWith {}; - - TRACE_1("Handcuff (FFV) animation interrupted",_newAnimation); - [_unit, "ACE_HandcuffedFFV", 2] call EFUNC(common,doAnimation); - [_unit, "ACE_HandcuffedFFV", 1] call EFUNC(common,doAnimation); - }; - }]; + _animChangedEHID = _unit addEventHandler ["AnimChanged", DFUNC(handleAnimChangedHandcuffed)]; TRACE_2("Adding animChangedEH",_unit,_animChangedEHID); _unit setVariable [QGVAR(handcuffAnimEHID), _animChangedEHID]; diff --git a/addons/captives/functions/fnc_setSurrendered.sqf b/addons/captives/functions/fnc_setSurrendered.sqf index ba7468da0d..6acd3436aa 100644 --- a/addons/captives/functions/fnc_setSurrendered.sqf +++ b/addons/captives/functions/fnc_setSurrendered.sqf @@ -64,13 +64,7 @@ if (_state) then { TRACE_1("removing animChanged EH",_animChangedEHID); _unit removeEventHandler ["AnimChanged", _animChangedEHID]; }; - _animChangedEHID = _unit addEventHandler ["AnimChanged", { - params ["_unit", "_newAnimation"]; - if ((_newAnimation != "ACE_AmovPercMstpSsurWnonDnon") && {!(_unit getVariable ["ACE_isUnconscious", false])}) then { - TRACE_1("Surrender animation interrupted",_newAnimation); - [_unit, "ACE_AmovPercMstpSsurWnonDnon", 1] call EFUNC(common,doAnimation); - }; - }]; + _animChangedEHID = _unit addEventHandler ["AnimChanged", DFUNC(handleAnimChangedSurrendered)]; _unit setVariable [QGVAR(surrenderAnimEHID), _animChangedEHID]; }; }, [_unit], 0.01] call CBA_fnc_waitAndExecute;