08.02.2013, 19:52
Well you'd have to use the 'random' function for that.
What you could do was something like this:
Here I created a random value from 0 to 86.
Your array has only 33 indexes - this is why I have to check its value.
With the code above, the numbers 0-9 will give you the first index ("Shark"), 10-19 will give you the next one, et cetera.
If your randomly chosen value is 60 or more, it will simply set the moneybags.
Moneybag #1 is on index 6, so value 60 should be index 6, and we all know that 60 - 54 = 6, hence the "iRand -= 54;" expression.
If you want less change of getting moneybags, increase the integer used in the 'random' function call by a number dividible by 6, as you have 6 fishes, then change the if-statements to match it.
To then select your index, you simply have to do this:
I hope you understand and can and will take this to good use - good luck!
What you could do was something like this:
pawn Код:
new
iRand = random(87)
;
if( iRand < 10 ) // 0 - 9
{
iRand = 0;
}
else if( iRand < 20 ) // 10 - 19
{
iRand = 1;
}
else if( iRand < 30 ) // 20 - 29
{
iRand = 2;
}
else if( iRand < 40 ) // 30 - 39
{
iRand = 3;
}
else if( iRand < 50 ) // 40 - 49
{
iRand = 4;
}
else if( iRand < 60 ) // 50 - 59
{
iRand = 5;
}
else
{
iRand -= 54;
}
Your array has only 33 indexes - this is why I have to check its value.
With the code above, the numbers 0-9 will give you the first index ("Shark"), 10-19 will give you the next one, et cetera.
If your randomly chosen value is 60 or more, it will simply set the moneybags.
Moneybag #1 is on index 6, so value 60 should be index 6, and we all know that 60 - 54 = 6, hence the "iRand -= 54;" expression.
If you want less change of getting moneybags, increase the integer used in the 'random' function call by a number dividible by 6, as you have 6 fishes, then change the if-statements to match it.
To then select your index, you simply have to do this:
pawn Код:
FishNames[ iRand ]
//example:
format( string, sizeof( string ), "%s", FishNames[ iRand ] );