Compare Switch(random))
#1

Hey everyone,

Is it possible to compare a random number this is drawn with switch. To a number a player types in a params?

For instance


If I had

Код:
CMD:Ticket (playerid, params[]) {

                 new string[128], number;
			
	        if(sscanf(params, "d", number))
And say they said "/ticket 23"


I then want to do a random switch like


Код:
Switch(random(100))

case 1: 
 {
   if    ------Checks to make sure the can pay for a ticket
    {

        If there number matches 1 here
    }
  else
Tell them what number HERE
}
return 1;
}
Case 2:
and so on......

Is this possible?
Reply
#2

Yes you can.
Reply
#3

Thank you, Now can you tell me how?
Reply
#4

pawn Код:
random(100) // Starts from 0 to 99
case 0:
{

}
case 1:
{

}
case 2:
{

}
case 3..60:
{

}
case 61..98: // from 61 to 98
{

}
default: //else
{

}
Reply
#5

But How do I make it look to see if it matches the number they typed in after /ticket NUMBER


I know how to make cases.....
Reply
#6

Pretty much like you did, you just did a few mistakes in using a switch, this is how you should use it:
pawn Код:
switch(random(3))
{
    case 0:
    case 1:
    case 2:
    case 3:
}
Reply
#7

You mean

pawn Код:
switch(params)
{
    case 23:
    {

    }
}
Reply
#8

Ok,

Guys, I know how to do a case..

What I am asking is... if the player does /ticket NUMBER

How do I compare the NUMBER they typed.... to a certain case.

so if they picked 23, and the random number 23 came up.. How to tell they were right?
Reply
#9

You can check with an "if" for that.
pawn Код:
switch(random(100))
{
    case 23: if(number == 23) // Code
}
Reply
#10

Quote:
Originally Posted by CalvinC
Посмотреть сообщение
You can check with an "if" for that.
pawn Код:
switch(random(100))
{
    case 23: if(number == 23) // Code
}
Ok so,

if(number == 23) // Code

Would the word number be my params for CMD:ticket?


so it checks to see if the params of CMD ticket == the case?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)