Jump to content
Sign in to follow this  
mandoble

Weapon Index

Recommended Posts

Is there any way to find out the first weapon index of a named weapon? I mean a valid index to be used with action "UseWeapon".

Im trying this, which seems to work for vehicles, but not for soldiers:

private["_veh", "_i", "_modes", "_muzzles", "_weapons"];
_veh = _this select 0;
_msg = "";
_muzzles  =[];
_modes = [];
_weapons = [];
// _weapons = ["Throw"];
_weapons = _weapons + weapons _veh;
_i = 0;
{
  _msg = _msg + format["W:%1 - Index:%2\n",_x, _i];
//   _muzzles = getArray(configFile>>"cfgWeapons" >> _x >> "muzzles");
  _modes = getArray(configFile>>"cfgWeapons" >> _x >> "modes"); 
  _i = _i + (((count _muzzles) + (count _modes)) max 1);
} forEach _weapons;

hint format["%1", _msg];

Edited by Mandoble

Share this post


Link to post
Share on other sites

I've played around with your script some.

I don't think there will be a way to reliably get the index number. You'll have to check to see if the unit is carrying hand grenades, mines, and satchels as that is included in the actions. You'd have to get that from magazines. And add it in. Only issue is where to add it. You can't add it at the beginning, or the end i.e. _weapons + _mags.

From the limited testing I did, it seemed index 3-4 depending on the primary weapon used was the hand grenades.

Possibly, if your remove all weapons, then add them back in a certain order. Something like:

grenades

satchels

mines

magazines

Primary weapon

Secondary weapon

Pistol

night vision

compas etc

Then you could add the mags + _weapons, check to see if it has a muzzle (grenades, satchels, mines) then add the modes to that but only if it has a muzzle.

so:

grenade - 0

grenade - 0

grenade - 0

satchel - 1

primary weapon single - 2

primary weapon burst - 3

secondary weapon single - 4

pistol - 5

night vision - 6

etc

Share this post


Link to post
Share on other sites

It might be even more tricky if we consider items like map, etc are also counted as weapons. One thing is clear, if you drop weapons the index is recalculated. So ArmA2 engine should be following a rule that should be applicable also via scripting.

Share this post


Link to post
Share on other sites

_weapons = _weapons + weapons _veh;
_i = 0;
{
  _msg = _msg + format["W:%1 - Index:%2\n",_x, _i];
//   _muzzles = getArray(configFile>>"cfgWeapons" >> _x >> "muzzles");
  _modes = getArray(configFile>>"cfgWeapons" >> _x >> "modes"); 
  _i = _i + (((count _muzzles) + (count _modes)) max 1);
} forEach _weapons;

How can that work, _weapons is never defined!? :p

Share this post


Link to post
Share on other sites

lol, it is, in the copy/paste I missed to include it.

_weapons in my tests were defined as [] or as ["Throw"] before adding the rest of the weapons ot the unit.

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  

×