Jump to content
Zriel

Check classname is grenade (or throwable)

Recommended Posts

So, I'm working on a loadout system, and I would like to know if there is a way to check if a classname is a grenade (or is a throwable item, or at least I think that's how they are called on arma configs)

I currently can check if a classname is a magazine used by a weapon, but grenades and such seem to use a different set of configs.

 

Any common config item I should be looking for?

Share this post


Link to post
Share on other sites

Query the magazines of each subclass of ( "CfgWeapons" >> "Throw" )

_item = "SmokeShell";
_isThrowable = count ( "
	_item in getArray( _x >> 'magazines' ) 
"configClasses ( configFile >> "CfgWeapons" >> "Throw" ) ) > 0;
Same can be done for explosives and mines by using "Put"
  • Like 1

Share this post


Link to post
Share on other sites

Nah, item is not given, I wan't to be able to check this before giving it to the unit.

 

Query the magazines of each subclass of ( "CfgWeapons" >> "Throw" )

_item = "SmokeShell";
_isThrowable = count ( "
	_item in getArray( _x >> 'magazines' ) 
"configClasses ( configFile >> "CfgWeapons" >> "Throw" ) ) > 0;
Same can be done for explosives and mines by using "Put"

 

Yay! this is working perfectly. Many thanks!

Share this post


Link to post
Share on other sites

AFAIK this should work too:

"className" isKindOf "Throw" <- No this does not work!
// Returns true or false

Read the comments in the BIS Arma Wiki for other possible solutions:
https://community.bistudio.com/wiki/isKindOf
 
/edit

This works:

(getText(configfile >> "CfgMagazines" >> "className" >> "selectionFireAnim") == "zasleh");
 
But the solution posted by Larrow is actually the most reliable so you should stick to this.

  • Like 1

Share this post


Link to post
Share on other sites

Query the magazines of each subclass of ( "CfgWeapons" >> "Throw" )

_item = "SmokeShell";
_isThrowable = count ( "
	_item in getArray( _x >> 'magazines' ) 
"configClasses ( configFile >> "CfgWeapons" >> "Throw" ) ) > 0;

 

Seems like I found a much faster way to determine whether the item is throwable:

Fn_Gear_IsThrowable = {	
	private _cfa = configFile >> "CfgAmmo" >> getText(configFile >> "CfgMagazines" >> _this >> "ammo");
	while {true} do {
		if (not isClass _cfa or {configName _cfa isEqualTo "GrenadeHand"}) exitWith {isClass _cfa};
		_cfa = inheritsFrom _cfa}
};
magazines player select {_x call Fn_Gear_IsThrowable}
//Result: ["Chemlight_green","SmokeShell","SmokeShellGreen","Chemlight_green","HandGrenade","HandGrenade"]

Share this post


Link to post
Share on other sites

 

Seems like I found a much faster way to determine whether the item is throwable:

Fn_Gear_IsThrowable = {	
	private _cfa = configFile >> "CfgAmmo" >> getText(configFile >> "CfgMagazines" >> _this >> "ammo");
	while {true} do {
		if (not isClass _cfa or {configName _cfa isEqualTo "GrenadeHand"}) exitWith {isClass _cfa};
		_cfa = inheritsFrom _cfa}
};
magazines player select {_x call Fn_Gear_IsThrowable}
//Result: ["Chemlight_green","SmokeShell","SmokeShellGreen","Chemlight_green","HandGrenade","HandGrenade"]

 

Careful on how/where you use that, it will return UGL magazines as throwable plus a host of vehicle ammo.

You could nearly double its speed by using isKindOf instead of the while loop.

_isThrowable = "1Rnd_SmokeOrange_Grenade_shell" call {
    params[ "_item" ];
    
    private _cfa = configFile >> "CfgAmmo" >> getText(configFile >> "CfgMagazines" >> _item >> "ammo");
    configName _cfa isKindOf "GrenadeHand"
};

is TRUE

  • Like 1

Share this post


Link to post
Share on other sites
You're right. First aproach failed. Second aproach:
Fn_Gear_IsThrowable = {
	{if (_this in getArray (configFile >> "CfgWeapons" >> "Throw" >> _x >> "magazines"))
			exitWith {true}; false} forEach getArray (configFile >> "CfgWeapons" >> "Throw" >> "muzzles")
};

Filters grenadier inventory for ~0.027ms, your version for ~0.037ms. Thank you.

Share this post


Link to post
Share on other sites

Try this:

fn_isThrowable = 
{	
	private _cfgMagazine = configFile >> "CfgMagazines" >> _this;
	if (getNumber (_cfgMagazine >> "initSpeed") < 30) exitWith
	{
		toLower getText (configFile >> "CfgAmmo" >> getText (_cfgMagazine >> "ammo") >> "simulation") in [
			"shotgrenade", 					
			"shotsmokex",
			"shotsmoke", 
			"shotsubmunitions", 
			"shotdeploy", 
			"shotilluminating", 
			"shotshell", 
			"shotnvgmarker"
		]
	};
	false
};
  • Like 1

Share this post


Link to post
Share on other sites

 

Try this:

Works fine, ~80 times faster than my variant

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

×