SA-MP Forums Archive
0 or 1. - 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: 0 or 1. (/showthread.php?tid=437632)



0 or 1. - Beckett - 16.05.2013

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!


Re: 0 or 1. - Yuup - 16.05.2013

Quote:

(from 0 to this value minus one)

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


Re: 0 or 1. - Beckett - 16.05.2013

Alright thanks. Imma try that.


Re: 0 or 1. - Djole1337 - 16.05.2013

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


Re: 0 or 1. - Pottus - 16.05.2013

if(IsPlayerConnected(playerid)) no need for this.


Re: 0 or 1. - Beckett - 16.05.2013

------