SA-MP Forums Archive
How do I make a random number, on my /gamble command - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: How do I make a random number, on my /gamble command (/showthread.php?tid=464007)



How do I make a random number, on my /gamble command - ExtendedCarbon - 14.09.2013

I want to make a gamble command that chooses a number between 1 and 3 and if it lands on 2 it will give the player 50 dollars, if it it lands on something else it will tell him he lost.

I have this code but it doesn't work.
Code:
CMD:gamble(playerid, params[])
{
    new rand = random(1 - 3);
	new string[64];
    GivePlayerMoney(playerid, -10);
    if(rand == 2)
    {
        SendClientMessage(playerid, COLOR_YELLOW, "Your number landed on 3, and you won 50 dollars!");
    }
    else
    {
		format(string,sizeof(string),"Your number is %d",rand);
		SendClientMessage(playerid, COLOR_RED, string);
    }
    return 1;
}



Re: How do I make a random number, on my /gamble command - ThePhenix - 14.09.2013

It should work:
PHP Code:
CMD:gamble(playeridparams[])
{
    new 
rand random(3);//It's 3 no 1 - 3
    
new string[64];
    
    if(
rand == 2)
    {
        
SendClientMessage(playeridCOLOR_YELLOW"Your number landed on 3, and you won 50 dollars!");
        
GivePlayerMoney(playerid50);
    }
    else
    {
        
format(string,sizeof(string),"Your number is %d",rand);
        
SendClientMessage(playeridCOLOR_REDstring);
        
GivePlayerMoney(playerid, -10);
    }
    return 
1;