ACE3/addons/captives/functions/fnc_surrender.sqf

77 lines
2.5 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>
* 1: State <BOOL>
*
* Return Value:
* Nothing
*
* Example:
2015-02-06 23:03:56 +00:00
* [Pierre, true] call ACE_captives_fnc_surrender;
2015-02-03 02:04:50 +00:00
*
* Public: No
*/
#include "script_component.hpp"
PARAMS_2(_unit,_state);
2015-02-07 04:24:27 +00:00
// We only want this function to work on local machines
if (!local _unit) exitwith {
[_this, QUOTE(FUNC(surrender)), _unit] call EFUNC(common,execRemoteFnc);
TRACE_2("running surrender on remote unit",_unit,_state);
};
2015-02-07 04:24:27 +00:00
if ((_unit getVariable [QGVAR(isSurrendering), false]) isEqualTo _state) then {
LOG("Surrender: current state same as new");
};
if (_state) then {
2015-02-06 21:54:26 +00:00
_unit setVariable [QGVAR(isSurrendering), true, true];
[_unit, QGVAR(Surrendered), true] call EFUNC(common,setCaptivityStatus);
2015-02-06 23:03:56 +00:00
if (_unit == ACE_player) then {
showHUD false;
};
2015-02-07 04:24:27 +00:00
// fix anim on mission start (should work on dedicated servers)
[{
PARAMS_1(_unit);
if (_unit getVariable [QGVAR(isSurrendering), false] && {vehicle _unit == _unit}) then {
[_unit] call EFUNC(common,fixLoweredRifleAnimation);
[_unit, "ACE_AmovPercMstpSsurWnonDnon", 1] call EFUNC(common,doAnimation);
};
}, [_unit], 0.01, 0] call EFUNC(common,waitAndExecute);
2015-02-06 21:54:26 +00:00
2015-02-07 04:24:27 +00:00
//PFEH - (TODO: move to event system?)
[{
EXPLODE_1_PVT((_this select 0),_unit);
2015-02-06 21:54:26 +00:00
if (_unit getVariable [QGVAR(isSurrendering), false]) then {
2015-02-07 04:24:27 +00:00
//If unit dies, gets knocked out, or is handcuffed then end surrender
2015-02-06 09:38:27 +00:00
if ((!alive _unit) || {_unit getVariable ["ACE_isUnconscious", false]} || {_unit getVariable [QGVAR(isHandcuffed), false]}) then {
2015-02-06 21:54:26 +00:00
[_unit, false] call FUNC(surrender);
2015-02-07 04:24:27 +00:00
[(_this select 1)] call CBA_fnc_removePerFrameHandler;
2015-02-04 05:56:51 +00:00
};
2015-02-06 21:54:26 +00:00
} else {
2015-02-06 09:38:27 +00:00
[(_this select 1)] call cba_fnc_removePerFrameHandler;
};
2015-02-07 04:24:27 +00:00
}, 0.0, [_unit]] call CBA_fnc_addPerFrameHandler;
} else {
2015-02-06 21:54:26 +00:00
_unit setVariable [QGVAR(isSurrendering), false, true];
2015-02-07 04:24:27 +00:00
[_unit, QGVAR(Surrendered), false] call EFUNC(common,setCaptivityStatus);
2015-02-06 21:54:26 +00:00
2015-02-07 04:24:27 +00:00
if ((vehicle _unit) == _unit) then {
//Break out of hands up animation loop (doAnimation handles Unconscious prioity)
2015-02-06 21:54:26 +00:00
[_unit, "ACE_AmovPercMstpSsurWnonDnon_AmovPercMstpSnonWnonDnon", 2] call EFUNC(common,doAnimation);
};
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;
};
};
};