Jump to content
Undeceived

Add the right suppressor to rifle

Recommended Posts

Hi guys,

 

is there a way to (code-wise) add a compatible weapon attachment - here: suppressor - to the currently selected gun?

 

In my case it's an AK from the CUP mod (if this is relevant at all).

 

Thank you very much!

Share this post


Link to post
Share on other sites
_cfgArray = getArray (configfile >> "CfgWeapons" >>  _yourWeapon >> "WeaponSlotsInfo" >> "MuzzleSlot" >> "compatibleItems"); 
_supressor = [nil, selectRandom _cfgArray] select (count _cfgArray > 0);
_unit addPrimaryWeaponItem _supressor;

 

  • Like 2
  • Thanks 1

Share this post


Link to post
Share on other sites
35 minutes ago, 7erra said:

_cfgArray = getArray (configfile >> "CfgWeapons" >>  _yourWeapon >> "WeaponSlotsInfo" >> "MuzzleSlot" >> "compatibleItems"); 
_supressor = [nil, selectRandom _cfgArray] select (count _cfgArray > 0);
_unit addPrimaryWeaponItem _supressor;

 

 

Thanks a lot, 7erra! Much appreciated.

 

At first it didn't work, but then I checked the config and found what to change -> the part in the "WeaponSlotsInfo". In vanilla it is "MuzzleSlot", in CUP it's "CUP_EastMuzzleSlotAK". 

 

This means that the code is not totally "universal", but in my case it's absolutely sufficient as there are no Western weapons in the corresponding mission.

 

Thanks again!

 

The code looks like this now:

 

_cfgArray = getArray (configfile >> "CfgWeapons" >> (currentWeapon player) >> "WeaponSlotsInfo" >> "CUP_EastMuzzleSlotAK" >> "compatibleItems"); 
_supressor = [nil, selectRandom _cfgArray] select (count _cfgArray > 0);
player addPrimaryWeaponItem _supressor; 

 

  • Like 2

Share this post


Link to post
Share on other sites

You could check for CUP_ prefix. If CUP then do CUP_EastMuzzleSlotAK or whatever and if vanilla, etc... Do something else. Use find command to search for prefix.

Share this post


Link to post
Share on other sites

As @HazJ suggested, it's best to use BIS_fnc_compatibleItems if you want to make sure that all compatible suppressors are returned, since, as you already noticed, some mods have their own muzzle class and won't inherit from the vanilla class.

This will always add the first compatible suppressor if there are compatible ones:

_muzzles = [currentweapon player,"muzzle"] call BIS_fnc_compatibleItems;
_muzzles params [["_suppressor",""]];
_unit addPrimaryWeaponItem _suppressor;

You might end up with non matching combinations in terms of color though (at least for vanilla weapons).

 

Cheers

  • Like 3

Share this post


Link to post
Share on other sites
22 hours ago, Undeceived said:

 

Thanks a lot, 7erra! Much appreciated.

 

At first it didn't work, but then I checked the config and found what to change -> the part in the "WeaponSlotsInfo". In vanilla it is "MuzzleSlot", in CUP it's "CUP_EastMuzzleSlotAK". 

 

This means that the code is not totally "universal", but in my case it's absolutely sufficient as there are no Western weapons in the corresponding mission.

 

Thanks again!

 

The code looks like this now:

 


_cfgArray = getArray (configfile >> "CfgWeapons" >> (currentWeapon player) >> "WeaponSlotsInfo" >> "CUP_EastMuzzleSlotAK" >> "compatibleItems"); 
_supressor = [nil, selectRandom _cfgArray] select (count _cfgArray > 0);
player addPrimaryWeaponItem _supressor; 

 

make it universal with a switch statement kind of like so using the author

_devName = getText (configFile >> "cfgWeapons" >> _weaponName >> "author");

 

then do a switch on _devName

_muzzleSlot = "";

switch (_devName) do
{
	case "CUP": {_muzzleSlot = "whatever";
	case "Bohemia Interactive": {_muzzleSlot = "yea that"};
};

 

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

×