the random() function: HELP PLEASE?
#1

Hey, erm... this code doesn't work properly

pawn Код:
CMD:football(playerid, params[])
{
    new rand = random(3);
    if( rand == 1)
    {
        SCM(playerid, -1, "You got beat 1-0");
        GivePlayerMoney(playerid, 50000);
    }
    if( rand == 2)
    {
        SCM(playerid, -1, "You won 3-2");
        GivePlayerMoney(playerid, 50000);
    }
    if( rand == 3)
    {
        SCM(playerid, -1, "You drew 3-3");
        GivePlayerMoney(playerid, 1000);
    }
    return 1;
}
Reply
#2

pawn Код:
if( rand == 1)
    {
        SCM(playerid, 0xFFFFFFAA , "You got beat 1-0");
        GivePlayerMoney(playerid, 50000);
    }
    if( rand == 2)
    {
        SCM(playerid, 0xFFFFFFAA ,"You won 3-2");
        GivePlayerMoney(playerid, 50000);
    }
    if( rand == 3)
    {
        SCM(playerid, 0xFFFFFFAA , "You drew 3-3");
        GivePlayerMoney(playerid, 1000);
    }
oh and i think the script is bad look , if you want to give a player - money just add this - sign near your GivePlayerMoney,
Example: GivePlayerMoney(playerid, -5000); and it will give him -5000$
Reply
#3

Above -.-
Reply
#4

I used switch(random(3)) instead... but thanks anyways
Reply
#5

Quote:

A random number ranging from 0 to max-1.

but in your code there is no if(rand == 0)
Reply
#6

pawn Код:
CMD:football(playerid, params[])
{
    new rand = random(3);
    if( rand == 0)
    {
        SCM(playerid, -1, "You got beat 1-0");
        GivePlayerMoney(playerid, 50000);
    }
    if( rand == 1)
    {
        SCM(playerid, -1, "You won 3-2");
        GivePlayerMoney(playerid, 50000);
    }
    if( rand == 2)
    {
        SCM(playerid, -1, "You drew 3-3");
        GivePlayerMoney(playerid, 1000);
    }
    return 1;
}
Reply
#7

Try like this

Код:
CMD:football(playerid,params[])
{
      new
      ball = random(3);
      switch(ball)
      {
           case 0: // CASE 1
           {

           }
           case 1: // CASE 1
           {

	  }           
           case 2: // CASE 3
           {

	  }
     }
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)