Jump to content
beno_83au

Check if unit has a machine gun or automatic rifle

Recommended Posts

So, as title'd I need to determine if a unit has a machine gun/automatic rifle. At the moment I'm running with:

_machineGuns = [
	"MMG_02_base_F",
	"arifle_MX_SW_F",
	"LMG_Mk200_F",
	"LMG_Zafir_F",
	"MMG_01_base_F"
];

_gunCheck = {(primaryWeapon _unit) isKindOf [_x, configFile >> "CfgWeapons"]} count _machineGuns;
if (_gunCheck != 0) then {
        //Code
};

It works, but it would potentially require an edit to _machineGuns for any mod MGs, which detracts from it's user-friendliness. This is as basic as I was able to work out, so is there a better way? Please take note that I'm checking the weapon, not the unit.

 

As an example, this is what I'm trying to achieve (script taken from VBS3):

if ([configFile>>"CfgWeapons",(primaryWeapon _unit),"vbs2_mgun"] call fn_vbs_isKindOf) then {
	//Code
};

So, in the example it's very convenient that "vbs2_mgun" covered everything, and thus requires no editing on the user's part.

 

Cheers.

Share this post


Link to post
Share on other sites

You could check the different magazines used by the weapon and see if one of those has 100 bullets or more.

I don't think MG's have their own parent class, so it's probably the simplest solution.

  • Like 2

Share this post


Link to post
Share on other sites
_isMG = getText(configfFile >> "CfgWeapons" >> primaryWeapon player >> "cursor") == "mg";
_isMG = ( primaryweapon player call BIS_fnc_itemtype ) select 1 == "MachineGun"
Of which the second option relies on the first internally anyway.
  • Like 5

Share this post


Link to post
Share on other sites

Thanks guys. Haleks, that definitely crossed my mind but i could still come up with situations where that wouldn't work (Minimi using M16 mags for example).

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

×