diff --git a/addons/common/CfgFunctions.hpp b/addons/common/CfgFunctions.hpp index 2ac70f691..d6ad244bd 100644 --- a/addons/common/CfgFunctions.hpp +++ b/addons/common/CfgFunctions.hpp @@ -65,6 +65,7 @@ class CfgFunctions { PATHTO_FNC(removeWeapon); PATHTO_FNC(removeMagazine); PATHTO_FNC(removeItem); + PATHTO_FNC(uniqueUnitItems); PATHTO_FNC(weaponComponents); PATHTO_FNC(dropWeapon); PATHTO_FNC(dropMagazine); diff --git a/addons/common/fnc_uniqueUnitItems.sqf b/addons/common/fnc_uniqueUnitItems.sqf new file mode 100644 index 000000000..d4ba7a139 --- /dev/null +++ b/addons/common/fnc_uniqueUnitItems.sqf @@ -0,0 +1,48 @@ +/* ---------------------------------------------------------------------------- +Function: CBA_fnc_uniqueUnitItems + +Description: + Retrievs a unique list of items in the units inventory. + +Parameters: + _unit - Unit to retrieve the items from + _weaponItems - Include weapons, attachments, loaded magazines (Default: false) + _backpack - Include items in backpack (Default: true) + _vest - Include items in vest (Default: true) + _uniform - Include items in uniform (Default: true) + +Example: + (begin example) + _allItems = [player, true, false] call CBA_fnc_uniqueUnitItems + (end) + +Returns: + Array of item classnames + +Author: + Dedmen +---------------------------------------------------------------------------- */ +#include "script_component.hpp" +SCRIPT(uniqueUnitItems); + +params [["_unit", objNull, [objNull]], ["_weaponItems", true, [true]], ["_backpack", true, [true]], ["_vest", true, [true]], ["_uniform", true, [true]]]; + +private _allItems = (assignedItems _unit); +if (_uniform) then {_allItems append ((getItemCargo (uniformContainer _unit)) select 0);}; +if (_vest) then {_allItems append ((getItemCargo (vestContainer _unit)) select 0);}; +if (_backpack) then {_allItems append ((getItemCargo (backpackContainer _unit)) select 0);}; + +if (_weaponItems) then { + _allItems append (primaryWeaponItems _unit); + _allItems append (secondaryWeaponItems _unit); + _allItems append (handgunItems _unit); + _allItems append (primaryWeaponMagazine _unit); + _allItems append (secondaryWeaponMagazine _unit); + _allItems append (handgunMagazine _unit); + _allItems append [ + primaryWeapon _unit, secondaryWeapon _unit, handgunWeapon _unit + ]; + _allItems pushBack (_unit call CBA_fnc_binocularMagazine); +}; + +_allItems arrayIntersect _allItems //Remove duplicates