Select at Random Worldspaces

mmmyum

Valued Member!
Hey, I've written a short snippet you can use to select a random location and I figured it might be of some use to someone else! (I will be using it in my air raid script, feel free to use it too!)

Right now, the worldspaces are towns/cities, and there is a list of 50. There are some diag_logs your could comment out to clean up your RPT as well, and it gives variables containing x, y, z, and location name.

Code:
_loc = ["BalottaAirstrip",1.5,4829.9868,2450.1104];
_city = "BalottaAirstrip";  //init vars
_x = 4829.9868;
_y = 2450.1104;
_z = 1.5;
_coords = [_x,_y,_z];
_tries = 20;                           //set num of loops here
diag_log format ["RANDOM WORLDSPACE: Initializing... %1 | %2 %3 %4|",_city,_x,_y,_z];
sleep 1;
///////////////////////////////////////////////selector
While {_tries > 1} do {
_rndSel=floor(random 49); //select random number 0-49, then set loc based on the case number
_loc=
switch (_rndSel) do {
case 0: {["BalottaAirstrip",1.5,4829.9868,2450.1104]};
case 1: {["Berenzino",1.5,12954.624,9783.1533]};
case 2: {["Bereznio2",1.5,12043.963,9091.3477]};
case 3: {["BlackMountain",1.5,10276.416,12049.6640]};
case 4: {["Bor",1.5,3320.1643,3938.3496]};
case 5: {["Cherno",1.5,6743.8853,2581.1865]};
case 6: {["DevilsCastle",1.5,6891.9189,11438.73]};
case 7: {["DonsCamp",1.5,7788.2856,12613.048]};
case 8: {["Drozhino",1.5,3442.2849,4955.7129]};
case 9: {["Dubrovka",1.5,10445.011,9868.9912]};
case 10: {["Electro",1.5,10480.69,2217.8027]};
case 11: {["Factory",1.5,13060.078,7094.0596]};
case 12: {["Gorka",1.5,9659.084,8795.334]};
case 13: {["Grishno",1.5,5979.6953,10343.341]};
case 14: {["Guglovo",1.5,8517.8682,6676.3276]};
case 15: {["Gvozdno",1.5,8614.4316,11868.967]};
case 16: {["Kabanino",1.5,5318.8369,8602.6328]};
case 17: {["Kamyshovo",1.5,12127.406,3496.2185]};
case 18: {["Khelm",1.5,12290.833,10904.328]};
case 19: {["Komarovo",1.5,3654.0908,2475.9468]};
case 20: {["Kozlovka",1.5,4483.6777,4616.1675]};
case 21: {["Krastonav",1.5,11212.624,12256.609]};
case 22: {["Lopatino",1.5,2780.3135,10018.82]};
case 23: {["Moglievka",1.5,7544.5845,5148.7822]};
case 24: {["Msta",1.5,11275.323,5495.4053]};
case 25: {["Myshkino",1.5,2019.2487,7327.7178]};
case 26: {["Nadezhdino",1.5,5846.4434,4706.708]};
case 27: {["NEAF",1.5,12073.906,12724.305]};
case 28: {["Nizhnoye",1.5,13002.393,8285.8574]};
case 29: {["NovySobor",1.5,7074.4854,7683.4883]};
case 30: {["NWAF",1.5,4480.0781,10375.544]};
case 31: {["Orlovets",1.5,12146.174,7266.5801]};
case 32: {["Pavlovo",1.5,1693.9392,3845.0657]};
case 33: {["Petrovka",1.5,5014.1143,12493.039]};
case 34: {["Pogorevka",1.5,4473.5957,6411.3198]};
case 35: {["Polana",1.5,10753.393,8132.6606]};
case 36: {["Prigorodki",1.5,7976.5557,3299.5386]};
case 37: {["Pulkovo",1.5,4915.0903,5605.6401]};
case 38: {["Pusta",1.5,9156.2549,3897.7598]};
case 39: {["Pustoshka",1.5,3072.9629,7945.4404]};
case 40: {["Rogovo",1.5,4808.0024,6805.0518]};
case 41: {["Shakhovka",1.5,9654.5244,6555.2583]};
case 42: {["Solnichny",1.5,13454.279,6233.647]};
case 43: {["Soosnovka",1.5,2528.7561,6354.9839]};
case 44: {["Staroye",1.5,10140.659,5434.4302]};
case 45: {["StarySobor",1.5,6143.6167,7721.5176]};
case 46: {["Tulga",1.5,12803.296,4450.7466]};
case 47: {["Vybor",1.5,3815.0635,8865.0938]};
case 48: {["Vyshnoye",1.5,6590.3159,6029.1128]};
case 49: {["Zelenogorsk",1.5,2758.7144,5304.3457]};
};
_city = _loc select 0;
_z = _loc select 1;
_x = _loc select 2;
_y = _loc select 3;
_coords = [_x,_y,_z];
diag_log format ["RANDOM WORLDSPACE: %1 | %2",_city,_coords];
sleep 1;
diag_log format ["RANDOM WORLDSPACE SELECTED: %1 | City: %2 | Coords: %3  %4 |||Try %5",_rndSel,_city,_x,_y,_tries];
_tries = _tries - 1;
};
sleep 2;
diag_log format ["RANDOM WORLDSPACE: %1 | Going to shutdown",_tries];
exit

Current output RPT:
Code:
1:36:45 "RANDOM WORLDSPACE SELECTED: 16 | City: Kabanino | Coords: 5318.84 8602.63 |||Try 10"
1:36:45 "RANDOM WORLDSPACE: Prigorodki | [7976.56,3299.54,1.5]"
1:36:46 "RANDOM WORLDSPACE SELECTED: 36 | City: Prigorodki | Coords: 7976.56 3299.54 |||Try 9"
1:36:46 "RANDOM WORLDSPACE: Kabanino | [5318.84,8602.63,1.5]"
1:36:47 "RANDOM WORLDSPACE SELECTED: 16 | City: Kabanino | Coords: 5318.84 8602.63 |||Try 8"
1:36:47 "RANDOM WORLDSPACE: Factory | [13060.1,7094.06,1.5]"
 
I would do that different ...

set up a nested array like this:

Code:
_locations = [
 
["BalottaAirstrip",1.5,4829.9868,2450.1104],
["Berenzino",1.5,12954.624,9783.1533],
["Bereznio2",1.5,12043.963,9091.3477],
["BlackMountain",1.5,10276.416,12049.6640]
 
];
etc, the last one must NOT have a comma at the end.

Then you can simply do in your while loop

Code:
_rnd=floor(random((count _locations)-1));
 
_location = _locations select _rnd;
_coords = [_location select 2,_location select 3,_location select 1];
_city = _location select 0;
 
@Sarge, I didn't even know that was possible, tho I had been wondering about using just the array, you are a hero! Thanks for the advice.

I'm still learning most of it, and I know I've been going about things in a less than efficient fashion. I appreciate it.


Just trying to make sure I understand, it's real late here -
Will the count _locations return the actual number (as in they start 1,2,3,4), so you subtract 1 from that to get a value we can use to select the right location in the nested array (as arrays start numbering at 0)?

Thanks again man.
 
correct, that's why i subtract 1 from the count of the array.

CRAP .-) shouldn't write stuff tired .-)

remove the -1, thats incorrect. random 4 will never give 4, but 0. So the subtracting is not needed at all.

sry, Sarge
 
Haha no worries we all been there. Thanks for letting me know, I might've spent quite a while on it today if I noticed it wasn't working.
Going to go implement this in my code now, thanks again
 
These are both snippets meant to be part of a script. All they do is pick at random a location from the list. I use one in my airraid script.
 
Thanks for this !
I just installed it for my Taviana server, just need the cities coords to modify the provide one...someone can help me ? thx
 
Back
Top