Chance?
#1

How to make so when someone does command like /casino
it gives them a chance to win or lose
so 5% of wining
95% of losing
Reply
#2

Simply
pawn Код:
if(random(100) < 5) // 5%
{
// winner
}
Reply
#3

how can i send him a message if he lost?
Reply
#4

add at the end

else{
// fail
}
Reply
#5

Using random() is really poor for this I would suggest using this as instead.

https://sampforum.blast.hk/showthread.php?tid=109196

Want to see how poorly random() performs?

Try run the following code on this website.

http://slice-vps.nl:7070/

pawn Код:
#include <a_samp>

main() {
    new r[100];
    for(new i = 0; i < 100; i++)
    {
        r[random(100)]++;
    }
    for(new i = 0; i < 100; i++)
    {
        printf("Number: %i Chosen: %i", i, r[i]);
   
    }
    return 1;
}
Output: (This changes each run but as you can see the distribution is terrible you can't get a reliable win percentage)

Number: 0 Chosen: 0
Number: 1 Chosen: 0
Number: 2 Chosen: 2
Number: 3 Chosen: 1
Number: 4 Chosen: 2
Number: 5 Chosen: 0
Number: 6 Chosen: 0
Number: 7 Chosen: 1
Number: 8 Chosen: 0
Number: 9 Chosen: 4
Number: 10 Chosen: 2
Number: 11 Chosen: 0
Number: 12 Chosen: 1
Number: 13 Chosen: 2
Number: 14 Chosen: 2
Number: 15 Chosen: 0
Number: 16 Chosen: 0
Number: 17 Chosen: 0
Number: 18 Chosen: 2
Number: 19 Chosen: 2
Number: 20 Chosen: 1
Number: 21 Chosen: 1
Number: 22 Chosen: 0
Number: 23 Chosen: 1
Number: 24 Chosen: 0
Number: 25 Chosen: 3
Number: 26 Chosen: 3
Number: 27 Chosen: 2
Number: 28 Chosen: 2
Number: 29 Chosen: 0
Number: 30 Chosen: 1
Number: 31 Chosen: 0
Number: 32 Chosen: 1
Number: 33 Chosen: 1
Number: 34 Chosen: 1
Number: 35 Chosen: 2
Number: 36 Chosen: 0
Number: 37 Chosen: 0
Number: 38 Chosen: 1
Number: 39 Chosen: 0
Number: 40 Chosen: 0
Number: 41 Chosen: 0
Number: 42 Chosen: 0
Number: 43 Chosen: 1
Number: 44 Chosen: 1
Number: 45 Chosen: 1
Number: 46 Chosen: 2
Number: 47 Chosen: 2
Number: 48 Chosen: 0
Number: 49 Chosen: 1
Number: 50 Chosen: 3
Number: 51 Chosen: 2
Number: 52 Chosen: 0
Number: 53 Chosen: 0
Number: 54 Chosen: 2
Number: 55 Chosen: 0
Number: 56 Chosen: 0
Number: 57 Chosen: 3
Number: 58 Chosen: 2
Number: 59 Chosen: 0
Number: 60 Chosen: 3
Number: 61 Chosen: 0
Number: 62 Chosen: 0
Number: 63 Chosen: 1
Number: 64 Chosen: 0
Number: 65 Chosen: 0
Number: 66 Chosen: 0
Number: 67 Chosen: 2
Number: 68 Chosen: 0
Number: 69 Chosen: 1
Number: 70 Chosen: 1
Number: 71 Chosen: 0
Number: 72 Chosen: 1
Number: 73 Chosen: 0
Number: 74 Chosen: 2
Number: 75 Chosen: 2
Number: 76 Chosen: 1
Number: 77 Chosen: 0
Number: 78 Chosen: 0
Number: 79 Chosen: 1
Number: 80 Chosen: 0
Number: 81 Chosen: 0
Number: 82 Chosen: 2
Number: 83 Chosen: 0
Number: 84 Chosen: 1
Number: 85 Chosen: 0
Number: 86 Chosen: 0
Number: 87 Chosen: 2
Number: 88 Chosen: 1
Number: 89 Chosen: 0
Number: 90 Chosen: 0
Number: 91 Chosen: 4
Number: 92 Chosen: 1
Number: 93 Chosen: 3
Number: 94 Chosen: 0
Number: 95 Chosen: 1
Number: 96 Chosen: 3
Number: 97 Chosen: 2
Number: 98 Chosen: 0
Number: 99 Chosen: 4
Reply
#6

How exactly is that distribution terrible? It's random and he wants it to be a random chance, not a reliable pattern.
Reply
#7

pottus i think u been smoking crack i see nothing wrong with it and for beginners certainly is not good to tell them to download plugin for simple and fully working function such as random()
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)