Jump to content
  • 0

HowTo get available weapons (mod independent)


Sharkking

Question

I like to share this piece of code shoing how to add all available weapons defined by a certain type to an array.

The code can run client or server side.

//Config

_allWeaponTypes = ["AssaultRifle","MachineGun","SniperRifle","Shotgun","Rifle","SubmachineGun","HandGun"];

// Other types (if you like them to include): GrenadeLauncher,Launcher,MissileLauncher,Mortar,RocketLauncher
//Full List: https://community.bistudio.com/wiki/BIS_fnc_itemType -> section Weapon

_allBannedWeapons=[];  //add banned weapons (eg M107_epoch), make shure to use the base version of the weapon

//Main Script

_baseWeapons = [];
_wpList = (configFile >> "cfgWeapons") call BIS_fnc_getCfgSubClasses;
{
	if (getnumber (configFile >> "cfgWeapons" >> _x >> "scope") == 2) then {
		_itemType = _x call bis_fnc_itemType;
		if (((_itemType select 0) == "Weapon") && ((_itemType select 1) in _allWeaponTypes)) then {
			_baseName = _x	call BIS_fnc_baseWeapon;
			if (!(_baseName in _baseWeapons) && !(_baseName in _allBannedWeapons)) then {
				_baseWeapons = _baseWeapons + [_baseName];
			};
		};
	};
} foreach _wpList;

_baseWeapons will have for instance 51 weapons in vanilla epoch, 171 with @mas addon

may someone find it useful.

 

Link to comment
Share on other sites

5 answers to this question

Recommended Posts

  • 0

@ALKINDA

As You can see in the official BIS wiki, BIS_fnc_getCfgSubClasses is an ArmA 3 function.

@Sharkking

Thanks for sharing that nice piece of code.

I tried to move different weapons into different arrays, but seems the EPOCH Sniper rifles, handguns, shotguns etc. all show up under "Assaultrifles", caused by a wrong implementation/wrong entry in the weapons config files.

I hope the EPOCH devs are aware of these issues and are going to fix them for the next release!

 

Here is my version of the script and below are the results:

_allWeaponTypes = ["AssaultRifle","MachineGun","SniperRifle","Shotgun","Rifle","SubmachineGun","HandGun];

_allBannedWeapons = [];
SEM_wpnAR = []; //Assault Rifles
SEM_wpnARG = []; //Assault Rifles with GL
SEM_wpnLMG = []; //Light Machine Guns
SEM_wpnSMG = []; //Sub Machine Guns
SEM_wpnDMR = []; //Designated Marksman Rifles
SEM_wpnSniper = []; //Sniper rifles
SEM_wpnHandGun = []; //HandGuns/Pistols
SEM_wpnShotGun = []; //Shotguns
SEM_wpnUnknown = []; //Misc


_addedBaseNames = [];
_wpList = (configFile >> "cfgWeapons") call BIS_fnc_getCfgSubClasses;
{
if (getnumber (configFile >> "cfgWeapons" >> _x >> "scope") == 2) then {
_itemType = _x call bis_fnc_itemType;
if (((_itemType select 0) == "Weapon") && ((_itemType select 1) in _allWeaponTypes)) then {
_baseName = _x call BIS_fnc_baseWeapon;
if (!(_baseName in _addedBaseNames) && !(_baseName in _allBannedWeapons)) then {
_addedBaseNames pushBack _baseName;

switch(_itemType select 1)do{
case "AssaultRifle" :{
if(count getArray(configfile >> "cfgWeapons" >> _baseName >> "muzzles") > 1)then[{SEM_wpnARG pushBack _baseName},{SEM_wpnAR pushBack _baseName}];
};
case "MachineGun" :{SEM_wpnLMG pushBack _baseName};
case "SubmachineGun" :{SEM_wpnSMG pushBack _baseName};
case "Rifle" :{SEM_wpnDMR pushBack _baseName};
case "SniperRifle" :{SEM_wpnSniper pushBack _baseName};
case "Shotgun" :{SEM_wpnShotGun pushBack _baseName};
case "HandGun" :{SEM_wpnHandGun pushBack _baseName};
default{SEM_wpnUnknown pushBack _baseName};
};
};
};
};
} foreach _wpList;


copytoclipboard format["SEM_wpnAR: %1, SEM_wpnARG: %2, SEM_wpnLMG: %3, SEM_wpnSMG: %4, SEM_wpnDMR: %5, SEM_wpnSniper: %6, SEM_wpnHandGun: %7, SEM_wpnShotGun: %8, SEM_wpnUnknown: %9",
SEM_wpnAR,SEM_wpnARG,SEM_wpnLMG,SEM_wpnSMG,SEM_wpnDMR,SEM_wpnSniper,SEM_wpnHandGun,SEM_wpnShotGun,SEM_wpnUnknown];

The result is this:

SEM_wpnAR: ["arifle_Katiba_F","arifle_Katiba_C_F","arifle_Mk20_F","arifle_Mk20_plain_F","arifle_Mk20C_F","arifle_Mk20C_plain_F","arifle_MXC_F","arifle_MX_F","arifle_MXM_F","arifle_MXC_Black_F","arifle_MX_Black_F","arifle_MXM_Black_F","arifle_SDAR_F","arifle_TRG21_F","arifle_TRG20_F","hgun_PDW2000_F","AKM_EPOCH","m4a3_EPOCH","M14_EPOCH","M14Grn_EPOCH","m16_EPOCH","m16Red_EPOCH","m107_EPOCH","m107Tan_EPOCH","m249_EPOCH","m249Tan_EPOCH","Rollins_F","ChainSaw","ChainSawB","ChainSawG","ChainSawP","ChainSawR","speargun_epoch]

SEM_wpnARG: ["arifle_Katiba_GL_F","arifle_Mk20_GL_F","arifle_Mk20_GL_plain_F","arifle_MX_GL_F","arifle_MX_GL_Black_F","arifle_TRG21_GL_F"]

SEM_wpnLMG: ["LMG_Mk200_F","LMG_Zafir_F","arifle_MX_SW_F","arifle_MX_SW_Black_F"]

SEM_wpnSMG: ["SMG_01_F","SMG_02_F"]

SEM_wpnDMR: []

SEM_wpnSniper: ["srifle_DMR_01_F","srifle_EBR_F","srifle_GM6_F","srifle_LRR_F","srifle_GM6_camo_F","srifle_LRR_camo_F"]

SEM_wpnHandGun: []

SEM_wpnShotGun: []

SEM_wpnUnknown: []

/Edit

Created an issue on github:

https://github.com/EpochModTeam/Epoch/issues/205

 

/Edit2

Just figured out, the "Rollins_F" shotgun can be equiped with any sight, except for the two "optic_MRD" and "optic_Yorris".

Yes that means, You can attach sniper optics like "optic_Nightstalker", "optic_SOS", "optic_LRPS" or "optic_DMS" to it...

Seems someone was in a hurry when creating the config files, while implementing new guns into the Mod ;)

Greez KiloSwiss

Link to comment
Share on other sites

  • 0
On 3/1/2015 at 8:52 AM, KiloSwiss said:

@ALKINDA

As You can see in the official BIS wiki, BIS_fnc_getCfgSubClasses is an ArmA 3 function.

 

@Sharkking

Thanks for sharing that nice piece of code.

I tried to move different weapons into different arrays, but seems the EPOCH Sniper rifles, handguns, shotguns etc. all show up under "Assaultrifles", caused by a wrong implementation/wrong entry in the weapons config files.

I hope the EPOCH devs are aware of these issues and are going to fix them for the next release!

 

 

Here is my version of the script and below are the results:

 

Hidden Content

 

 

/Edit

Created an issue on github:

https://github.com/EpochModTeam/Epoch/issues/205

 

/Edit2

Just figured out, the "Rollins_F" shotgun can be equiped with any sight, except for the two "optic_MRD" and "optic_Yorris".

Yes that means, You can attach sniper optics like "optic_Nightstalker", "optic_SOS", "optic_LRPS" or "optic_DMS" to it...

Seems someone was in a hurry when creating the config files, while implementing new guns into the Mod ;)

 

Greez KiloSwiss

I was facing this problem and found this script very helpful in working out a way to generate these lists and copy them to the clipboard. I have debuged it and adapted it to provide a more comprehensive list of class names for weapons, launchers, throwables, uniforms, vests, headgear, vehicles and magazines. For those who might find this handy you can download the complete set of tools:

https://github.com/Ghostrider-DbD-/Config-Extraction-Tools

 

 

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
  • Discord

×
×
  • Create New...