0 or 1.
#1

Well, yesterday I was scripting a command which when sometimes a player type /attempt it'll appear success and sometimes it'll appear fails, but I've faced a problem it only says 'Failed' I've set the random between 0 and 1 if its 1 = success 0 = fail, but as I said it only appear 'failed' can anyone help me with this? or tell me the right function?


Код:
if(strcmp(cmd, "/attempt", true) == 0)
	{
	    if(IsPlayerConnected(playerid))
	    {
	        if(gPlayerLogged[playerid] == 0)
	        {
	            SendClientMessage(playerid, COLOR_GREY, "[INFO]:You havent logged in yet !");
	            return 1;
	        }
			GetPlayerNameEx(playerid, sendername, sizeof(sendername));
			new length = strlen(cmdtext);
			while ((idx < length) && (cmdtext[idx] <= ' '))
			{
				idx++;
			}
			new offset = idx;
			new result[96];
			while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
			{
				result[idx - offset] = cmdtext[idx];
				idx++;
			}
			result[idx - offset] = EOS;
			if(!strlen(result))
			{
				SendClientMessage(playerid, COLOR_WHITE, "USAGE: /attempt [action]");
				return 1;
			}
			if(PlayerInfo[playerid][pMask] == 1)
			{
				new rn = random(1);
				if (rn == 0) // failed
				{
			    	format(string, sizeof(string), "* Stranger tried to %s and failed.", result);
			    }
			    else // succeded
			    {
			        format(string, sizeof(string), "* Stranger tried to %s and succeeded.", result);
			    }
			}
			else
			{
			    new rn = random(1);
			    if (rn == 0) // failed
			    {
					format(string, sizeof(string), "* %s tried to %s and failed.", sendername, result);
				}
				else // succeded
				{
				    format(string, sizeof(string), "* %s tried to %s and succeeded.", sendername, result);
				}
			}
			ProxDetector(30.0, playerid, string, COLOR_LIGHTBLUE,COLOR_LIGHTBLUE,COLOR_LIGHTBLUE,COLOR_LIGHTBLUE,COLOR_LIGHTBLUE);
		}
		return 1;
	}
Thank you very much!
Reply
#2

Quote:

(from 0 to this value minus one)

So try and use 2 instead of 1 at the "new rn = random(1);"
Reply
#3

Alright thanks. Imma try that.
Reply
#4

Try something like this?
pawn Код:
switch(random(500))
{
    case 0..250: // failed
    default: // success
}
Also consider using zcmd.
Reply
#5

if(IsPlayerConnected(playerid)) no need for this.
Reply
#6

------
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)