ACE3/addons/captives/functions/fnc_doEscortCaptive.sqf

60 lines
2.0 KiB
Plaintext
Raw Normal View History

#include "..\script_component.hpp"
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:
2021-04-08 18:35:10 +00:00
* [player, bob, true] call ACE_captives_fnc_doEscortCaptive;
2015-02-04 19:16:19 +00:00
*
* Public: No
*/
params ["_unit", "_target","_state"];
2015-02-04 19:16:19 +00:00
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-04-25 21:03:21 +00:00
[_unit, _target, false] call EFUNC(common,claim);
2015-02-06 05:11:28 +00:00
_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
private _actionID = _unit addAction [format ["<t color='#FF0000'>%1</t>", localize LSTRING(StopEscorting)],
2015-02-06 05:11:28 +00:00
{[(_this select 0), ((_this select 0) getVariable [QGVAR(escortedUnit), objNull]), false] call FUNC(doEscortCaptive);},
2017-12-30 13:38:45 +00:00
nil, 20, false, true, "", QUOTE(!isNull GETVAR(_target,QGVAR(escortedUnit),objNull))];
2015-02-04 19:16:19 +00:00
2015-04-25 21:03:21 +00:00
[{
2015-08-23 07:29:51 +00:00
params ["_args", "_pfID"];
_args params ["_unit", "_target", "_actionID"];
2016-05-03 00:32:44 +00:00
2015-02-06 09:38:27 +00:00
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 {
2015-11-30 15:45:20 +00:00
[(_this select 1)] call CBA_fnc_removePerFrameHandler;
2015-04-25 21:03:21 +00:00
[objNull, _target, false] call EFUNC(common,claim);
2015-02-06 09:38:27 +00:00
detach _target;
_unit removeAction _actionID;
_unit setVariable [QGVAR(escortedUnit), objNull, true];
};
2015-04-25 21:03:21 +00:00
}, 0, [_unit, _target, _actionID]] call CBA_fnc_addPerFrameHandler;
2015-02-06 09:38:27 +00:00
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
};