Random Arrays -
Luis- - 06.03.2015
Hey! I've just thought of an idea but don't know if it'll work, to save me time coding it i'd rather ask here first.
Would it be possible to have a few different arrays with coords in them, all named "Array" with a number at the end, "1, 2, 3 etc" and then have a function to choose one of the arrays at random? Maybe formatting a string, "format(string, sizeof string, "Array%d", random(5));"
Surely it must be possible.
AW: Random Arrays -
Kaliber - 06.03.2015
Just make it easy and make a multidimensional array like this:
PHP код:
stock const array[][] = {
{1,2,3,4},
{5,6,7,8},
{9,10,11,12}
};
printf("%d",array[random(sizeof array)][random(sizeof(array[]))]);
Greekz
Re: Random Arrays -
Luis- - 06.03.2015
What if i had multiple coords in one array though?
Re: Random Arrays -
RedFusion - 06.03.2015
one 3d array should suffice.
pawn Код:
new Float:testarray[2][2][3] =
{
{
{0.0, 0.0, 0.0},
{1.0, 1.0, 1.0}
},{
{0.0, 0.0, 0.0},
{1.0, 1.0, 1.0}
}
};
getRandomArray(&Float:x, &Float:y, &Float:z)
{
new
first_index = random(sizeof testarray),
second_index = random(sizeof testarray[]),
x = testarray[first_index][second_index][0],
y = testarray[first_index][second_index][1],
z = testarray[first_index][second_index][2]
;
}
AW: Re: Random Arrays -
Kaliber - 06.03.2015
Quote:
Originally Posted by Luis-
What if i had multiple coords in one array though?
|
Can you make an Example, like this:
PHP код:
stock const Float:coords[][3] = {
{x,y,z},
{x1,y1,z1},
{x2,y2,z2}
};
new r = 1;
printf("X: %f | Y: %f | Z: %f",coords[r][0],coords[r][1],coords[r][2]);
//-> Would be: X: x1 | Y: y1 | Z: z1
new r = random(sizeof coords); //That would coose random coords
Greekz
Re: Random Arrays -
Luis- - 06.03.2015
Well, i'm wanting to do it for my DMV system, instead of having just one route to use, I was thinking of having a couple which would be chosen at random. So, if the script chose array1 it'd show the checkpoints for array1, if it chose array2 it'd show array2 checkpoints.
AW: Re: Random Arrays -
Kaliber - 06.03.2015
Quote:
Originally Posted by Luis-
Well, i'm wanting to do it for my DMV system, instead of having just one route to use, I was thinking of having a couple which would be chosen at random. So, if the script chose array1 it'd show the checkpoints for array1, if it chose array2 it'd show array2 checkpoints.
|
Ahh i understand ok.
Well, then make sth like this:
Код:
switch(random(MAX_ROUTS)) {
case 0: //here you start route 1
case 1: //here you start route 2
case 2: //here you start route 3
//...
}
Make it like this..its the easiest way xD
Re: Random Arrays -
Luis- - 06.03.2015
Got it working, thank you