Question - How to make random based on percentage
#1

How to make random function by percentage ( i mean chance)
if i have a command like: /random , the change to show up the message "Winner" is 1%
Reply
#2

Pretty basic.

pawn Код:
new rand = random(3);
switch(rand)
{
    case 0:
    {
       SendClientMessage(playerid, -1, "You are a winner!");
    }
    case 1:
    {
        SendClientMessage(playerid, -1, "You are a loser!");
    }
    case 2:
    {
        SendClientMessage(playerid, -1, "You are a loser!");
    }
You can change the value of random times that you desire by changing "new rand = random(3);" to maybe 4 or 5 and then put new cases at the bottom.
Reply
#3

I asked how to add percentage to random function.
I have a cmd named /getprize and i want to make the cases with percentage cuz i put some really really big prizes and for example the nrg can be won at a percentage of 1%.
That is what i am needing.
Reply
#4

And that's exactly what I showed you up there, unless you want me to make a '/getprize' command for you entirely, in which I won't do.

You can however seek for such a request here; https://sampforum.blast.hk/showthread.php?tid=447813.
Reply
#5

https://sampforum.blast.hk/showthread.php?tid=388165
Something like this. Read the full topic.
Reply
#6

Then you just change his code a little bit?
pawn Код:
new rand = random(100);
switch(rand)
{
    case 1:
    {
       SendClientMessage(playerid, -1, "You are a winner!");
    }
    default:
    {
        SendClientMessage(playerid, -1, "You are a loser!");
    }
}
Reply
#7

For example:
New randprize = random(3);
Switch(random)
{
Case: 0
{
SCM..."You won a NRG"
}
Case 1:
{
SCM..."You won 500$"
}
Case 2:
{
SCM..."You won 300$"
}
How to make case 0 to be hard to win.
Reply
#8

//EDIT: oliverrud posted the correct solution already, didnt see it >.<
the correct way to do it.

1% chance to win, if it's 99 (100-1, cuz max of random is value-1) you'll win
pawn Код:
new rand = random(100);
switch(rand)
{
    case 0..98://simply means >= 0 and  <=98
    {
       SendClientMessage(playerid, -1, "You are a loser!");
    }
    default://the rest (99)
    {
        SendClientMessage(playerid, -1, "You are a winner!");
    }
}
Reply
#9

Quote:
Originally Posted by buburuzu19
Посмотреть сообщение
For example:
New randprize = random(3);
Switch(random)
{
Case: 0
{
SCM..."You won a NRG"
}
Case 1:
{
SCM..."You won 500$"
}
Case 2:
{
SCM..."You won 300$"
}
How to make case 0 to be hard to win.
Simple solution off the top of my head would be something like this:
pawn Код:
New randprize = random(100);
Switch(random)
{
 Case: 0:
 {
     SCM..."You won a NRG"
}
Case 1..15:
{
 SCM..."You won 500$"
}
Case 16..40:
{
  SCM..."You won 300$"
}
default:{
//yalost
}
Reply
#10

And how to do if i have 2 prizes rare to win?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)