SA-MP Forums Archive
Percents - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Percents (/showthread.php?tid=512788)



Percents - rumen98 - 12.05.2014

Hello I want to ask, for example is it possible to make code example I want to have a 20% chance to become IGInfo [playerid] [Owner] = 1; and in the other 80% to nothing happens.
Could this be done somehow?


Re: Percents - Konstantinos - 12.05.2014

pawn Код:
switch (random(10))
{
    case 0, 1:
    {
        // 20%
    }
}



Re: Percents - rumen98 - 12.05.2014

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
pawn Код:
switch (random(10))
{
    case 0, 1:
    {
        // 20%
    }
}
is there

PHP код:
case 01
are percent options ? example
PHP код:
 case 0
is 10% ? and for 5% how to make ?


Re: Percents - Konstantinos - 12.05.2014

Using 10 as max in random function will let you to use it as 10, 20 .. 90, 100 percent. And yes, using case 0 is like using 10% for the above example.

However for using 5%, you'll need to change the max to 100 and check if it's the first 5 digits (0-4), then it's 5 percent.
pawn Код:
switch (random(100))
{
    case 0 .. 4:
    {
        // 5%
    }
}



Re: Percents - rumen98 - 12.05.2014

Thanks you i will try it and post if i have any problems


Re: Percents - rumen98 - 13.05.2014

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
pawn Код:
switch (random(10))
{
    case 0, 1:
    {
        // 20%
    }
}
Hello again, I want to ask does this code generate 10 or 11 numbers in the sense of adding 0 as another number + those from 1 to 10 are 11 or so?

I ask because there wondering one thing and do not know whether it is so

with 27 numbers
PHP код:
    switch (random(27-RLTnfo[playerid][Chance]))
    {
        case 
0,1//7,40% - 28,57% by 20 level Chance
        
{
        
//code
        
}
    } 
or

with 27 numbers plus a zero to the numbers from 1 to 27 = 28
PHP код:
    switch (random(27-RLTnfo[playerid][Chance]))
    {
        case 
0,1//7.14% - 25% by 20 level Chance
        
{
        
//code
        
}
    } 
Which of these is the 2 correct?


Re: Percents - Konstantinos - 13.05.2014

Because the indexes in PAWN starts from 0 when you have size/max a number N, it's always: 0 to (N-1).

For example, using 10 is 0-9 (which is 10 in total).

I'm not sure if you can use floating-point numbers for that case.


Re: Percents - rumen98 - 13.05.2014

Ah, so the first one is true?
Here it
PHP код:
    switch (random(27-RLTnfo[playerid][Chance])) 
    { 
        case 
0,1//7,40% - 28,57% by 20 level Chance 
        

        
//code 
        

    } 



Re: Percents - Konstantinos - 13.05.2014

No, it's not. The max value in random is unknown and with case 0/1 you won't get 7.40% - 28.57% percent.


Re: Percents - rumen98 - 13.05.2014

I think you do not understand exactly, then these percentages which I have written have a chance to drop these numbers by random (27) rates to fall 0 or 1 is 7.40% and at Level 20 Chance parameter, which removes 20 index and becomes random (7) the chance to fall 0 or 1 becomes 28.57%