ACE3/addons/captives/functions/fnc_setSurrendered.sqf

116 lines
5.0 KiB
Plaintext
Raw Normal View History

#include "..\script_component.hpp"
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:
* 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
*/
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 {
WARNING("running surrender on remote unit");
2015-02-07 04:24:27 +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
[DFUNC(setSurrendered), _this, 0.05] call CBA_fnc_waitAndExecute;
} 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 {
WARNING("Surrender: current state same as new");
2015-02-07 04:24:27 +00:00
};
if (_state) then {
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
[_unit, "setCaptive", QGVAR(surrendered), true] call EFUNC(common,statusEffect_set);
[_unit, "blockRadio", QGVAR(surrendered), true] call EFUNC(common,statusEffect_set);
if (_unit == ACE_player) then {
["captive", [false, false, false, false, false, false, false, false, false, true]] call EFUNC(common,showHud);
};
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];
};
}, [_unit], 0.01] call CBA_fnc_waitAndExecute;
} else {
_unit setVariable [QGVAR(isSurrendering), false, true];
[_unit, "setCaptive", QGVAR(surrendered), false] call EFUNC(common,statusEffect_set);
[_unit, "blockRadio", QGVAR(surrendered), false] call EFUNC(common,statusEffect_set);
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];
_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
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
if !(_unit call EFUNC(common,isAwake)) exitWith {}; //don't touch animations if unconscious
2015-02-17 00:03:09 +00:00
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
if ((CBA_missionTime > _maxTime) || {_unit getVariable [QGVAR(isSurrendering), false]} || {!(_unit call EFUNC(common,isAwake))}) 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-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;