From 3c65c422b1ab81db92640ee90a2c52f63fc67b02 Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Sun, 15 Feb 2015 16:42:00 -0600 Subject: [PATCH] More Surrender Fixes Increase "drop hands" animation speed (now just 1/2 of normal) Use "AnimChanged" EH to watch for animation breaks while surrendering Only "crack" the hands up animation if we are in the right animation state --- addons/captives/CfgMoves.hpp | 2 +- .../captives/functions/fnc_canSurrender.sqf | 11 +++- addons/captives/functions/fnc_surrender.sqf | 62 +++++++++++-------- 3 files changed, 46 insertions(+), 29 deletions(-) diff --git a/addons/captives/CfgMoves.hpp b/addons/captives/CfgMoves.hpp index 6e67f3615b..d60fab5a33 100644 --- a/addons/captives/CfgMoves.hpp +++ b/addons/captives/CfgMoves.hpp @@ -72,7 +72,7 @@ class CfgMovesMaleSdr: CfgMovesBasic { InterpolateTo[] = {"Unconscious",0.01}; }; class ACE_AmovPercMstpSsurWnonDnon_AmovPercMstpSnonWnonDnon: ACE_AmovPercMstpSnonWnonDnon_AmovPercMstpSsurWnonDnon { - speed = 0.333; //for gameplay reasons, slow this down + speed = 0.5; //for gameplay reasons, slow this down actions = "CivilStandActions"; file = "\A3\anims_f\Data\Anim\Sdr\mov\erc\stp\sur\non\AmovPercMstpSsurWnonDnon_AmovPercMstpSnonWnonDnon"; ConnectTo[] = {"AmovPercMstpSnonWnonDnon",0.1}; diff --git a/addons/captives/functions/fnc_canSurrender.sqf b/addons/captives/functions/fnc_canSurrender.sqf index 238087c62b..4c16e8ccd0 100644 --- a/addons/captives/functions/fnc_canSurrender.sqf +++ b/addons/captives/functions/fnc_canSurrender.sqf @@ -18,5 +18,12 @@ PARAMS_2(_unit,_newSurrenderState); -//TODO: any other conditions?? -(!((_unit getVariable [QGVAR(isSurrendering), false]) isEqualTo _newSurrenderState)) +private "_returnValue"; + +_returnValue = if (_newSurrenderState) then { + !(_unit getVariable [QGVAR(isSurrendering), false]); //Not currently surrendering +} else { + (_unit getVariable [QGVAR(isSurrendering), false]); //isSurrendering and on the hands up animation - // && {(animationState _unit) == "ACE_AmovPercMstpSsurWnonDnon"}; +}; + +_returnValue diff --git a/addons/captives/functions/fnc_surrender.sqf b/addons/captives/functions/fnc_surrender.sqf index 25d5e6a008..f2103d2c1c 100644 --- a/addons/captives/functions/fnc_surrender.sqf +++ b/addons/captives/functions/fnc_surrender.sqf @@ -30,7 +30,12 @@ if ((_unit getVariable [QGVAR(isSurrendering), false]) isEqualTo _state) then { if (_state) then { _unit setVariable [QGVAR(isSurrendering), true, true]; - + [_unit, QGVAR(Surrendered), true] call EFUNC(common,setCaptivityStatus); + + if (_unit == ACE_player) then { + showHUD false; + }; + // fix anim on mission start (should work on dedicated servers) [{ PARAMS_1(_unit); @@ -38,37 +43,42 @@ if (_state) then { [_unit] call EFUNC(common,fixLoweredRifleAnimation); [_unit, "ACE_AmovPercMstpSsurWnonDnon", 1] call EFUNC(common,doAnimation); }; - }, [_unit], 0.01, 0] call EFUNC(common,waitAndExecute); - //Start up a pfeh to make sure the unit actualy goes into the animation - //Only change variables and captivity when they reach that state - //fixes vaulting to break animation - [{ - PARAMS_2(_args,_pfID); - EXPLODE_2_PVT(_args,_unit,_maxTime); - - if (time > _maxTime) exitWith { - [_pfID] call CBA_fnc_removePerFrameHandler; - _unit setVariable [QGVAR(isSurrendering), false, true]; - ERROR("Surrender animation failed"); - }; - if ((animationState _unit) == "ACE_AmovPercMstpSsurWnonDnon") exitWith { - [_pfID] call CBA_fnc_removePerFrameHandler; - - if (_unit == ACE_player) then { - showHUD false; + //Adds an animation changed eh + //Should handle changes in animation + _animChangedEHID = _unit addEventHandler ["AnimChanged", { + PARAMS_2(_unit,_newAnimation); + if (_newAnimation != "ACE_AmovPercMstpSsurWnonDnon") then { + ERROR("Surrender animation failed"); + systemChat "You Stop Surrendering"; + [_unit, false] call FUNC(surrender); }; - [_unit, QGVAR(Surrendered), true] call EFUNC(common,setCaptivityStatus); - }; - }, 0, [_unit, (time + 20)]] call CBA_fnc_addPerFrameHandler; + }]; + _unit setVariable [QGVAR(surrenderAnimEHID), _animChangedEHID]; + + }, [_unit], 0.01, 0] call EFUNC(common,waitAndExecute); } else { _unit setVariable [QGVAR(isSurrendering), false, true]; [_unit, QGVAR(Surrendered), false] call EFUNC(common,setCaptivityStatus); - if ((vehicle _unit) == _unit) then { - //Break out of hands up animation loop (doAnimation handles Unconscious prioity) - [_unit, "ACE_AmovPercMstpSsurWnonDnon_AmovPercMstpSnonWnonDnon", 2] call EFUNC(common,doAnimation); - }; + _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; if (_unit == ACE_player) then { //only re-enable HUD if not handcuffed