From 13ec08ea9043ea421982b537f8a69386da37cd83 Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Mon, 22 May 2017 13:11:49 -0500 Subject: [PATCH] Remove unit from laser pointer list if laser removed --- addons/laserpointer/XEH_postInit.sqf | 29 ++++++++++--------- .../functions/fnc_getNearUnits.sqf | 4 +-- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/addons/laserpointer/XEH_postInit.sqf b/addons/laserpointer/XEH_postInit.sqf index d8857da32a0..7e90e29259b 100644 --- a/addons/laserpointer/XEH_postInit.sqf +++ b/addons/laserpointer/XEH_postInit.sqf @@ -41,9 +41,16 @@ GVAR(greenLaserUnits) = []; params ["_unit"]; private _weapon = currentWeapon _unit; + if (!(_unit isFlashlightOn _weapon)) exitWith { + GVAR(redLaserUnits) deleteAt (GVAR(redLaserUnits) find _unit); + GVAR(greenLaserUnits) deleteAt (GVAR(greenLaserUnits) find _unit); + }; + private _laser = [(_unit weaponAccessories _weapon) select 1] param [0, ""]; - - if (_laser isEqualTo "") exitWith {}; + if (_laser isEqualTo "") exitWith { + GVAR(redLaserUnits) deleteAt (GVAR(redLaserUnits) find _unit); + GVAR(greenLaserUnits) deleteAt (GVAR(greenLaserUnits) find _unit); + }; private _laserID = GVAR(laserClassesCache) getVariable _laser; @@ -51,20 +58,16 @@ GVAR(greenLaserUnits) = []; _laserID = getNumber (configFile >> "CfgWeapons" >> _laser >> "ACE_laserpointer"); GVAR(laserClassesCache) setVariable [_laser, _laserID]; }; + TRACE_3("",_weapon,_laser,_laserID); - if (_unit isFlashlightOn _weapon) then { - if (_laserID isEqualTo 1) exitWith { - GVAR(redLaserUnits) pushBackUnique _unit; - GVAR(greenLaserUnits) deleteAt (GVAR(greenLaserUnits) find _unit); - }; + if (_laserID isEqualTo 1) exitWith { + GVAR(redLaserUnits) pushBackUnique _unit; + GVAR(greenLaserUnits) deleteAt (GVAR(greenLaserUnits) find _unit); + }; - if (_laserID isEqualTo 2) exitWith { - GVAR(greenLaserUnits) pushBackUnique _unit; - GVAR(redLaserUnits) deleteAt (GVAR(redLaserUnits) find _unit); - }; - } else { + if (_laserID isEqualTo 2) exitWith { + GVAR(greenLaserUnits) pushBackUnique _unit; GVAR(redLaserUnits) deleteAt (GVAR(redLaserUnits) find _unit); - GVAR(greenLaserUnits) deleteAt (GVAR(greenLaserUnits) find _unit); }; }; diff --git a/addons/laserpointer/functions/fnc_getNearUnits.sqf b/addons/laserpointer/functions/fnc_getNearUnits.sqf index 6f31a99a2ac..eb505c37950 100644 --- a/addons/laserpointer/functions/fnc_getNearUnits.sqf +++ b/addons/laserpointer/functions/fnc_getNearUnits.sqf @@ -6,7 +6,7 @@ * None * * Return Value: - * None + * Near Units * * Public: No */ @@ -15,7 +15,7 @@ private _camPosAGL = positionCameraToWorld [0, 0, 0]; // handle RHS / bugged vehicle slots -if !((_camPosAGL select 0) isEqualType 0) exitWith {}; +if !((_camPosAGL select 0) isEqualType 0) exitWith { [] }; private _nearUnits = [];