From 0d126dc5621236a388c4b99c5ed634f9307f6b02 Mon Sep 17 00:00:00 2001 From: commy2 Date: Tue, 7 Apr 2015 14:44:34 +0200 Subject: [PATCH] function to return object's lights --- addons/common/XEH_preInit.sqf | 1 + .../fnc_getReflectorsWithSelections.sqf | 45 +++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 addons/common/functions/fnc_getReflectorsWithSelections.sqf diff --git a/addons/common/XEH_preInit.sqf b/addons/common/XEH_preInit.sqf index 6db323a9f4..d61dc8b351 100644 --- a/addons/common/XEH_preInit.sqf +++ b/addons/common/XEH_preInit.sqf @@ -189,6 +189,7 @@ PREP(getConfigGunner); PREP(getConfigCommander); PREP(getHitPoints); PREP(getHitPointsWithSelections); +PREP(getReflectorsWithSelections); PREP(getVehicleCrew); // turrets diff --git a/addons/common/functions/fnc_getReflectorsWithSelections.sqf b/addons/common/functions/fnc_getReflectorsWithSelections.sqf new file mode 100644 index 0000000000..6d47943155 --- /dev/null +++ b/addons/common/functions/fnc_getReflectorsWithSelections.sqf @@ -0,0 +1,45 @@ +/* + * Author: commy2 + * + * Returns all lighting hitpoints of any vehicle. + * Note: These are actual selections that are affected by setHit and getHit, not getHitPointDamage or setHitpointDamage. + * They behave like having an armor value of 0. + * + * Arguments: + * 0: A vehicle, not the classname (Object) + * + * Return Value: + * The light names and selections (Array) + */ +#include "script_component.hpp" + +private ["_vehicle", "_config", "_hitpoints", "_selections"]; + +_vehicle = _this select 0; + +_config = configFile >> "CfgVehicles" >> typeOf _vehicle; + +_hitpoints = []; +_selections = []; + +// iterate through all parents +while {isClass _config} do { + private "_class"; + _class = _config >> "Reflectors"; + + for "_i" from 0 to (count _class - 1) do { + private ["_entry", "_selection"]; + + _entry = _class select _i; + _selection = getText (_entry >> "hitpoint"); + + if (!(_selection in _selections) && {!isNil {_vehicle getHit _selection}}) then { + _hitpoints pushBack configName _entry; + _selections pushBack _selection; + }; + }; + + _config = inheritsFrom _config; +}; + +[_hitPoints, _selections]