forked from CBATeam/CBA_A3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fnc_compatibleMagazines.sqf
67 lines (53 loc) · 2.27 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
66
67
#include "script_component.hpp"
/* ----------------------------------------------------------------------------
Function: CBA_fnc_compatibleMagazines
Description:
Retrieves a list of magazines that are compatible with a weapon.
Parameters:
_weapon - Weapon class name or config <STRING, CONFIG>
_allMuzzles - Get magazines for all muzzles on this weapon (optional, default: false) <BOOLEAN>
Returns:
Array of magazine classnames in config capitalization <ARRAY>
Examples:
(begin example)
_mags = ["arifle_MX_SW_F"] call CBA_fnc_compatibleMagazines;
_mags = [configFile >> "CfgWeapons" >> _rifle >> _glMuzzle] call CBA_fnc_compatibleMagazines;
(end)
Author:
PabstMirror, johnb43, based on code from Dedmen
---------------------------------------------------------------------------- */
SCRIPT(compatibleMagazines);
params [["_weapon", "", ["", configNull]], ["_allMuzzles", false, [false]]];
if (_weapon isEqualType "") then {
_weapon = configFile >> "CfgWeapons" >> _weapon;
};
if (isNil QGVAR(magNamespace)) then {
GVAR(magNamespace) = createHashMap;
};
+(GVAR(magNamespace) getOrDefaultCall [format ["%1#%2", _weapon, _allMuzzles], {
if (_allMuzzles) then {
// Get all mags from all muzzles
private _returnMags = createHashMap;
{
if (_x == "this") then {
_returnMags insert [true, _weapon call CBA_fnc_compatibleMagazines, []];
} else {
_returnMags insert [true, (_weapon >> _x) call CBA_fnc_compatibleMagazines, []];
};
} forEach getArray (_weapon >> "muzzles");
keys _returnMags
} else {
// Get mags just for a specific muzzle
private _cfgMagazines = configFile >> "CfgMagazines";
private _cfgMagazineWells = configFile >> "CfgMagazineWells";
private _returnMags = getArray (_weapon >> "magazines") createHashMapFromArray [];
{
{
_returnMags insert [true, (getArray _x) apply {configName (_cfgMagazines >> _x)}, []];
} forEach configProperties [_cfgMagazineWells >> _x, "isArray _x", false];
} forEach (getArray (_weapon >> "magazineWell"));
// Delete invalid entry
_returnMags deleteAt "";
keys _returnMags
};
}, true])