ACE3/addons/attach/functions/fnc_canDetach.sqf

41 lines
1.1 KiB
Plaintext
Raw Normal View History

#include "..\script_component.hpp"
2015-01-11 20:39:49 +00:00
/*
2015-02-01 20:56:19 +00:00
* Author: commy2
* Check if a unit has an item attached and if it can remove that item.
*
* Arguments:
* 0: vehicle that it will be detached from (player or vehicle) <OBJECT>
* 1: unit doing the detaching (player) <OBJECT>
2015-02-01 20:56:19 +00:00
*
* Return Value:
2015-03-27 17:08:05 +00:00
* Can Detach <BOOL>
2015-02-01 20:56:19 +00:00
*
* Example:
2015-03-27 17:08:05 +00:00
* [bob, bob] call ace_attach_fnc_canDetach;
2015-02-01 20:56:19 +00:00
*
* Public: No
*/
2015-01-11 20:39:49 +00:00
params ["_attachToVehicle", "_unit"];
2015-08-06 18:17:59 +00:00
TRACE_2("params",_attachToVehicle,_unit);
2015-02-15 14:31:09 +00:00
if ((vehicle _unit) != _unit) exitWith {false};
private _attachedList = _attachToVehicle getVariable [QGVAR(attached), []];
2015-08-29 16:47:56 +00:00
if ((count _attachedList) == 0) exitWith {false};
private _inRange = false;
{
_x params ["_xObject"];
2015-08-29 16:47:56 +00:00
if (isNull _xObject) exitWith {
TRACE_1("Null attached",_x);
_attachedList deleteAt _forEachIndex;
_attachToVehicle setVariable [QGVAR(attached), _attachedList, true];
};
if (((getPos _unit) distance2d (getPos _xObject)) < 4) exitWith {_inRange = true};
2015-08-29 16:47:56 +00:00
} forEach _attachedList;
_inRange &&
{(_unit == _attachToVehicle) || {canStand _unit}} &&
{alive _attachToVehicle}