From 1b3dcfc07bbbf00e01334cbb59fe37a52f38845c Mon Sep 17 00:00:00 2001 From: commy2 Date: Sat, 14 Mar 2015 11:26:52 +0100 Subject: [PATCH] A3 check if gunlight is turned on --- addons/mapfx/XEH_preInit.sqf | 1 + .../mapfx/functions/fnc_determineMapLight.sqf | 3 +- addons/mapfx/functions/fnc_isGunLightOn.sqf | 42 +++++++++++++++++++ 3 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 addons/mapfx/functions/fnc_isGunLightOn.sqf diff --git a/addons/mapfx/XEH_preInit.sqf b/addons/mapfx/XEH_preInit.sqf index ecdf9cf694..b894367c9a 100644 --- a/addons/mapfx/XEH_preInit.sqf +++ b/addons/mapfx/XEH_preInit.sqf @@ -6,6 +6,7 @@ LOG(MSG_INIT); PREP(determineMapLight); PREP(determineZoom); +PREP(isGunLightOn); PREP(updateMapFx); ADDON = true; diff --git a/addons/mapfx/functions/fnc_determineMapLight.sqf b/addons/mapfx/functions/fnc_determineMapLight.sqf index 2307116b4e..445bd5392d 100644 --- a/addons/mapfx/functions/fnc_determineMapLight.sqf +++ b/addons/mapfx/functions/fnc_determineMapLight.sqf @@ -2,8 +2,7 @@ private ["_darkenMap","_darkenColor","_createLight","_gunlight","_nearObjects","_light"]; -// @todo: Update the way to check for flashlights -_gunlight = isArray(configFile>> "CfgWeapons" >> currentWeapon player >>"ace_gunlight_classes") || {"ACE_MugLite" in weapons player}; +_gunlight = [ACE_player] call FUNC(isGunLightOn); _fnc_blendColor = { EXPLODE_3_PVT(_this,_c1,_c2,_alpha); diff --git a/addons/mapfx/functions/fnc_isGunLightOn.sqf b/addons/mapfx/functions/fnc_isGunLightOn.sqf new file mode 100644 index 0000000000..14b9c98cd1 --- /dev/null +++ b/addons/mapfx/functions/fnc_isGunLightOn.sqf @@ -0,0 +1,42 @@ +/* + * Author: commy2 + * + * Check if the given unit has it's flashlight attachment turned on. + * + * Argument: + * 0: A unit with gunlight (Object) + * + * Return value: + * Unit has flashlight turned on? (Bool). + */ +#include "script_component.hpp" + +private "_unit"; + +_unit = _this select 0; + +private "_weapon"; + +_weapon = currentWeapon _unit; + +// exit if flashlight is turned off +if !(_unit isFlashlightOn _weapon) exitWith {false}; + +// get type of attachment +private "_gunLight"; +_gunLight = switch (_weapon) do { + case (""): {""}; + case (primaryWeapon _unit): { + primaryWeaponItems _unit select 1; + }; + case (secondaryWeapon _unit): { + secondaryWeaponItems _unit select 1; + }; + case (handgunWeapon _unit): { + handgunItems _unit select 1; + }; + default {""}; +}; + +// return false if the gunlight is a day laser +!(toLower _gunLight in ["ace_acc_pointer_red", "ace_acc_pointer_green"])