-
Notifications
You must be signed in to change notification settings - Fork 148
/
fnc_compatibleMagazines.sqf
65 lines (53 loc) · 2.37 KB
/
fnc_compatibleMagazines.sqf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#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
_allMuzzles - Get magazines for all muzzles on this weapon (default: false)
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]], ["_allMuzzles", false, [false]]];
if (_weapon isEqualType "") then {
_weapon = configFile >> "CfgWeapons" >> _weapon;
};
private _cacheKey = format ["%1#%2",_weapon,_allMuzzles];
if (isNil QGVAR(magNamespace)) then { GVAR(magNamespace) = call CBA_fnc_createNamespace; };
private _returnMags = GVAR(magNamespace) getVariable _cacheKey;
if (isNil "_returnMags") then {
if (_allMuzzles) then {
_returnMags = []; // get all mags from all muzzles
{
if (_x == "this") then {
_returnMags append (_weapon call CBA_fnc_compatibleMagazines);
} else {
_returnMags append ((_weapon >> _x) call CBA_fnc_compatibleMagazines);
};
} forEach getArray (_weapon >> "muzzles");
_returnMags = _returnMags arrayIntersect _returnMags;
} else {
_returnMags = getArray (_weapon >> "magazines"); // get mags just for a specific muzzle
{
private _wellConfig = configFile >> "CfgMagazineWells" >> _x;
{
_returnMags append getArray _x;
} forEach configProperties [_wellConfig, "isArray _x", false];
} 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