Jump to content
Sign in to follow this  
CarlGustaffa

How many rounds can magazine hold?

Recommended Posts

Hi

I'm sometimes using:

_type_name = getText(configFile>>"CfgVehicles" >> (typeOf (_vehicle)) >> "displayName"); to use the displayname of a vehicle.

How can I obtain the number of bullets each contained magazine holds? Something like:

_bullets = _bullets + getNumber(configFile>>"CfgWeapons">>.....)

Edit: Problem solved, sort of. I can use magazines instead for what I'm trying to achieve instead of bullets.

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

_weapon = "";

_magazines = [];

_possiblemagazines = [];

_magcount = 0;

_weapon = primaryWeapon player;

_magazines = magazines player;

_possiblemagazines = getArray (configFile >> "CfgWeapons" >> _weapon >> "magazines");

_i=0;

_j=0;

for "_i" from 0 to (count _magazines)-1 do{

 for "_j" from 0 to (count _possiblemagazines)-1 do{

   if((_magazines select _i) == (_possiblemagazines select _j)) then {

     _magcount = _magcount+1;

   };

 };

};

hint format ["wpn: %1\nmagcount: %2\n",_weapon,_magcount];

player sideChat format ["_possiblemagazines = %1",_possiblemagazines];

player globalChat format ["_magazines = %1",_magazines];

Share this post


Link to post
Share on other sites

And here is the "full" thing. The comments in the example explains it all. Please let me know if you find any bugs.

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

//Small snippet to be used with "getting weapons back on respawn" type scripts. Purpose it to

//avoid "1 shot left exploit"; this will remove a full magazine when one shot has been fired.

_weapon = "";

_magazines = [];

_possiblemagazines = [];

_currentmagcount = 0;

_currentmagmax = 0;

_magcount = 0;

_currentammo = 0;

_willdropammo = false;

_weapon = primaryWeapon player;

_magazines = magazines player;

_currentammo = player ammo _weapon;

_possiblemagazines = getArray (configFile >> "CfgWeapons" >> _weapon >> "magazines");

_magcounter=0; //magazine counter

_poscounter=0; //possible counter

_firstfound=-1; //first used ammo index selection

if(_weapon != "") then {

 for "_magcounter" from  0 to (count _magazines)-1 do{

   for "_poscounter" from  0 to (count _possiblemagazines)-1 do{

     if((_magazines select _magcounter)  == (_possiblemagazines select _poscounter)) then  {

       _magcount = _magcount+1;

       if (_firstfound == -1) then {_firstfound = _magcounter};

     };

   };

 };

 

//after dropping and getting, the _firstfound seems odd, but still works.

 _tmp = toArray (_magazines select _firstfound);

//Apparently you don't need to remove non number characters for this to work. Try 5RND blufor sniper to verify.

 _currentmagmax = parseNumber (toString [_tmp select 0]+toString [_tmp select 1]+toString [_tmp select 2]);

 _willdropammo = if(_currentammo != _currentmagmax) then {true} else {false};

 

 hint format ["_weapon: %1\n_magcount: %2\n_magmax=%3\n_firstfound=%4\n_willdropammo=%5", _weapon, _magcount, _currentmagmax, _firstfound, _willdropammo];

 player sideChat format ["_possiblemagazines = %1",_possiblemagazines];

 player globalChat format ["_magazines = %1",_magazines];

};

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  

×