SA-MP Forums Archive
Assigning a random number - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Server (https://sampforum.blast.hk/forumdisplay.php?fid=6)
+--- Forum: Server Support (https://sampforum.blast.hk/forumdisplay.php?fid=19)
+--- Thread: Assigning a random number (/showthread.php?tid=528926)



Assigning a random number - jackx3rx - 30.07.2014

How would I assign a random 5 digit number to targetid? Here is the code:

Код:
CMD:agivecellphone(playerid,params[])
{
    if(PlayerInfo[playerid][pAdmin] < 4) return SendClientMessage(playerid,-1,"{AA3333}ERROR:{FFFFFF} Only administrators may use this command.");
    {
        new targetid, string[128], string2[128];
        if(sscanf(params,"u",targetid)) return SendClientMessage(playerid,-1,"{AA3333}USAGE:{FFFFFF} /agivecellphone (id)");
        if(PlayerInfo[targetid][pCellNumber] > 0) return SendClientMessage(playerid,-1,"{AA3333}ERROR:{FFFFFF} Player already has a cellphone.");
        {
            // Assign a random 5 digit number to targetid, PlayerInfo[targetid][pCellNumber]
            format(string,128,"{AA3333}AdminCMD:{FFFFFF} You have given %s a cellphone.",RemoveUnderScore(targetid));
            SendClientMessage(playerid,-1,string);
            format(string2,128,"{AA3333}AdminCMD:{FFFFFF} You have been given a cellphone by an administrator.");
            SendClientMessage(targetid,-1,string2);
		}
	}
	return 1;
}



Re: Assigning a random number - coole210 - 30.07.2014

pawn Код:
#define randomEx(%0,%1) floatround(random((%1) - (%0)) + (%0))

PlayerInfo[targetid][pCellNumber] = randomEx(10000, 99999);