I am working on a script to randomize ammobox contents. What I would like to do, and am having trouble with, is create global arrays that are basically a set of items that could possibly spawn inside the ammobox. However, I am having trouble with the creation, initialization, and access of global arrays. If anyone could help shed some light on what I'm doing wrong, I'd greatly appreciate it.
// init.sqf
// array containing the class names of each weapon included in the mission
_arAllW =
[
"launch_NLAW_F",
"launch_RPG32_F",
"srifle_EBR_F",
...
...
];
publicVariable "_arAllW";
// initAmmobox.sqf
private "_ab"; // ammobox variable
if (true) then
{
_ab = _this select 0;
clearMagazineCargo _ab;
clearWeaponCargo _ab;
clearItemCargo _ab;
clearBackpackCargo _ab;
// Total number of guns within an ammobox: [1, 5]
_nGuns = (random 5) + 1;
// Count the number of elements contained in _arAllW
_wCnt = count _arAllW;
// loop runs nGuns times and computes a random index ranging from [0, _wCnt)
// (cont) then adds the weapon using the randomly chosen index, _n, to the ammobox
for [ {_i = 0}, {_i < _nGuns}, {_i = _i+1} ] do
{
_n = random _wCnt;
_ab addWeaponCargo [ _arAllW select _n, 1];
};
// Add a random amount of grenades ranging from [0, 4]
_ab addMagazineCargo["HandGrenade", random 5];
};
// code entered into the mission editor ammobox initialization field
_nul = [this] execVM "initAmmobox.sqf";
[\code]