ACE3/addons/attach/functions/fnc_canDetach.sqf

41 lines
1.0 KiB
Plaintext
Raw Normal View History

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
*/
#include "script_component.hpp"
2015-01-11 20:39:49 +00:00
PARAMS_2(_attachToVehicle,_unit);
2015-01-11 20:39:49 +00:00
2015-02-15 14:31:09 +00:00
private ["_attachedObjects", "_inRange"];
_attachedObjects = _attachToVehicle getVariable [QGVAR(Objects), []];
_inRange = false;
if (_unit == _attachToVehicle) then {
2015-02-15 14:31:09 +00:00
_inRange = count _attachedObjects > 0;
} else {
2015-02-01 20:56:19 +00:00
//Scan if unit is within range (using 2d distance)
2015-02-15 14:31:09 +00:00
private ["_unitPos", "_objectPos"];
2015-02-01 20:56:19 +00:00
_unitPos = getPos _unit;
_unitPos set [2,0];
{
_objectPos = getPos _x;
_objectPos set [2, 0];
2015-02-15 14:31:09 +00:00
if (_objectPos distance _unitPos < 4) exitWith {_inRange = true};
2015-02-01 20:56:19 +00:00
} forEach _attachedObjects;
};
2015-02-15 14:31:09 +00:00
canStand _unit && {_inRange} && {alive _attachToVehicle}