ACE3/addons/attach/functions/fnc_canDetach.sqf
jonpas 742626ff1a
General - Relative script_component.hpp includes (#9378)
Co-authored-by: PabstMirror <pabstmirror@gmail.com>
2023-09-12 20:58:10 +02:00

41 lines
1.1 KiB
Plaintext

#include "..\script_component.hpp"
/*
* 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>
*
* Return Value:
* Can Detach <BOOL>
*
* Example:
* [bob, bob] call ace_attach_fnc_canDetach;
*
* Public: No
*/
params ["_attachToVehicle", "_unit"];
TRACE_2("params",_attachToVehicle,_unit);
if ((vehicle _unit) != _unit) exitWith {false};
private _attachedList = _attachToVehicle getVariable [QGVAR(attached), []];
if ((count _attachedList) == 0) exitWith {false};
private _inRange = false;
{
_x params ["_xObject"];
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};
} forEach _attachedList;
_inRange &&
{(_unit == _attachToVehicle) || {canStand _unit}} &&
{alive _attachToVehicle}