Random number wont display
#1

I'm trying to make a random thing
Код:
CMD:gamble(playerid, params[])
{
    new rand = random(1-5);
	new string[64];
	format(string,sizeof(string),"Your number is %i",rand);
    GivePlayerMoney(playerid, -10);
    if(rand == 3)
    {
        SendClientMessage(playerid, COLOR_YELLOW, "Your number landed on 3, and you won 50 dollars!");
    }
    else
    {
		SendClientMessage(playerid, COLOR_RED, string);
    }
    return 1;
}
But it shows up in game as "Your number is123124313412"
Reply
#2

I'm not too good with random numbers, but try this;

pawn Код:
format(string,sizeof(string),"Your number is %d",rand); // %d instead of %i
Reply
#3

pawn Код:
random(1-5)
1-5 won't end up being 1 THROUGH 5, it will end up being -4. Try doing this:

pawn Код:
random(5)
#e: Keep your shit to a single thread. https://sampforum.blast.hk/showthread.php?tid=464007
Reply
#4

Quote:
Originally Posted by ExtendedCarbon
Посмотреть сообщение
I'm trying to make a random thing
Код:
CMD:gamble(playerid, params[])
{
    new rand = random(1-5);
	new string[64];
	format(string,sizeof(string),"Your number is %i",rand);
    GivePlayerMoney(playerid, -10);
    if(rand == 3)
    {
        SendClientMessage(playerid, COLOR_YELLOW, "Your number landed on 3, and you won 50 dollars!");
    }
    else
    {
		SendClientMessage(playerid, COLOR_RED, string);
    }
    return 1;
}
But it shows up in game as "Your number is123124313412"
Try this:
Код:
CMD:gamble(playerid, params[])
{
    new rand = random(1-5);
	new string[64];
	format(string,sizeof(string),"Your number is %i",rand);
    GivePlayerMoney(playerid, -10);
    if(rand == 3)
    {
        SendClientMessage(playerid, COLOR_YELLOW, "Your number landed on 3, and you won 50 dollars!");
    }
    else
    {
		SendClientMessage(playerid, COLOR_RED, string);
                return 1;
    }
    return 1;
}
or other method like this:

Код:
CMD:gamble(playerid, params[])
{
    switch(random(5))
    {
        case 0:
        {
		SendClientMessage(playerid, COLOR_RED, "Your number is 1");
	}
        case 1:
        {
		SendClientMessage(playerid, COLOR_RED, "Your number is 2");
        }
	case 2:
	{
             SendClientMessage(playerid, COLOR_YELLOW, "Your number landed on 3, and you won 50 dollars!");
	}
	case 3:
	{
		SendClientMessage(playerid, COLOR_RED, "Your number is 4");
	}
	case 4:
	{
		SendClientMessage(playerid, COLOR_RED, "Your number is 5");
	}
    }
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)