Jump to content
Sign in to follow this  
demonized

How to get magazine for rifle from cfgWeapon? and a muzzle question

Recommended Posts

Hello all, my cfg use knowledge is pretty much non existing.

1: How can i get the magazine for a weapon from cfgWeapons or cfgMagazines?

"assume" my weapon is the BAF rifle and i dont know the classname for the magazine.

_weapon = "BAF_L85A2_UGL_ACOG";
_magazine = <code to find usable magazine>????  // what should i enter here?

Also can i get multiple types of Magazines, and are they ordered in a certain way?

Fex: _magazine returns ["bullets","HE_grenades","monkey_Poo"]; ??

2: "assume" i dont know the musslename either for the grenade launcher on the same weapon, how can i get that from cfgWeapon?

_weapon = "BAF_L85A2_UGL_ACOG";
_muzzle = <code to find muzzlename>????  // what should i enter here?

I know its this "BAF_L17_40mm", but asuming i didnt knew this?

Any help much appreciated.

Share this post


Link to post
Share on other sites

_weapon = "BAF_L85A2_UGL_ACOG";

think config entry for "BAF_L85A2_UGL_ACOG" don't have "magazines" class,

then, first, you should to find base class for "BAF_L85A2_UGL_ACOG",

exactly this is "BAF_L85A2_RIS_ACOG",

then "L85A2_base_BAF",

and from "L85A2_base_BAF" get "magazines" array,

then from "magazines" array get any entry.

so,

_i = 0;//needed later

while {!(isClass (configFile >> "CfgWeapons" >> _weapon >> "magazines"))}
do {_weapon = inheritsFrom (configFile >> "CfgWeapons" >> _weapon)};

_magazines_array = getArray (configFile >> "CfgWeapons" >> _weapon >> "magazines");
/*
_magazines_array for "BAF_L85A2_UGL_ACOG" returns array ["30Rnd_556x45_Stanag","30Rnd_556x45_StanagSD","30Rnd_556x45_G36"]
*/
_magazine = _magazines_array select _i;

think something like this)

don't copypaste - check syntax first)

Share this post


Link to post
Share on other sites

Shouldn't be needed to check for base class in my experience since all 'children' classes inherits the parent class, and thus will have copies of all its variable definitions once the game is running and the config files have been parsed. Will test in a moment ^^

Share this post


Link to post
Share on other sites

_magazinearray = getArray (configFile >> "CfgWeapons" >> _weapon >> "magazines");

gives you an array of magazines for the weapon. Convention seems to be that the default magazine is:

_magazinearray select 0;

For muzzles, try the following:

_muzzlearray = getArray (configFile >> "CfgWeapons" >> _weapon >> "muzzles");

_launcher_muzzle = _muzzlearray select 1;

(always seems to be second entry)

Share this post


Link to post
Share on other sites

Here a simple little test I did to prove my earlier statement. I simply put a player soldier on the map and added a radio trigger to run the script. The weapon in my current test is that of a BAF grenadier; a BAF_L85A2_UGL_ACOG which does NOT have a defined magazine array, but rather only inherits the magazine array from L85A2_base_BAF through another weapon in-between.

magazineHint.sqf

// Run with:
// nul = [player] execVM "magazineHint.sqf";

_unit = _this select 0;
_weapon = currentWeapon _unit;
_cfg = getArray (configFile >> "CfgWeapons" >> _weapon >> "magazines");
_count = count _cfg;
_text = "Magazines:\n";

for "_i" from 0 to (_count - 1) do
{
_text = format ["%1%2\n",_text,_cfg select _i];
};
hint _text;

With the short and simple information from Das Attorney it could easily be converted into showing the UGL-magazines.

Share this post


Link to post
Share on other sites

Further to what Inko says;

if you want the magazine names for the UGL (Grenade Launcher) then try the following:

_GL_magazine_array = getArray (configFile >> "CfgWeapons" >> _weapon >> _muzzlearray select 1 >> "magazines");

I've been using it with your AIshootflare script to make it compatible with all grenade launching - assault rifles.

If you want to verify, then use a hint.

player sideChat format["%1",_GL_magazine_array];

Share this post


Link to post
Share on other sites

Great, this is for updating my Ai shoot flares script so spot on.

Share this post


Link to post
Share on other sites

perfect!! all working like a charm.

---------- Post added at 06:51 PM ---------- Previous post was at 05:59 PM ----------

just an addition wich was relevant to my question:

useful for adding different types of ammo dynamically for each weapon.

when collecting magzine types from muzzle 1 (grenade launcher)

array always returns type grenades in this order: HE, color flare, color smoke.

Example;

["1Rnd_HE_GP25","FlareWhite_GP25","FlareGreen_GP25","FlareRed_GP25","FlareYellow_GP25","1Rnd_SMOKE_GP25","1Rnd_SMOKERED_GP25","1Rnd_SMOKEGREEN_GP25","1Rnd_SMOKEYELLOW_GP25"]

This worked for all rifle with grenade launchers for BAF, PMC, A2, OA vanilla weapons, with 1 exeption.

"M4A1_RCO_GL" this weapon stopped the output at this:

_magazinearray = getArray (configFile >> "CfgWeapons" >> _weapon >> "magazines");

no errors in rpt, verified classname seperatly in hint, basically this weapon fails the config line check, all else works fine.

Im using A2 CO (a2 + OA) full BAF, PMC, official patch 1.57 no beta in my test.

Edit: Maybe it gets messed up because of the OA equivalent weapon "M4A3_RCO_GL_EP1".

Edited by Demonized

Share this post


Link to post
Share on other sites

Glad you got it working.

I know you said in your first post that you wanted to get better at extracting information from configs; so respectfully, check out these two links. They really helped me learn how to obtain and use information from configs. I'm still learning myself but please feel free to PM if you need any help.

http://forums.bistudio.com/showthread.php?p=1484329&highlight=getnumber+foreach#post1484329

http://browser.dev-heaven.net/

Cheers.

EDIT: Nice job spotting the convention for HE > Flare > Smoke in the magazine array. May come in useful at some point in the future...

Share this post


Link to post
Share on other sites

This might be relevant. I did this for my sandbox. You use a weapon as input and it extracts a magazine for each muzzle. Inherited muzzles as well.

_weapon = _this select 0;

_magazines = [];
_muzzles = getArray(configfile >> "cfgWeapons" >> _weapon >> "muzzles");

if ("this" in _muzzles) then {
_muzzles = _muzzles - ["this"];
_magazines = _magazines + [(getArray(configfile >> "cfgWeapons" >> _weapon >> "magazines")) select 0];
};
{
_m = [(getArray(configfile >> "cfgWeapons" >> _weapon >> _x >> "magazines")) select 0];
_magazines = _magazines - _m;
_magazines = _magazines + _m;
}forEach _muzzles;

_magazines

Hope this helps :)

Cheers

-dmos

Share this post


Link to post
Share on other sites
just an addition wich was relevant to my question:

useful for adding different types of ammo dynamically for each weapon.

when collecting magzine types from muzzle 1 (grenade launcher)

array always returns type grenades in this order: HE, color flare, color smoke.

I would be careful about making this assumption. IFAIK, the order of the returned magazines array is the same as it is defined in the config, which is not guaranteed to be the same for all weapons.

Share this post


Link to post
Share on other sites
I would be careful about making this assumption. IFAIK, the order of the returned magazines array is the same as it is defined in the config, which is not guaranteed to be the same for all weapons.

Yes you are right ofc, but only when it comes to user mods.

All vanilla A2, CO + dlc ones come in that order and the color order as i posted.

I also think ACE mod kept the same order and color order, but its a long time since this thread was started, so not totally sure on the ACE bit, i know they have some extra flares also, "AI_flareGreen" or something, not sure.

You can see the results derived from this thread in my AIshootflares script in my sig, where the said order is used.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×