Jump to content
Sign in to follow this  
d3nn16

infantry weapons retrieved from config

Recommended Posts

Hi,

My objective is to create a script to retrieve all weapons and corresponding magazines for each weapon a soldier can carry (including backpacks).

I started with weapons first and I came up with the following script which it turns out that it also grabs some classes from cfgweapons config that are not real weapons (like M16_base):


// name of root config for all weapon configs
_root = configName (configFile / "CfgWeapons" / "Default");

// names of root configs for infantry weapon configs
_weapon_roots = [configName (configFile / "CfgWeapons" / "Rifle"), configName (configFile / "CfgWeapons" / "Pistol"), configName (configFile / "CfgWeapons" / "Launcher"), configName (configFile / "CfgWeapons" / "TimeBomb"), configName (configFile / "CfgWeapons" / "Put")];

// loop through all weapon configs
for "_i" from 0 to count (configFile / "CfgWeapons") - 1 do 
{
// store current config entry
_cfg_entry = (configFile / "CfgWeapons") select _i;

// check whether it could be a weapon config
if (isClass _cfg_entry && (isArray (_cfg_entry / "magazines") || isArray (_cfg_entry / "muzzles"))) then
{
	// check whether it is an infantry weapon config
	_is_weapon = false;
	_cfg_parent = inheritsFrom _cfg_entry;
	while {! (configName _cfg_parent in _weapon_roots) && configName _cfg_parent != _root} do
	{
		_cfg_parent = inheritsFrom _cfg_parent;
	};

	if (configName _cfg_parent in _weapon_roots) then
	{
		_is_weapon = true;
	};

	// continue only if it is an infantry weapon config
	if (_is_weapon || configName _cfg_entry == "Throw") then
	{
		diag_log ("class: " + configName _cfg_entry);


	};
};
};

So the problem here is determining what is the condition that will tell me that a cfgweapons class is a weapon i can add with addWeapon to a soldier.

Once I know when a class is a weapon I can retrieve magazines list by looking at muzzle subclasses and magazine array of the weapon class.

Thanks

Share this post


Link to post
Share on other sites

I don't think that checking for muzzles would work because :

player sideChat ("res: " + str (configFile / "CfgWeapons" / "M16_base" / "muzzles"));

returns ["this"]

---------- Post added at 11:05 PM ---------- Previous post was at 10:24 PM ----------

I found a solution, it works for pistols rifles and launchers :

// name of root config for all weapon configs
_root = configName (configFile / "CfgWeapons" / "Default");

// names of root configs for infantry weapon configs
_weapon_roots = [configName (configFile / "CfgWeapons" / "Rifle"), configName (configFile / "CfgWeapons" / "Pistol"), configName (configFile / "CfgWeapons" / "Launcher")];

// loop through all weapon configs
for "_i" from 0 to count (configFile / "CfgWeapons") - 1 do 
{
// store current config entry
_cfg_entry = (configFile / "CfgWeapons") select _i;

// check whether it could be a weapon config
if (isClass _cfg_entry) then
{
	// check whether it is an infantry weapon config
	_is_weapon = false;
	_cfg_parent = inheritsFrom _cfg_entry;
	while {! (configName _cfg_parent in _weapon_roots) && configName _cfg_parent != _root} do
	{
		_cfg_parent = inheritsFrom _cfg_parent;
	};

	if (configName _cfg_parent in _weapon_roots) then
	{
		_is_weapon = true;
	};

	// continue only if it is an infantry weapon config
	if (_is_weapon && getText (_cfg_entry / "descriptionShort") != "") then
	{
		diag_log ("class: " + configName _cfg_entry);

		{
			diag_log ("     " + _x);
		} forEach getArray (_cfg_entry / "magazines");

		for "_i" from 0 to count _cfg_entry - 1 do 
		{
			_x = _cfg_entry select _i;
			if (isClass _x) then
			{
				if (isArray (_x / "magazines")) then
				{
					{
						diag_log ("     " + _x);
					} forEach getArray (_x / "magazines");
				};
			};
		};
	};
};
};

So first I am parsing all CfgWeapons entries,

then I check if it is a class,

then if it inherits from Pistol, Rifle or Launcher class

then I remove base classes like M16_base by checking if shortDescription != ""

finally i take whatever I can find in magazines array directly in the class or in any (muzzle) subclasses that have a magazine array

Now I need to get the special Put and throw magazines (satchels, mines, IEDs, handgrenades etc)

---------- Post added at 11:28 PM ---------- Previous post was at 11:05 PM ----------

And here is the script that also takes into account "Put" and "Throw" weapons and their magazines:

// name of root config for all weapon configs
_root = configName (configFile / "CfgWeapons" / "Default");

// names of root configs for infantry weapon configs
_weapon_roots = [configName (configFile / "CfgWeapons" / "Rifle"), configName (configFile / "CfgWeapons" / "Pistol"), configName (configFile / "CfgWeapons" / "Launcher")];

// loop through all weapon configs
for "_i" from 0 to count (configFile / "CfgWeapons") - 1 do 
{
// store current config entry
_cfg_entry = (configFile / "CfgWeapons") select _i;

// check whether it could be a weapon config
if (isClass _cfg_entry) then
{
	// check whether it is an infantry weapon config
	_is_weapon = false;
	_cfg_parent = inheritsFrom _cfg_entry;
	while {! (configName _cfg_parent in _weapon_roots) && configName _cfg_parent != _root} do
	{
		_cfg_parent = inheritsFrom _cfg_parent;
	};

	if (configName _cfg_parent in _weapon_roots) then
	{
		_is_weapon = true;
	};

	// continue only if it is an infantry weapon config
	if ((_is_weapon && getText (_cfg_entry / "descriptionShort") != "") || configName _cfg_entry == "Put" || configName _cfg_entry == "Throw") then
	{
		diag_log ("class: " + configName _cfg_entry);

		{
			diag_log ("     " + _x);
		} forEach getArray (_cfg_entry / "magazines");

		for "_i" from 0 to count _cfg_entry - 1 do 
		{
			_x = _cfg_entry select _i;
			if (isClass _x) then
			{
				if (isArray (_x / "magazines")) then
				{
					{
						diag_log ("     " + _x);
					} forEach getArray (_x / "magazines");
				};
			};
		};
	};
};
};

Share this post


Link to post
Share on other sites

Check the scope parameter. Weapons with scope = 2 should be "real" weapons. Ex:

if(getNumber(configFile >> "CfgWeapons" >> _classname >> "scope") < 2)then{_isWeapon = false};

Share this post


Link to post
Share on other sites

what is the scope attribute for ? why would it be more reliable than shortDescription ?

Share this post


Link to post
Share on other sites

finally i ended up checking scope attribute (scope = 2) instead of shortdescription because it is more reliable (shortdescription grabs Rifle and Explosive weapons which are not real weapons)

Share this post


Link to post
Share on other sites

If each player executes the script that retrieves weapons from CfgWeapons, does this mean that they can end up calling for example addWeapon "mycustomfluffymod_ninjastar" where "mycustomfluffymod_ninjastar" weapon is only present on their machine. What can the result be ?

Should I broadcast the list of available weapons from server ?

Thanks

Share this post


Link to post
Share on other sites

Yes, if you use a config based ammo box type thing and they are using a mod that others are not using, they'll have access to the weapon but others will see them holding nothing.

Share this post


Link to post
Share on other sites

I would like a game admin to be able to set a limit on the number of magazines of a specific type that a player can take (which also allows to prevent players from using a specific type of magazine when number is set to 0).

I divided magazines in following types (that are interesting for CTF/DM maps):

- explosives

- hand grenades & rifle grenades

- hand smokeshells & rifle smokeshells

- launcher rockets

- handgun magazines

Is there a (simple) way I can identify magazines in each category ? Like for instance an attribute in the grenade magazine config ?

Thanks

---------- Post added at 09:29 PM ---------- Previous post was at 09:19 PM ----------

The toughest part is knowing when a magazine is a grenade or a smokeshell because the other types I can guess them easily :

- Explosive would be any magazine used by the abstract "Put" weapon

- Rockets would be any magazine used by the Launcher class type weapons

- Handgun magazines would be any magazine used by the Pistol class type weapons

- Rifle magazines would be the remaining types of magazines

---------- Post added at 09:55 PM ---------- Previous post was at 09:29 PM ----------

Found a solution for grenades and smokeshells :

- rifle grenades: all class names for rifle grenades contain the "HE" substring

- hand grenades: all class names contain the "HandGrenade" substring

- rifle smokeshells and hand smokeshells class names contain the "Smoke" substring

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  

×