From e0d1d08913061204d303135bdc4a7dcf6200eb7a Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Sun, 15 Feb 2015 18:19:01 -0600 Subject: [PATCH] Change AnimChange EH --- .../fnc_handleZeusDisplayChanged.sqf | 4 +- .../captives/functions/fnc_setHandcuffed.sqf | 2 +- addons/captives/functions/fnc_surrender.sqf | 51 +++++++++++-------- 3 files changed, 34 insertions(+), 23 deletions(-) diff --git a/addons/captives/functions/fnc_handleZeusDisplayChanged.sqf b/addons/captives/functions/fnc_handleZeusDisplayChanged.sqf index e328d410fa..2299fa7031 100644 --- a/addons/captives/functions/fnc_handleZeusDisplayChanged.sqf +++ b/addons/captives/functions/fnc_handleZeusDisplayChanged.sqf @@ -22,10 +22,10 @@ PARAMS_2(_unit,_zeusIsOpen); //set showHUD based on unit status: if (!_zeusIsOpen) then { if ((_unit getVariable [QGVAR(isHandcuffed), false]) || {_unit getVariable [QGVAR(isSurrendering), false]}) then { - TRACE_1("Player Change (showHUD false)",_newUnit); + TRACE_1("Player Change (showHUD false)",_unit); showHUD false; } else { - TRACE_1("Player Change (showHUD true)",_newUnit); + TRACE_1("Player Change (showHUD true)",_unit); showHUD true; }; }; diff --git a/addons/captives/functions/fnc_setHandcuffed.sqf b/addons/captives/functions/fnc_setHandcuffed.sqf index 06906167e9..0d404f6c6e 100644 --- a/addons/captives/functions/fnc_setHandcuffed.sqf +++ b/addons/captives/functions/fnc_setHandcuffed.sqf @@ -31,7 +31,7 @@ if (_state isEqualTo (_unit getVariable [QGVAR(isHandcuffed), false])) then { if (_state) then { _unit setVariable [QGVAR(isHandcuffed), true, true]; if (_unit getVariable [QGVAR(isSurrendering), false]) then { //If surrendering, stop - [_unit, _false] call FUNC(surrender); + [_unit, false] call FUNC(surrender); }; [_unit, QGVAR(Handcuffed), true] call EFUNC(common,setCaptivityStatus); _unit setVariable [QGVAR(CargoIndex), ((vehicle _unit) getCargoIndex _unit), true]; diff --git a/addons/captives/functions/fnc_surrender.sqf b/addons/captives/functions/fnc_surrender.sqf index adffc4d2aa..e1e4c19c11 100644 --- a/addons/captives/functions/fnc_surrender.sqf +++ b/addons/captives/functions/fnc_surrender.sqf @@ -4,7 +4,7 @@ * * Arguments: * 0: Unit - * 1: State + * 1: True to surrender, false to un-surrender * * Return Value: * Nothing @@ -45,12 +45,16 @@ if (_state) then { }; //Adds an animation changed eh - //Should handle changes in animation + //If we get a change in animation before we've "locked" in the hands up animationState, then stop surrendering _animChangedEHID = _unit addEventHandler ["AnimChanged", { PARAMS_2(_unit,_newAnimation); + if (_newAnimation != "ACE_AmovPercMstpSsurWnonDnon") then { - ERROR("Surrender animation failed"); - [_unit, false] call FUNC(surrender); + if ((animationState _unit != "ACE_AmovPercMstpSnonWnonDnon_AmovPercMstpSsurWnonDnon") && (animationState _unit != "ACE_AmovPercMstpSsurWnonDnon")) then { + ERROR("Surrender animation failed"); + systemChat "Debug: Surrender animation failed"; + [_unit, false] call FUNC(surrender); + }; }; }]; _unit setVariable [QGVAR(surrenderAnimEHID), _animChangedEHID]; @@ -62,22 +66,7 @@ if (_state) then { _animChangedEHID = _unit getVariable [QGVAR(surrenderAnimEHID), -1]; _unit removeEventHandler ["AnimChanged", _animChangedEHID]; - - //spin up a PFEH, to watching animationState for the next 10 seconds to make sure we don't enter - [{ - PARAMS_2(_args,_pfID); - EXPLODE_2_PVT(_args,_unit,_maxTime); - //If maxtime or they re-surrendered, exit loop - if ((time > _maxTime) || {_unit getVariable [QGVAR(isSurrendering), false]}) exitWith { - [_pfID] call CBA_fnc_removePerFrameHandler; - }; - //Only break animation if they are actualy the "hands up" animation (because we are using switchmove) - if (((vehicle _unit) == _unit) && {(animationState _unit) == "ACE_AmovPercMstpSsurWnonDnon"}) exitWith { - [_pfID] call CBA_fnc_removePerFrameHandler; - //Break out of hands up animation loop (doAnimation handles Unconscious prioity) - [_unit, "ACE_AmovPercMstpSsurWnonDnon_AmovPercMstpSnonWnonDnon", 2] call EFUNC(common,doAnimation); - }; - }, 0.05, [_unit, (time + 15)]] call CBA_fnc_addPerFrameHandler; + _unit setVariable [QGVAR(surrenderAnimEHID), -1]; if (_unit == ACE_player) then { //only re-enable HUD if not handcuffed @@ -85,4 +74,26 @@ if (_state) then { showHUD true; }; }; + + //if we are in "hands up" animationState, crack it now + if (((vehicle _unit) == _unit) && {(animationState _unit) == "ACE_AmovPercMstpSsurWnonDnon"}) then { + [_unit, "ACE_AmovPercMstpSsurWnonDnon_AmovPercMstpSnonWnonDnon", 2] call EFUNC(common,doAnimation); + } else { + //spin up a PFEH, to watching animationState for the next 20 seconds to make sure we don't enter + //Handles long animation chains + [{ + PARAMS_2(_args,_pfID); + EXPLODE_2_PVT(_args,_unit,_maxTime); + //If maxtime or they re-surrendered, exit loop + if ((time > _maxTime) || {_unit getVariable [QGVAR(isSurrendering), false]}) exitWith { + [_pfID] call CBA_fnc_removePerFrameHandler; + }; + //Only break animation if they are actualy the "hands up" animation (because we are using switchmove) + if (((vehicle _unit) == _unit) && {(animationState _unit) == "ACE_AmovPercMstpSsurWnonDnon"}) exitWith { + [_pfID] call CBA_fnc_removePerFrameHandler; + //Break out of hands up animation loop (doAnimation handles Unconscious prioity) + [_unit, "ACE_AmovPercMstpSsurWnonDnon_AmovPercMstpSnonWnonDnon", 2] call EFUNC(common,doAnimation); + }; + }, 0.05, [_unit, (time + 20)]] call CBA_fnc_addPerFrameHandler; + }; };