zyg0tic 12 Posted February 25, 2015 (edited) Sorry the subject line is misleading. It should be non-random or random item adding to box script. This is a beginner's level script for adding items (randomly or non-randomly) to a container. It could be a supply box, ammo box, vehicle, whatever. The script is designed as a tutorial. So it doesn't choose the items for you, you have to do that yourself. It just has some example items (MX rifles and ammo). It does include a link to where you find all the item codes as a comment. I've added helpful comments to every line of the code in order for beginner's to learn exactly what the code is doing. I myself am a beginner and have been annoyed by how very rarely people add insightful comments to their scripts! Copy-paste the code into a Notepad++ file and save as cacheFiller.sqf. The code itself includes all the instructions. // Save this code as cacheFiller.sqf. I recommend Notepad++ for editing Arma3 scripts. // In the Arma 3 Editor you must add // init_Handle = this execVM "cacheFiller.sqf"; // to the Initialization field of the container. // cacheFiller is just the name I chose for the script. If you change the file-name of the script // you must also correct the file-name in the Initialization field also. _this allowDamage false; // Makes the container indestructible clearWeaponCargoGlobal _this; clearMagazineCargoGlobal _this; clearItemCargoGlobal _this; clearBackpackCargoGlobal _this; // Clears the entire contents of the container // 1. This section adds items non-randomly. _this addWeaponCargoGlobal ["arifle_MX_F", 2]; // Adds an item (in this case 2 MX assault rifles) non-randomly. _this addMagazineCargoGlobal ["30Rnd_65x39_caseless_mag", 20]; // Adds 20 magazines for the MX assault rifle non-randomly. // The class (item ID/codes) were found at https://community.bistudio.com/wiki/Arma_3_Assets // 2. This section adds items randomly. _gun = ["arifle_MX_F", "arifle_MX_GL_Black_F"] call BIS_fnc_selectRandom; // _gun is a custom name we use, important for what comes after. You could call it _banana instead of you prefer. // In the array (items included between the square brackets) we have some guns. The standard MX assault rifle or the GL variant in black. // After the square bracket closes, we have the command to randomly select one of the guns. _this addWeaponCargoGlobal [_gun,5]; // Here you see _gun again followed by ,5. // If you preferred to call it _banana instead of _gun, you would need to change it to [_banana,5] // This means that after the gun is randomly chosen, it will place 5 of them in the container. // _this specifies you want the item placed into the container. // It is critical to limit the items to their own category (Weapon, Magazine, Item, Backpack). // For other categories you will need to add another section of code, as shown below. _ammo = ["30Rnd_65x39_caseless_mag","30Rnd_65x39_caseless_mag_Tracer"] call BIS_fnc_selectRandom; // _ammo is an appropriate name chosen for the magazines. // In the array (items included between the square brackets) we have standard round or tracer round magazines. _this addMagazineCargoGlobal [_ammo,20]; // Adds 20 of the randomly chosen magazine to the container. // What if you want only to spawn the ammo that suits the randomly chosen weapon? if ((_gun == "arifle_MX_F") OR (_gun == "arifle_MX_GL_Black_F")) then { _this addMagazineCargoGlobal ["30Rnd_65x39_caseless_mag", 2 +random 9]; }; // If the guns that take the 6.5mm STANAG magazines spawn, this will add only that ammo. // the +random 9 means there is a chance of spawning 0-9 more magazines than just the 2. // You will need to specify which ammo for which guns. Just copy-paste the section and add/subtract as you please. Without comments: _this allowDamage false; clearWeaponCargoGlobal _this; clearMagazineCargoGlobal _this; clearItemCargoGlobal _this; clearBackpackCargoGlobal _this; _this addWeaponCargoGlobal ["arifle_MX_F", 2]; _this addMagazineCargoGlobal ["30Rnd_65x39_caseless_mag", 20]; _gun = ["arifle_MX_F", "arifle_MX_GL_Black_F"] call BIS_fnc_selectRandom; _this addWeaponCargoGlobal [_gun,5]; _ammo = ["30Rnd_65x39_caseless_mag","30Rnd_65x39_caseless_mag_Tracer"] call BIS_fnc_selectRandom; _this addMagazineCargoGlobal [_ammo,20]; if ((_gun == "arifle_MX_F") OR (_gun == "arifle_MX_GL_Black_F")) then { _this addMagazineCargoGlobal ["30Rnd_65x39_caseless_mag", 2 +random 9]; }; I dont know how to get it to work with MP or Dedicated as Im not that advanced in my scripting knowledge yet. Im just using it with Editor/SP so far. Edited February 25, 2015 by zyg0tic 1 Share this post Link to post Share on other sites
Kaleu 24 Posted January 6, 2017 Exactly what I was looking for, thank you Share this post Link to post Share on other sites