ACE3/addons/minedetector/functions/fnc_getDetectedObject.sqf
Dedmen Miller e2ac18a05d [WIP] Fix script errors reporting wrong line numbers (#6407)
* advanced_ballistics

* advanced_fatigue

* advanced_throwing

* ai

* aircraft

* arsenal

* atragmx

* attach

* backpacks

* ballistics

* captives

* cargo

* chemlights

* common

* concertina_wire

* cookoff

* dagr

* disarming

* disposable

* dogtags

* dragging

* explosives

* fastroping

* fcs

* finger

* frag

* gestures

* gforces

* goggles

* grenades

* gunbag

* hearing

* hitreactions

* huntir

* interact_menu

* interaction

* inventory

* kestrel4500

* laser

* laserpointer

* logistics_uavbattery

* logistics_wirecutter

* magazinerepack

* map

* map_gestures

* maptools

* markers

* medical

* medical_ai

* medical_blood

* medical_menu

* microdagr

* minedetector

* missileguidance

* missionmodules

* mk6mortar

* modules

* movement

* nametags

* nightvision

* nlaw

* optics

* optionsmenu

* overheating

* overpressure

* parachute

* pylons

* quickmount

* rangecard

* rearm

* recoil

* refuel

* reload

* reloadlaunchers

* repair

* respawn

* safemode

* sandbag

* scopes

* slideshow

* spectator

* spottingscope

* switchunits

* tacticalladder

* tagging

* trenches

* tripod

* ui

* vector

* vehiclelock

* vehicles

* viewdistance

* weaponselect

* weather

* winddeflection

* yardage450

* zeus

* arsenal defines.hpp

* optionals

* DEBUG_MODE_FULL 1

* DEBUG_MODE_FULL 2

* Manual fixes

* Add SQF Validator check for #include after block comment

* explosives fnc_openTimerUI

* fix uniqueItems
2018-09-17 14:19:29 -05:00

57 lines
1.7 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;
{
private _objectType = typeOf _x;
_isDetectable = GVAR(detectableClasses) getVariable _objectType;
if (isNil "_isDetectable" || {(getModelInfo _x) select 0 == "empty.p3d"}) then {
_isDetectable = false;
};
// If a nun-null object was detected exit the search
if (_isDetectable && {!isNull _x}) exitWith {
_distance = _detectorPointAGL distance _x;
_mine = _x;
TRACE_3("return", _isDetectable, _mine, _distance);
};
} forEach _nearestObjects;
[_isDetectable, _mine, _distance];