Skip to content

Commit

Permalink
Add CBA_fnc_compatibleMagazines that supports mag wells (#965)
Browse files Browse the repository at this point in the history
* Add CBA_fnc_getCompatibleMagazines that supports mag wells

* Make filtering optional

* Catching

* Fix Header
  • Loading branch information
PabstMirror authored and commy2 committed Aug 25, 2018
1 parent b75ca63 commit a88fc7b
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
1 change: 1 addition & 0 deletions addons/common/CfgFunctions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class CfgFunctions {
PATHTO_FNC(addWeapon);
PATHTO_FNC(addMagazine);
PATHTO_FNC(addItem);
PATHTO_FNC(compatibleMagazines);
PATHTO_FNC(removeWeapon);
PATHTO_FNC(removeMagazine);
PATHTO_FNC(removeItem);
Expand Down
55 changes: 55 additions & 0 deletions addons/common/fnc_compatibleMagazines.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#include "script_component.hpp"
/* ----------------------------------------------------------------------------
Function: CBA_fnc_compatibleMagazines
Description:
Retrieves a list of magazines that are compatible with a weapon.
Parameters:
_weapon - Weapon configName or config
Example:
(begin example)
_mags = ["arifle_MX_SW_F"] call CBA_fnc_compatibleMagazines
_mags = [configFile >> "CfgWeapons" >> _rifle >> _glMuzzle] call CBA_fnc_compatibleMagazines
(end)
Returns:
Array of magazine classnames in config capitalization <ARRAY>
Author:
PabstMirror, based on code from Dedmen
---------------------------------------------------------------------------- */
SCRIPT(compatibleMagazines);

params [["_weapon", "", ["", configNull]]];

if (_weapon isEqualType "") then {
_weapon = configFile >> "CfgWeapons" >> _weapon;
};

private _cacheKey = str _weapon;
if (_cacheKey == "") exitWith { ERROR_1("Weapon Does Not Exist %1",_this); [] };

if (isNil QGVAR(magNamespace)) then { GVAR(magNamespace) = call CBA_fnc_createNamespace; };

private _returnMags = GVAR(magNamespace) getVariable _cacheKey;

if (isNil "_returnMags") then {
_returnMags = getArray (_weapon >> "magazines");
{
private _wellConfig = configFile >> "CfgMagazineWells" >> _x;
{
_returnMags append getArray _x;
} forEach configProperties [_wellConfig, "isArray _x", true];
} forEach (getArray (_weapon >> "magazineWell"));

private _cfgMagazines = configFile >> "CfgMagazines";
_returnMags = _returnMags select {isClass (_cfgMagazines >> _x)};
_returnMags = _returnMags apply {configName (_cfgMagazines >> _x)};
_returnMags = _returnMags arrayIntersect _returnMags;

GVAR(magNamespace) setVariable [_cacheKey, _returnMags];
};

+_returnMags

0 comments on commit a88fc7b

Please sign in to comment.