-
Notifications
You must be signed in to change notification settings - Fork 149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add CBA_fnc_compatibleMagazines that supports mag wells #965
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#include "script_component.hpp" | ||
/* ---------------------------------------------------------------------------- | ||
Function: CBA_fnc_compatibleMagazines | ||
|
||
Description: | ||
Retrievs 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 | ||
(end) | ||
|
||
Returns: | ||
Array of magazine classnames <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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this could be replaced with early return There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't forget to copy the returned array, otherwise someone will mess up the cache by editing it by reference. |
||
_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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Retrieves