SA-MP Forums Archive
Random problem :( - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Random problem :( (/showthread.php?tid=196915)



Random problem :( - i3Cookies - 07.12.2010

Hi.. recently i have created a liiiitlle script and dont work
Код:
    if (strcmp("/random", cmdtext, true, 6) == 0)
    {
	            if(IsPlayerConnected(playerid))
	            {
	            new rand = random(3)+1;
	            GetPlayerName(playerid, sendername, sizeof(sendername));
			    new random[MAX_PLAYERS];
   			    if(rand == 3)
	            {
				random = "happy";
				random = "very happy";
				random = "lucky";
				}
				else
				{
				random = "sad";
				}
			    format(string, sizeof(string), "A player is  %s", random);
			    ProxDetector(10.0, playerid, string, COLOR_PINK,COLOR_PINK,COLOR_PINK,COLOR_PINK,COLOR_PINK);
		        }
     return 1;
     }
The problem is..
When i type /random the script show me only: A player is LUCKY
or
A player is sad
(
how can i solve this problem?


Re: Random problem :( - Mehtab - 07.12.2010

what do you actual want


Re: Random problem :( - i3Cookies - 07.12.2010

i want , when you type /random, the script select one of
Код:
happy, lucky, very happy or sad



Re: Random problem :( - Mehtab - 07.12.2010

change this code to yours



Код:
new gla;
gla=random(10); // Type here the number of messages you have.
switch(gla)
{
case 0: SendClientMessage(playerid, 0xFFFFFFFF, "This is the first message");
case 1: SendClientMessage(playerid, 0xFFFFFFFF, "This is the sencond message");
case 2: SendClientMessage(playerid, 0xFFFFFFFF, "This is the third message");
//....
}



Re: Random problem :( - Celson - 07.12.2010

You're creating an array with 500 cells, but only up to a maximum of 10 of those cells will actually be used. Wouldn't it just be a better idea to make it..

pawn Код:
new random[10];
Infact you shouldn't even call it 'random', since it's sharing the name with a function.


Re: Random problem :( - nutzkung69 - 07.12.2010

pawn Код:
if (strcmp("/random", cmdtext, true, 6) == 0)
{
    if(IsPlayerConnected(playerid))
    {
        new rand = random(3)+1;
        GetPlayerName(playerid, sendername, sizeof(sendername));
        new random[MAX_PLAYERS];
        if(rand == 1)
        {
            random = "happy";
        }
        if(rand == 2)
        {
            random = "very happy";
        }
        if(rand == 3)
        {
            random = "lucky";
        }
        else
        {
            random = "sad";
        }
        format(string, sizeof(string), "A player is  %s", random);
        ProxDetector(10.0, playerid, string, COLOR_PINK,COLOR_PINK,COLOR_PINK,COLOR_PINK,COLOR_PINK);
    }
    return 1;
}



Re: Random problem :( - Voldemort - 07.12.2010

pawn Код:
if (strcmp("/random", cmdtext, true, 6) == 0)
{
    if(IsPlayerConnected(playerid))
    {
        new rand = random(4);
        new emo[12];
        if(rand == 0) { emo = "happy"; }
        else if(rand == 1) { emo = "very happy"; }
        else if(rand == 2) { emo = "lucky"; }
        else { emo = "sad"; }
        format(string, sizeof(string), "A player is  %s", emo);
        ProxDetector(10.0, playerid, string, COLOR_PINK,COLOR_PINK,COLOR_PINK,COLOR_PINK,COLOR_PINK);
    }
    return 1;
}