Jump to content
Sign in to follow this  
alleycat

Pick from list randomly?

Recommended Posts

I got an array containing 5 different arrays, with 3 ASL coordinates for each one. How do I randomly pick from that array?

#define SPAWN1		[7278.79,276.733,290.255]
#define SPAWN2		[2023.23,76.0343,360.341]
#define SPAWN3		[2113.41,95.0344,353.035]
#define SPAWN4		[2836.51,553.222,367.111]
#define SPAWN5		[3004.98,699.092,378.777]

I would like to create a list from this and pick from it randomly but I am not sure how.

Like this:

_spawnlist = [1,2,3,4,5], then pick from it random

Share this post


Link to post
Share on other sites

_item = [sPAWN1,SPAWN2,SPAWN3,SPAWN4,SPAWN5] call BIS_fnc_selectRandom;

You may need the function module placed on the map

OR

_spawnlist = [sPAWN1,SPAWN2,SPAWN3,SPAWN4,SPAWN5]; 
_index = floor random 5;// 0-4
hint str (_spawnlist select _index);

Edited by F2k Sel

Share this post


Link to post
Share on other sites

Something like this should also work:

_spawn_pos = call compile format["SPAWN%1", (floor random 5)+1];

Share this post


Link to post
Share on other sites

Or more simply....

_arr = [sPAWN1,SPAWN2,SPAWN3,SPAWN4,SPAWN5];
_pos = _arr select (floor (random (count _arr)));

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×