SA-MP Forums Archive
Check procents % - 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: Check procents % (/showthread.php?tid=576995)



Check procents % - Banditukas - 08.06.2015

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;
}


Re: Check procents % - Rabea - 08.06.2015

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



Re: Check procents % - Banditukas - 08.06.2015

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.


Re: Check procents % - dominik523 - 08.06.2015

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.


Re: Check procents % - Konstantinos - 08.06.2015

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%
    }
}



Re: Check procents % - Banditukas - 08.06.2015

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
}


Re: Check procents % - Konstantinos - 08.06.2015

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)



Re: Check procents % - ikey07 - 08.06.2015

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