giving names to values
#1

hey guys, i've made a simple /makeadmin cmd that looks like that:
Код:
CMD:makeadmin(playerid, params[])
{
	if(IsPlayerAdmin(playerid))
	{
	    new id, level, string[126];
		if(sscanf(params, "ud", id, level)) return SendClientMessage(playerid, COL_SYSTEM, "* Syntax: /makeadmin "COLOR_ORANGE"[TargetID] [Level 1-1336]"COLOR_SYSTEM" *");
		PlayerInfo[id][pAdmin] = level;
		format (string, sizeof(string), "* System: "COLOR_ORANGE"[Administrator] - %s"COLOR_SYSTEM" has set your admin level to "COLOR_ORANGE"%d"COLOR_SYSTEM". *", GetNameEx(playerid), level);
	    SendClientMessage(id, COL_SYSTEM, string);
	    format (string, sizeof(string), "* System: You have set "COLOR_ORANGE"%s's"COLOR_SYSTEM" admin level to "COLOR_ORANGE"%d"COLOR_SYSTEM". *", GetNameEx(id), level);
	    SendClientMessage(playerid, COL_SYSTEM, string);
	}
	else
	{
	    SendClientMessage(playerid, COL_SYSTEM, "* System: You are "COLOR_LIGHTRED"not allowed"COLOR_SYSTEM" to use this command! *");
	}
	return 1;
}
my question is how can i make the levels which appear as %d to appear as names aka junior admin senior admin etc..? thanks in advance!
Reply
#2

Use an array or a switch. Also perhaps this is just me, but I think admin levels like 1337 or 9999 are super retarded. You need at most 5 or so.
Reply
#3

You can either do a conditional checking based on level variable and initialize a string according to it and display it. Or you can have constant global or static array of strings having nominal meaning of each level so as to use these level variable as indices to access this array contents.
Reply
#4

PHP код:
static const LVLNames[][] = 
{
      
"junior""junior""name for level 2""name for level 3",
};
cmd:level(playeridparams[])
{
     new 
str[20];
     
format(strsizeof(str), "You are: %s"LVLNames[playerlevel]);
     
SendClientMessage(playerid,  -1str); //levels 0-1 junior rest you decide.
     
return 1;

Reply
#5

Quote:
Originally Posted by Vince
Посмотреть сообщение
Use an array or a switch. Also perhaps this is just me, but I think admin levels like 1337 or 9999 are super retarded. You need at most 5 or so.
Quote:
Originally Posted by SyS
Посмотреть сообщение
You can either do a conditional checking based on level variable and initialize a string according to it and display it. Or you can have constant global or static array of strings having nominal meaning of each level so as to use these level variable as indices to access this array contents.
I am not really familiar with those..can you make a small example for me please? :O
Reply
#6

Quote:
Originally Posted by MrCesar
Посмотреть сообщение
I am not really familiar with those..can you make a small example for me please? :O
i sent the code of what they meant
Reply
#7

Quote:
Originally Posted by Whatname
Посмотреть сообщение
i sent the code of what they meant
yeah but what's /level for? i mean the message to say like you've been promoted/demoted to junior/senior admin etc..

I didn't fully understand your code maybe
Reply
#8

Код:
stock ReturnAdminRank(rankid)
{
	new string[20];
	
	switch(rankid){
		case 1: string = "Game Admin I";
		case 2: string = "Game Admin II";
		case 3: string = "Game Admin III";
		case 4: string = "Lead Admin I";
		case 5: string = "Lead Admin II";
		case 6: string = "Co-Owner";
		case 7: string = "Owner";
	}
	return string;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)