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:
|
2017-06-08 13:31:51 +00:00
|
|
|
* None
|
2015-02-03 02:04:50 +00:00
|
|
|
*
|
|
|
|
* 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"
|
|
|
|
|
2015-08-04 23:15:20 +00:00
|
|
|
params ["_unit","_state"];
|
2015-08-23 17:32:46 +00:00
|
|
|
TRACE_2("params",_unit,_state);
|
2015-02-17 00:03:09 +00:00
|
|
|
|
2015-11-30 16:14:05 +00:00
|
|
|
if (!local _unit) exitWith {
|
2016-09-13 21:52:51 +00:00
|
|
|
WARNING("running surrender on remote unit");
|
2015-02-07 04:24:27 +00:00
|
|
|
};
|
2015-01-11 16:42:31 +00:00
|
|
|
|
2016-02-20 14:57:47 +00:00
|
|
|
if !(missionNamespace getVariable [QGVAR(captivityEnabled), false]) exitWith {
|
|
|
|
// It's to soon to call this function, delay it
|
|
|
|
if (EGVAR(common,settingsInitFinished)) then {
|
|
|
|
// Settings are already initialized, but the small wait isn't over
|
2016-05-22 13:27:24 +00:00
|
|
|
[DFUNC(setSurrendered), _this, 0.05] call CBA_fnc_waitAndExecute;
|
2016-02-20 14:57:47 +00:00
|
|
|
} else {
|
|
|
|
// Settings are not initialized yet
|
|
|
|
[DFUNC(setSurrendered), _this] call EFUNC(common,runAfterSettingsInit);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2015-02-17 00:03:09 +00:00
|
|
|
if ((_unit getVariable [QGVAR(isSurrendering), false]) isEqualTo _state) exitWith {
|
2016-09-13 21:52:51 +00:00
|
|
|
WARNING("Surrender: current state same as new");
|
2015-02-07 04:24:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
if (_state) then {
|
2016-09-13 21:52:51 +00:00
|
|
|
if ((vehicle _unit) != _unit) exitWith {WARNING("Cannot surrender while mounted");};
|
|
|
|
if (_unit getVariable [QGVAR(isHandcuffed), false]) exitWith {WARNING("Cannot surrender while handcuffed");};
|
2015-02-17 00:03:09 +00:00
|
|
|
|
2015-02-06 21:54:26 +00:00
|
|
|
_unit setVariable [QGVAR(isSurrendering), true, true];
|
2015-02-17 00:03:09 +00:00
|
|
|
|
2016-01-19 15:34:59 +00:00
|
|
|
[_unit, "setCaptive", QGVAR(Surrendered), true] call EFUNC(common,statusEffect_set);
|
2015-02-15 22:42:00 +00:00
|
|
|
|
|
|
|
if (_unit == ACE_player) then {
|
2016-09-29 22:53:17 +00:00
|
|
|
["captive", [false, false, false, false, false, false, false, false]] call EFUNC(common,showHud);
|
2015-02-15 22:42:00 +00:00
|
|
|
};
|
|
|
|
|
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)
|
|
|
|
[{
|
2015-08-15 02:29:01 +00:00
|
|
|
params ["_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)
|
2015-11-17 16:43:07 +00:00
|
|
|
private _animChangedEHID = _unit getVariable [QGVAR(surrenderAnimEHID), -1];
|
2015-10-23 18:11:11 +00:00
|
|
|
if (_animChangedEHID != -1) then {
|
|
|
|
TRACE_1("removing animChanged EH",_animChangedEHID);
|
|
|
|
_unit removeEventHandler ["AnimChanged", _animChangedEHID];
|
|
|
|
};
|
2018-05-30 22:39:28 +00:00
|
|
|
_animChangedEHID = _unit addEventHandler ["AnimChanged", {call FUNC(handleAnimChangedSurrendered)}];
|
2015-02-17 00:03:09 +00:00
|
|
|
_unit setVariable [QGVAR(surrenderAnimEHID), _animChangedEHID];
|
|
|
|
};
|
2016-05-22 13:27:24 +00:00
|
|
|
}, [_unit], 0.01] call CBA_fnc_waitAndExecute;
|
2015-02-15 22:42:00 +00:00
|
|
|
} else {
|
|
|
|
_unit setVariable [QGVAR(isSurrendering), false, true];
|
2016-01-19 15:34:59 +00:00
|
|
|
[_unit, "setCaptive", QGVAR(Surrendered), false] call EFUNC(common,statusEffect_set);
|
2015-02-15 22:42:00 +00:00
|
|
|
|
2015-02-17 00:03:09 +00:00
|
|
|
//remove AnimChanged EH
|
2015-11-17 16:43:07 +00:00
|
|
|
private _animChangedEHID = _unit getVariable [QGVAR(surrenderAnimEHID), -1];
|
2015-02-15 22:42:00 +00:00
|
|
|
_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 {
|
2015-10-16 03:45:35 +00:00
|
|
|
["captive", []] call EFUNC(common,showHud); //same as showHud true;
|
2015-02-06 21:54:26 +00:00
|
|
|
};
|
|
|
|
};
|
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
|
|
|
|
[{
|
2015-08-15 02:29:01 +00:00
|
|
|
params ["_args", "_pfID"];
|
|
|
|
_args params ["_unit", "_maxTime"];
|
2015-02-17 00:03:09 +00:00
|
|
|
//If waited long enough or they re-surrendered or they are unconscious, exit loop
|
2016-03-02 10:01:39 +00:00
|
|
|
if ((CBA_missionTime > _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);
|
|
|
|
};
|
2016-03-02 10:01:39 +00:00
|
|
|
}, 0, [_unit, (CBA_missionTime + 20)]] call CBA_fnc_addPerFrameHandler;
|
2015-02-16 00:19:01 +00:00
|
|
|
};
|
2015-01-11 16:42:31 +00:00
|
|
|
};
|
2015-09-29 15:17:17 +00:00
|
|
|
|
|
|
|
//Global Event after changes:
|
2016-05-24 13:13:11 +00:00
|
|
|
["ace_captiveStatusChanged", [_unit, _state, "SetSurrendered"]] call CBA_fnc_globalEvent;
|