auroraah 10 Posted July 28, 2017 Sorry if this has been posted before but I've not been able to find exactly what I mean (maybe I'm just being a noob, not maybe, I am being a noob) I've got a script running that defines the array "weapon" as a random selection of weapons. gun = ["srifle_EBR_DMS_F","srifle_GM6_LRPS_F"," srifle_LRR_LRPS_F","LMG_Mk200_MRCO_F"] call BIS_fnc_selectRandom; This is defined in my Init.sqf I've then added a crate and given it the variable name CASE1. The next line in the init is this: CASE1 addWeaponCargo [gun,1]; This spawns one of weapons defined by gun at random. What I want to be able to do is add something to the effect the code below into the init file of the actual case, instead of having to name all of my cases and load it from the init.sqf. this addWeaponCargo [gun,1]; Additionally I'd like to run the command a few times without just pasting it on 3 lines for example. I tried the forEach command but I'm puzzled by it. Please excuse me as I imagine this is an extremely easy thing to do, just v new to this :D Thanks in advance! Share this post Link to post Share on other sites
HallyG 239 Posted July 28, 2017 Assuming that this is singleplayer, the variable "gun" will be defined once, in the init.sqf, and will be a random weapon. To add a random weapon to the crate each time, you need to select a random weapon again otherwise they will all have the same weapon since "gun" has been defined only once. (I'm assuming you want random weapons in each crate). Define your guns in the init.sqf: gun = ["srifle_EBR_DMS_F","srifle_GM6_LRPS_F"," srifle_LRR_LRPS_F","LMG_Mk200_MRCO_F"]; To do this you could put the following into the object(s) init: _gun = selectRandom gun; this addWeaponCargo [_gun, 1]; This makes sure that, each time, a random gun is chosen from a defined array of possible weapons rather than always adding one randomly selected weapon. To run the same code X amount of times you can use a for loop, specifically a for-from-to-loop. This is demonstrated in the example below: for "_i" from 1 to 3 do { _gun = selectRandom gun; this addWeaponCargo [_gun, 1]; }; This will run the code 3 times, (1 to 3 inclusive) and each time it will define a new random weapon to spawn in the crate. You can read more about for loops in the link I provided. Share this post Link to post Share on other sites
auroraah 10 Posted July 28, 2017 Thanks for that, knew it could be done more simply! The for-from-to-loop is absolutely perfect for what I need too :D Through trial and error I'd found the thing with it always spawning the same gun, that was the reason for wanting the loop. Share this post Link to post Share on other sites
HallyG 239 Posted July 28, 2017 Just now, auroraah said: Thanks for that, knew it could be done more simply! The for-from-to-loop is absolutely perfect for what I need too :D Through trial and error I'd found the thing with it always spawning the same gun, that was the reason for wanting the loop. It was always spawning the same gun because the variable "gun" was a random weapon which was defined once, at the start of the mission. What you need to do is to chose a random weapon each time you want to add something, hence the code in my examples. Share this post Link to post Share on other sites
auroraah 10 Posted July 28, 2017 2 minutes ago, HallyG said: It was always spawning the same gun because the variable "gun" was a random weapon which was defined once, at the start of the mission. What you need to do is to chose a random weapon each time you want to add something, hence the code in my examples. Tis perfect tyvm :) Share this post Link to post Share on other sites