clydefrog 3 Posted May 1, 2013 Hi, if I have a group being spawned like the following: _pedgrp = createGroup west; // create and spawn pedestrian group _unit1 = _pedgrp createUnit ["C_man_1_1_F", [_spawnPos select 0,_spawnPos select 1,1], [], 26, "NONE"]; _unit2 = _pedgrp createUnit ["C_man_polo_1_F", [_spawnPos select 0,_spawnPos select 1,2], [], 26, "NONE"]; _unit3 = _pedgrp createUnit ["C_man_1", [_spawnPos select 0,_spawnPos select 1,3], [], 26, "NONE"]; _unit4 = _pedgrp createUnit ["C_man_polo_6_F", [_spawnPos select 0,_spawnPos select 1,4], [], 26, "NONE"]; how can I make the script only select a random amount of them each time the script is run? So in this case a maximum of 4 and minimum of 1? Share this post Link to post Share on other sites
mikie boy 18 Posted May 1, 2013 (edited) how can I make the script only select a random amount of them each time the script is run? So in this case a maximum of 4 and minimum of 1? do you mean something like this or have i read that wrong.... _rnd = ceil(random 5); _pedgrp = createGroup west; for [{_i=1}, {_i<_rnd},{_i = _i +1}] do { _soldier = ["C_man_1_1_F","C_man_polo_6_F","C_man_1","C_man_polo_1_F"] call BIS_fnc_selectRandom; _unit1 = _pedgrp createUnit [_soldier , [_spawnPos select 0,_spawnPos select 1,_i], [], 26, "NONE"]; }; Edited May 1, 2013 by Mikie boy Share this post Link to post Share on other sites
clydefrog 3 Posted May 1, 2013 If that's picking a random classname no. I mean selecting a random amount of units from the group to spawn. So if the group created is 4 soldiers then randomly spawn a number between 1 and 4. Share this post Link to post Share on other sites
mikie boy 18 Posted May 1, 2013 the above randomly spawns between 1 and 4 soldiers with different classes Share this post Link to post Share on other sites
clydefrog 3 Posted May 1, 2013 Oh great, do you mind explaining a bit how that's working? I can see it is assigning _i as a random number below 5 and then spawning that many units, but I'm unsure about a couple of things, including where _i is in the createUnit array. Thanks Share this post Link to post Share on other sites
mikie boy 18 Posted May 1, 2013 look at the tutorial i made - the 'for loop' - should clear up what _i is doing there. long story short - _i is just representing the count form 0 upwards - but placing _i within the loop it represents whatever 0 -4 number it is currently. So each time it goes round it increments by 1 until it reaches whatever the maximum number is defined by _rnd. Sorry if i havent been clear Share this post Link to post Share on other sites
clydefrog 3 Posted May 1, 2013 look at the tutorial i made - the 'for loop' - should clear up what _i is doing there. long story short - _i is just representing the count form 0 upwards - but placing _i within the loop it represents whatever 0 -4 number it is currently. So each time it goes round it increments by 1 until it reaches whatever the maximum number is defined by _rnd.Sorry if i havent been clear Yeah I've read it and I just had another look before asking you but still couldn't make full sense of it ( I understand it in your tutorial but didn't this way with the random number). 2 things, how come the _i goes where it does in that array? I thought that was to do with position. And also sometimes it is not spawning any units at all. Share this post Link to post Share on other sites
mikie boy 18 Posted May 1, 2013 its probably defining 0 in the random variable. basically you have used _spawnPos select 1,1 - i have put _i in where _spawnPos select 1,_i - this is because each time the loop goes round _i = 1, then 2, then 3, then 4. Thus it mirrors the 1,4 you wanted. If i didnt put _i there it would always be the number u put in the line. if the loop only goes round three times then the first will be 1 and the last will be 3. that any better? Share this post Link to post Share on other sites
clydefrog 3 Posted May 1, 2013 its probably defining 0 in the random variable. basically you have used _spawnPos select 1,1 - i have put _i in where _spawnPos select 1,_i - this is because each time the loop goes round _i = 1, then 2, then 3, then 4. Thus it mirrors the 1,4 you wanted. If i didnt put _i there it would always be the number u put in the line. if the loop only goes round three times then the first will be 1 and the last will be 3. that any better? I don't actually know what the number at the end of that line [_spawnPos select 0,_spawnPos select 1,1] does. They are 1 to 4 in my first example just because I was trying to see what it actually did, I thought it might be altitude or something, this is why I'm confused why the _i goes there. I still don't know now what it does. Sorry for not understanding this, maybe by putting those 1 - 4 after each _spawnPos select 0,_spawnPos select 1 I have confused you to what I want it to do as well. I just want to be able to create this group multiple times by calling the script multiple times, but each time the script is called it spawns a random amount of units from the group, with a maximum amount possible of about 4 or 5 and a minimum amount possible of 1. Share this post Link to post Share on other sites
mikie boy 18 Posted May 1, 2013 _spawnPos select 0,_spawnPos select 1,Z [x,y,Z] position of whatever _spawnpos is - height basically... _rnd = ceil(random 5); _pedgrp = createGroup west; for [{_i=1}, {_i<(_rnd + 1)},{_i = _i +1}] do { _soldier = ["C_man_1_1_F","C_man_polo_6_F","C_man_1","C_man_polo_1_F"] call BIS_fnc_selectRandom; _unit1 = _pedgrp createUnit [_soldier , [_spawnPos select 0,_spawnPos select 1,0], [], 26, "NONE"]; }; That should do it, +1 to the random number - so never 0. 1- 5 units per group should spawn everytime you call this script. I've set the Z co-ordinate to 0. Share this post Link to post Share on other sites
clydefrog 3 Posted May 2, 2013 _spawnPos select 0,_spawnPos select 1,Z [x,y,Z] position of whatever _spawnpos is - height basically... _rnd = ceil(random 5); _pedgrp = createGroup west; for [{_i=1}, {_i<(_rnd + 1)},{_i = _i +1}] do { _soldier = ["C_man_1_1_F","C_man_polo_6_F","C_man_1","C_man_polo_1_F"] call BIS_fnc_selectRandom; _unit1 = _pedgrp createUnit [_soldier , [_spawnPos select 0,_spawnPos select 1,0], [], 26, "NONE"]; }; That should do it, +1 to the random number - so never 0. 1- 5 units per group should spawn everytime you call this script. I've set the Z co-ordinate to 0. Works perfect, thanks Mikie. Share this post Link to post Share on other sites