SA-MP Forums Archive
[HELP]Success/Fail? - 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: [HELP]Success/Fail? (/showthread.php?tid=296276)



[HELP]Success/Fail? - MadalinX5 - 10.11.2011

Hello
I got a small question. I'm trying to make a small command "/rob" but I want to add a success / fail rate like chances of 25% to succeed. Can anyone help me with this? Thank you


Re: [HELP]Success/Fail? - Pharrel - 10.11.2011

new success = random(4);
if(success != 1)
return SendClientMessage(playerid, -1, "fail);

i'm not sure if the random get the 0 but i gess not... so this way if the random returns 1 he will be able to rob else he will receive the message...


Re: [HELP]Success/Fail? - MadalinX5 - 10.11.2011

How can I use the random(4) in my favor? For example random(2) = 50% chance.

And I didn't quite get the "If(success != 1)". Why should it be different from 1?

Please explain, I would appreciate.
Thanks ^^


Re: [HELP]Success/Fail? - Pharrel - 10.11.2011

The random get a random number between 1 (i'm not sure if is 1 or 0...probably 1) and the number that you put... so when you use random(4) the chances to return 1 is 25% that way you know that he failed if the number is different from 1 (the 1 can be any number between 1 and 4)

idk if you understood...sorry my bad english :/


Re: [HELP]Success/Fail? - PowerPC603 - 10.11.2011

Random gets a random value ranging from 0 to the value minus 1.

pawn Код:
random(100)
Would return a random value ranging from 0 to 99.

So, to use percentages:
pawn Код:
if (random(100) < 25) printf("You now have a 25% successrate");



Re: [HELP]Success/Fail? - MadalinX5 - 12.11.2011

Thank you for the help Pharrel and PowerPC603