Check procents %
#1

Hi,

I want to calculate chance for people for action for ex:

When he write command:

CMD:HELLO(playerid,params[])
{

How to send this message calcuating 70 proc. of success. Of course can be x/100 proc.
SendClientMessage( playerid, -1,"Succes");
return 1;
}
Reply
#2

pawn Код:
new success = random(2);
if(success == 0)
{
  // codes
}
else if(success == 1)
{
 //codes
}
Reply
#3

I know random but i need another way for example how you will do if i want to make 99 % that will be succefully and left 1 % that can fail.
Reply
#4

Well it depends on what is the maximum value. Try to add random(20) and you will get more chances, I mean like
5 % and other.
Reply
#5

Quote:
Originally Posted by Banditukas
Посмотреть сообщение
I know random but i need another way for example how you will do if i want to make 99 % that will be succefully and left 1 % that can fail.
Still using random.

pawn Код:
switch (random(100))
{
    case 0:
    {
        // 1%
    }
    default:
    {
        99%
    }
}
Reply
#6

It'is will be possible to make stock like that

stock CalculateProc( proc )
{
switch (random(proc-1))
{
case 0:
{
// 1%
}
default:
{
99%
}
}

how work with cases
}
Reply
#7

Something like this?

PHP код:
CalculateProc(value)
{
    return (
<= random(100) < value) ? 2;

pawn Код:
// returns 1 if the random number is in the percentage you specified or else it returns 2
CalculateProc(50); // 50% - 50%
CalculateProc(30); // 30% (returns 1) - 70% (returns 2)
CalculateProc(1); // 1% (returns 1) - 99% (returns 2)
Reply
#8

pawn Код:
if(random(100) < 70)
{
    //Do your thing
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)