ACE3/addons/minedetector/functions/fnc_getDetectedObject.sqf
Grim 59af3e1f6d
General - Change CBA Namespaces to HashMap (#8801)
* medical_treatment

* advanced_throwing

* common, csw

* Update fnc_replaceRegisteredItems.sqf

* Sanitised numerous components

* Update XEH_postInit.sqf

* Update XEH_postInit.sqf

* FUNC -> LINKFUNC

* Changed tagging hashmap

* Reverted some changes

* Reverted some changes

* Update XEH_clientInit.sqf

* Tweaks and fixes

* Fix number replacements

* Minor cleanup

* Update fnc_getMagazineName.sqf

* Update fnc_getMagazineName.sqf

* Minor improvement

* Made factions case-sensitive and added `toLowerANSI` to be safe

* Update fnc_getDetectedObject.sqf

* Update addons/common/functions/fnc_actionKeysNamesConverted.sqf

Co-authored-by: Grim <69561145+LinkIsGrim@users.noreply.github.com>

* Throw error if item doesn't exist

---------

Co-authored-by: Salluci <69561145+Salluci@users.noreply.github.com>
Co-authored-by: johnb432 <58661205+johnb432@users.noreply.github.com>
2024-06-11 12:34:32 -03:00

55 lines
1.6 KiB
Plaintext

#include "..\script_component.hpp"
/*
* Author: Glowbal
* Get the distance to the nearest detectable object
*
* Arguments:
* 0: Unit <OBJECT>
* 1: Configuration <ARRAY>
*
* Return Value:
* [isDetected <BOOL>, mine <OBJECT>, distance <NUMBER>] <ARRAY>
*
* Example:
* [ace_player, DETECTOR_CONFIG] call ace_minedetector_fnc_getDetectedObject
*
* Public: No
*/
params ["_unit", "_detectorConfig"];
_detectorConfig params ["", "_radius"];
private _worldPosition = _unit modelToWorld (_unit selectionPosition "granat");
private _ref = (_unit weaponDirection currentWeapon _unit) call EFUNC(common,createOrthonormalReference);
_ref params ["_v1", "_v2", "_v3"];
private _detectorPointAGL = _worldPosition vectorAdd
(_v1 vectorMultiply ( 0.9 * __DR)) vectorAdd
(_v2 vectorMultiply (-0.2 * __DR)) vectorAdd
(_v3 vectorMultiply ( 0.4 * __DR));
private _nearestObjects = nearestObjects [_detectorPointAGL, [], _radius];
#ifdef DEBUG_MODE_FULL
GVAR(debugDetector) = [_detectorPointAGL, _nearestObjects];
#endif
private _isDetectable = false;
private _mine = objNull;
private _distance = -1;
{
if ((getModelInfo _x) select 0 == "empty.p3d") then {
continue;
};
// If an object was detected, exit the search
if ((typeOf _x) in (uiNamespace getVariable QGVAR(detectableClasses))) exitWith {
_isDetectable = true;
_distance = _detectorPointAGL distance _x;
_mine = _x;
TRACE_3("return",_isDetectable,_mine,_distance);
};
} forEach _nearestObjects;
[_isDetectable, _mine, _distance];