2015-02-04 19:16:19 +00:00
|
|
|
/*
|
|
|
|
* Author: Nic547
|
|
|
|
* Attaches a Captive to the _unit
|
|
|
|
*
|
|
|
|
* Arguments:
|
|
|
|
* 0: _unit-Player <OBJECT>
|
|
|
|
* 1: target <OBJECT>
|
|
|
|
* 2: _state <BOOL>
|
|
|
|
*
|
|
|
|
* Return Value:
|
|
|
|
* The return value <BOOL>
|
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
* -
|
|
|
|
*
|
|
|
|
* Public: No
|
|
|
|
*/
|
|
|
|
#include "script_component.hpp"
|
|
|
|
|
|
|
|
PARAMS_3(_unit,_target,_state);
|
|
|
|
|
|
|
|
if (_state) then {
|
2015-02-06 05:11:28 +00:00
|
|
|
if (_unit getVariable [QGVAR(isEscorting), false]) exitWith {};
|
2015-02-04 19:16:19 +00:00
|
|
|
|
2015-02-06 05:11:28 +00:00
|
|
|
[_unit, _target] call EFUNC(common,claim);
|
|
|
|
_unit setVariable [QGVAR(isEscorting), true, true];
|
2015-02-04 19:16:19 +00:00
|
|
|
|
2015-02-06 05:11:28 +00:00
|
|
|
_target attachTo [_unit, [0, 1, 0]];
|
2015-02-04 19:16:19 +00:00
|
|
|
|
2015-02-06 05:11:28 +00:00
|
|
|
_unit setVariable [QGVAR(escortedUnit), _target, true];
|
2015-02-04 19:16:19 +00:00
|
|
|
|
2015-02-06 05:11:28 +00:00
|
|
|
//Add Actionmenu to release captive
|
|
|
|
_actionID = _unit addAction [format ["<t color='#FF0000'>%1</t>", localize "STR_ACE_Captives_StopEscorting"],
|
|
|
|
{[(_this select 0), ((_this select 0) getVariable [QGVAR(escortedUnit), objNull]), false] call FUNC(doEscortCaptive);},
|
|
|
|
nil, 20, false, true, "", QUOTE(!isNull (GETVAR(_target,QGVAR(escortedUnit),objNull)))];
|
2015-02-04 19:16:19 +00:00
|
|
|
|
2015-02-06 09:38:27 +00:00
|
|
|
private "_escortFnc";
|
|
|
|
_escortFnc = {
|
|
|
|
EXPLODE_3_PVT((_this select 0),_unit,_target,_actionID);
|
|
|
|
if (_unit getVariable [QGVAR(isEscorting), false]) then {
|
2015-02-06 05:11:28 +00:00
|
|
|
if (!alive _target || {!alive _unit} || {!canStand _target} || {!canStand _unit} || {_target getVariable ["ACE_isUnconscious", false]} || {_unit getVariable ["ACE_isUnconscious", false]} || {!isNull (attachedTo _unit)}) then {
|
|
|
|
_unit setVariable [QGVAR(isEscorting), false, true];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2015-02-06 09:38:27 +00:00
|
|
|
if (!(_unit getVariable [QGVAR(isEscorting), false])) then {
|
|
|
|
[(_this select 1)] call cba_fnc_removePerFrameHandler;
|
|
|
|
[objNull, _target] call EFUNC(common,claim);
|
|
|
|
detach _target;
|
|
|
|
_unit removeAction _actionID;
|
|
|
|
_unit setVariable [QGVAR(escortedUnit), objNull, true];
|
|
|
|
};
|
2015-02-06 05:11:28 +00:00
|
|
|
};
|
2015-02-06 09:38:27 +00:00
|
|
|
[_escortFnc, 0.2, [_unit, _target, _actionID]] call CBA_fnc_addPerFrameHandler;
|
|
|
|
|
2015-02-04 19:16:19 +00:00
|
|
|
} else {
|
2015-02-06 05:11:28 +00:00
|
|
|
_unit setVariable [QGVAR(isEscorting), false, true];
|
|
|
|
_unit setVariable [QGVAR(escortedUnit), objNull, true];
|
2015-02-04 19:16:19 +00:00
|
|
|
};
|