Jump to content
Sign in to follow this  
FartParty

calling 7 numbers in random order?

Recommended Posts

I need a script that will count randomly from 1 to 7, i'm not sure where to start

only just getting into scripting, it's very difficult

can anyone point me in the right direction

Share this post


Link to post
Share on other sites

Or you can use existing function BIS_fnc_arrayShuffle, without need to install any addon:

[1, 2, 3] call BIS_fnc_arrayShuffle;

More about functions

Share this post


Link to post
Share on other sites
Why allocate an array when you could use this?

x=floor(random 7)+1;

will return 1-7

That will return a random number between 1 and 7, but it seems like the OP wanted to have a loop iterate 7 times and each time choose a unique number between 1 and 7. In that case he would need an array.

Share this post


Link to post
Share on other sites
I don't see where the loop comes into play.

From the first post

I need a script that will count randomly from 1 to 7

Share this post


Link to post
Share on other sites

Okay whatever you say.

_count = 0;
while {_count < 6}
do
{
x=floor(random 7)+1;
//Do something with random number
_count = _count + 1;
};

Edited by Johnson11B2P
for to increment the counter

Share this post


Link to post
Share on other sites
Okay whatever you say.

_count = 0;
while {_count < 6}
do
{
x=floor(random 7)+1;
//Do something with random number
};

But from what the OP says, it looks like he wants each number to be unique. Your example can choose the same number more than once. For example: 1, 4, 5, 6, 2, 1, 6

If he wanted to have each number selected exactly once you would need an array.

[1, 2, 3, 4, 5, 6, 7]

Then using the array shuffle function you get the numbers in a random order,

[4, 2, 3, 7, 5, 1, 7]

The difference is that in the second example each number is unique.

Share this post


Link to post
Share on other sites
_numbers = [1,2,3,4,5,6,7];
while{_count <  6}
do
{
_numbers call BIS_fnc_arrayShuffle;
_num = _numbers call BIS_fnc_arrayPop;
_count = _count + 1;
};

Share this post


Link to post
Share on other sites
_numbers = [1,2,3,4,5,6,7];
while{_count <  6}
do
{
_numbers call BIS_fnc_arrayShuffle;
_num = _numbers call BIS_fnc_arrayPop;
_count = _count + 1;
};

Although it would only be necessary to shuffle the array once. Since after you shuffle it, all of the elements are in a random order. Also, BIS_fnc_arrayShuffle returns the new sorted array, so you would have to store it. _numbers = _numbers call BIS_fnc_arrayShuffle.

{
   // Do something with _x (the random number)
} foreach ([1, 2, 3, 4, 5, 6, 7] call BIS_fnc_arrayShuffle)

This would be a little bit more efficient.

Share this post


Link to post
Share on other sites

thanks, this is very helpful, but i'm not sure i understand how to use this information

i have 7 triggers on the map, and i want to activate them all in a random order

they are activated by whatever this is called

"trigger1 = true"

Share this post


Link to post
Share on other sites

To check boolean (true/false) of a variable, use the variables name. ie;

if (trigger1) then {hint "It's true";} else {hint "It's false";}; //example 1
if (!trigger1) then {hint "It's false";} else {hint "It's true";};//example 2

Share this post


Link to post
Share on other sites

okay i used that code, but it's not doing anything

How do i use it to activate the triggers?

I want each trigger to be a script. it will activate trigger1, which in turn will activate a script (being a gamemode [e.g. team deathmatch/capture the flag])

it will wait until the gamemode has concluded, tally a winner, and call the next gamemode, repeat, until all 7 have been played

a.k.a. warzone from the killzone series

Share this post


Link to post
Share on other sites
okay i used that code, but it's not doing anything

...

I want each trigger to be a script. it will activate trigger1, which in turn will activate a script (being a gamemode [e.g. team deathmatch/capture the flag])

it will wait until the gamemode has concluded, tally a winner, and call the next gamemode, repeat, until all 7 have been played

a.k.a. warzone from the killzone series

Ahh yes, that was a simple explanation on how to check if a variable has been set to true or false. The variable can be anything you like. And you're asking how to make one mission, containing a huge nest of different game modes? LOL, I wont touch this one! But good luck getting the ball rolling on that.

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  

×