ACE3/addons/captives/functions/fnc_setSurrendered.sqf

103 lines
4.2 KiB
Plaintext
Raw Normal View History

2015-02-03 02:04:50 +00:00
/*
2015-02-06 21:54:26 +00:00
* Author: commy2 PabstMirror
* Lets a unit surrender
2015-02-03 02:04:50 +00:00
*
* Arguments:
* 0: Unit <OBJECT>
2015-02-16 00:19:01 +00:00
* 1: True to surrender, false to un-surrender <BOOL>
2015-02-03 02:04:50 +00:00
*
* Return Value:
* Nothing
*
* Example:
2015-02-17 00:03:09 +00:00
* [Pierre, true] call ACE_captives_fnc_setSurrendered;
2015-02-03 02:04:50 +00:00
*
* Public: No
*/
#include "script_component.hpp"
PARAMS_2(_unit,_state);
2015-02-17 00:03:09 +00:00
2015-02-07 04:24:27 +00:00
if (!local _unit) exitwith {
2015-02-17 00:03:09 +00:00
ERROR("running surrender on remote unit");
2015-02-07 04:24:27 +00:00
};
2015-02-17 00:03:09 +00:00
if ((_unit getVariable [QGVAR(isSurrendering), false]) isEqualTo _state) exitWith {
ERROR("Surrender: current state same as new");
2015-02-07 04:24:27 +00:00
};
if (_state) then {
2015-02-17 00:03:09 +00:00
if ((vehicle _unit) != _unit) exitWith {ERROR("Cannot surrender while mounted");};
if (_unit getVariable [QGVAR(isHandcuffed), false]) exitWith {ERROR("Cannot surrender while handcuffed");};
2015-02-06 21:54:26 +00:00
_unit setVariable [QGVAR(isSurrendering), true, true];
2015-02-17 00:03:09 +00:00
[_unit, QGVAR(Surrendered), true] call EFUNC(common,setCaptivityStatus);
if (_unit == ACE_player) then {
showHUD false;
};
2015-02-17 00:03:09 +00:00
[_unit] call EFUNC(common,fixLoweredRifleAnimation);
[_unit, "ACE_AmovPercMstpSsurWnonDnon", 1] call EFUNC(common,doAnimation);
2015-02-07 04:24:27 +00:00
// fix anim on mission start (should work on dedicated servers)
[{
PARAMS_1(_unit);
2015-02-17 00:03:09 +00:00
if (_unit getVariable [QGVAR(isSurrendering), false] && {(vehicle _unit) == _unit}) then {
//Adds an animation changed eh
//If we get a change in animation then redo the animation (handles people vaulting to break the animation chain)
_animChangedEHID = _unit addEventHandler ["AnimChanged", {
PARAMS_2(_unit,_newAnimation);
if ((_newAnimation != "ACE_AmovPercMstpSsurWnonDnon") && {!(_unit getVariable ["ACE_isUnconscious", false])}) then {
2015-02-17 00:03:09 +00:00
ERROR("Surrender animation interrupted");
systemChat format ["debug %2: new %1", _newAnimation, time];
[_unit, "ACE_AmovPercMstpSsurWnonDnon", 1] call EFUNC(common,doAnimation);
2015-02-16 00:19:01 +00:00
};
2015-02-17 00:03:09 +00:00
}];
_unit setVariable [QGVAR(surrenderAnimEHID), _animChangedEHID];
};
2015-02-07 04:24:27 +00:00
}, [_unit], 0.01, 0] call EFUNC(common,waitAndExecute);
} else {
_unit setVariable [QGVAR(isSurrendering), false, true];
[_unit, QGVAR(Surrendered), false] call EFUNC(common,setCaptivityStatus);
2015-02-17 00:03:09 +00:00
//remove AnimChanged EH
_animChangedEHID = _unit getVariable [QGVAR(surrenderAnimEHID), -1];
_unit removeEventHandler ["AnimChanged", _animChangedEHID];
2015-02-16 00:19:01 +00:00
_unit setVariable [QGVAR(surrenderAnimEHID), -1];
2015-02-06 21:54:26 +00:00
if (_unit == ACE_player) then {
2015-02-07 04:24:27 +00:00
//only re-enable HUD if not handcuffed
2015-02-06 21:54:26 +00:00
if (!(_unit getVariable [QGVAR(isHandcuffed), false])) then {
showHUD true;
};
};
2015-02-16 00:19:01 +00:00
2015-03-26 05:53:38 +00:00
if (!alive _unit) exitWith {};
2015-02-17 00:03:09 +00:00
if (_unit getVariable ["ACE_isUnconscious", false]) exitWith {}; //don't touch animations if unconscious
2015-02-16 00:19:01 +00:00
//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 {
2015-02-17 00:03:09 +00:00
//spin up a PFEH, to watching animationState for the next 20 seconds to make sure we don't enter "hands up"
2015-02-16 00:19:01 +00:00
//Handles long animation chains
[{
PARAMS_2(_args,_pfID);
EXPLODE_2_PVT(_args,_unit,_maxTime);
2015-02-17 00:03:09 +00:00
//If waited long enough or they re-surrendered or they are unconscious, exit loop
if ((time > _maxTime) || {_unit getVariable [QGVAR(isSurrendering), false]} || {_unit getVariable ["ACE_isUnconscious", false]}) exitWith {
2015-02-16 00:19:01 +00:00
[_pfID] call CBA_fnc_removePerFrameHandler;
};
2015-02-17 00:03:09 +00:00
//Only break animation if they are actualy the "hands up" animation (because we are using switchmove there won't be an transition)
2015-02-16 00:19:01 +00:00
if (((vehicle _unit) == _unit) && {(animationState _unit) == "ACE_AmovPercMstpSsurWnonDnon"}) exitWith {
[_pfID] call CBA_fnc_removePerFrameHandler;
2015-02-17 00:03:09 +00:00
//Break out of hands up animation loop
2015-02-16 00:19:01 +00:00
[_unit, "ACE_AmovPercMstpSsurWnonDnon_AmovPercMstpSnonWnonDnon", 2] call EFUNC(common,doAnimation);
};
2015-02-17 00:03:09 +00:00
}, 0, [_unit, (time + 20)]] call CBA_fnc_addPerFrameHandler;
2015-02-16 00:19:01 +00:00
};
};