Simply execute the script with the execVM command in the desired units initialization box.
This script will give the unit a random amount of randomly selected magazines with a random amount of ammo for a random weapon.
Example
With the weapon selection containing only an M9 the script can select a random number of magazines that consist of both the regular and SD magazines. The magazines will have anywhere between 1 and 15 bullets per magazine.
Script
_unit = _this select 0;// Unit that receives the equipment
_current=0;
_weaponselection=[];// Insert the weapons you want to use
_weapon = _weapons select floor random count _weapons;// This selects a random weapon from the weapons array
_magazineselection = getArray (configFile >> "CfgWeapons" >> _weapon >> "magazines");// Gets the array of magazines for the weapon
_magpossibilities = [];// Insert the possible number of magazines ex. [1,2,3,4,5,6,7,8] where 1 is the minimal amount and 8 is the maximum amount
_magamount = (_magpossibilities select floor random count _magpossibilities);// Gets the magazine ammount
while {(_current<_magamount)} do {
_current=_current+1;
_magazine = (_magazineselection select floor random count _magazineselection);// Selects random magazine
_munitions = getNumber (configFile >> "CfgMagazines" >> _magazine >> "count");// This retrieves the maximum amount of rounds in the magazine
_munfin = 1;// This is the minimal amount of rounds per mag
if (_munitions > 1) then {// This checks if the magazine has more than one round in it
_munfin = (round(random(_munitions-1)));// This gets a random amount of rounds between 0 and the maximum amount the magazine can hold minus 1
_munfin = _munfin+1;// This adds one to the random amount
};
_unit addMagazine [_magazine,_munfin];// This gives the unit the magazine with the final ammo value
};
Random Magazine with Random Amount of Ammo Script
in ARMA 2 & OA : MISSIONS - Editing & Scripting
Posted · Edited by qwertyvabc
Fixed small error
Random Magazine with Random Amount of Ammo Script
Simply execute the script with the execVM command in the desired units initialization box.
This script will give the unit a random amount of randomly selected magazines with a random amount of ammo for a random weapon.
Example
With the weapon selection containing only an M9 the script can select a random number of magazines that consist of both the regular and SD magazines. The magazines will have anywhere between 1 and 15 bullets per magazine.
Script
_unit = _this select 0;// Unit that receives the equipment _current=0; _weaponselection=[];// Insert the weapons you want to use _weapon = _weapons select floor random count _weapons;// This selects a random weapon from the weapons array _magazineselection = getArray (configFile >> "CfgWeapons" >> _weapon >> "magazines");// Gets the array of magazines for the weapon _magpossibilities = [];// Insert the possible number of magazines ex. [1,2,3,4,5,6,7,8] where 1 is the minimal amount and 8 is the maximum amount _magamount = (_magpossibilities select floor random count _magpossibilities);// Gets the magazine ammount while {(_current<_magamount)} do { _current=_current+1; _magazine = (_magazineselection select floor random count _magazineselection);// Selects random magazine _munitions = getNumber (configFile >> "CfgMagazines" >> _magazine >> "count");// This retrieves the maximum amount of rounds in the magazine _munfin = 1;// This is the minimal amount of rounds per mag if (_munitions > 1) then {// This checks if the magazine has more than one round in it _munfin = (round(random(_munitions-1)));// This gets a random amount of rounds between 0 and the maximum amount the magazine can hold minus 1 _munfin = _munfin+1;// This adds one to the random amount }; _unit addMagazine [_magazine,_munfin];// This gives the unit the magazine with the final ammo value };