Jump to content
Joe98

A more elegant wat to do - random

Recommended Posts

Place a box on the map and name it box1

Place 9 markers on the map. Group the box with the markers.

Every time the mission starts, the box will start at one of 10 places selected at random (its original location or one of the 9 markers).

 

 

I would like to do this in a more elegant way avoiding those confusing lines all over the map. For example:

 

Place 10 markers on the map and name them marker0 – marker9

Then, in the init of box1, type:

box1 setpos getpos marker(select a number at random from 0 to 9);

 

 

I went to the wiki and found this:

 

https://community.bistudio.com/wiki/random

 

As a result I tried this command in the init of box1

 

_nRumber  =  floor  random  10;  box1  setpos  getpos  marker(_rNumber);

 

It does not work.  Any suggestions?.

.

 

Share this post


Link to post
Share on other sites


box1 setPos (getMarkerPos format ["marker_%1",floor(random 10)];);

  • Like 1

Share this post


Link to post
Share on other sites

Try this untested piece of code in the init line:

_rNumber = floor random 10; this setPos (getMarkerPos format ["marker%1", _rNumber]);

Share this post


Link to post
Share on other sites

This should also work (and is a bit shorter than the previous answers):

this setPos getMarkerPos ("marker" + str floor(random(10)));

I prefer short comands in init-fields.

Share this post


Link to post
Share on other sites

createvehicle can do this on it's own.

 

box1 createvehicle ["box1classname", markerpos "marker_0", "marker_1",["marker_2", "marker_3", "marker_4", "marker_5", "marker_6", "marker_7", "marker_8", "marker_9"],0,"NONE"];

Share this post


Link to post
Share on other sites

The favourite ones I use mostly are:

 

 

For Integers:

rndNum = round(random 10);

For Strings in Array (Got a bit cheeky here ;) ):

player addAction ["Am I good, ArmA?", {rndStr = ["are fucking amazing!", "are a pro!", "are good.", "are not bad.", "are bad.", "are terrible.", "fucking suck!", "are shit at this game."] call BIS_fnc_SelectRandom; hint format ["You %1", rndStr]}];

I never tried the below for myself really, but it is another loop method I found:

rndNum = round(random 10);
switch (rndNum) do {
	case 0: {};
	case 1: {};
	case 3: {};
	case 4: {};
	case 5: {};
	case 6: {};
	case 7: {};
	case 8: {};
	case 9: {};
	case 10: {};
};

Share this post


Link to post
Share on other sites

Place a box on the map and name it box1

Place 9 markers on the map. Group the box with the markers.

 

How do you do that ? Everytime I'm clicking on the "group" or "chain" icon, all markers are disapearing in the editor.

Share this post


Link to post
Share on other sites

How do you do that ? Everytime I'm clicking on the "group" or "chain" icon, all markers are disapearing in the editor.

Yes, you have to remember where the marker is before grouping it.

Share this post


Link to post
Share on other sites

Yes, you have to remember where the marker is before grouping it.

 

Or simply make it of a visible type, link them all, then make them empty again :).

Share this post


Link to post
Share on other sites

Or simply make it of a visible type, link them all, then make them empty again :).

Nope because when you select the 'group' menu (f2), all markers are hidden.

Share this post


Link to post
Share on other sites

Nope because when you select the 'group' menu (f2), all markers are hidden.

 

And that's what I get for trying to answer posts too soon after waking up :p, lol.

  • Like 2

Share this post


Link to post
Share on other sites

Yes, you have to remember where the marker is before grouping it.

 

Thx !! I was not aware of this feature.

I just create the marker close by then move it once grouped with the unit.

Share this post


Link to post
Share on other sites
this setPos getMarkerPos ("marker" + str floor(random(10)));

This is the best and I confirm that it works beautifully thank you!

 

.

Share this post


Link to post
Share on other sites

Agreed. Out of all the solutions, it's the sexiest.

Share this post


Link to post
Share on other sites

The favourite ones I use mostly are:

For Integers:

rndNum = round(random 10);

This one is not the best. Numbers 1 and 10 has only half the chance of being selected compared to 2..9, and 10 was not supposed to be selected either. Better to use floor than round to get a value in the span 0..9:

rndNum = floor random 10;

Share this post


Link to post
Share on other sites

I allways had some doubt about the floor random method.

 

In this case. What if floor random 10 returns 10?

 

I mean: you have "Marker0","marker1"..."Matrker9" so, floor random 10 will be 0 to 9 in 99,999999% of times.

 

But what if your mission is making random calls millions of times per session? That will happen!

 

Just a thought...

Share this post


Link to post
Share on other sites

 

In this case. What if floor random 10 returns 10?

random 10 will never return 10. It's between 0>= x <10

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

×