SA-MP Forums Archive
giving names to values - 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: giving names to values (/showthread.php?tid=636332)



giving names to values - MrCesar - 25.06.2017

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!


Re: giving names to values - Vince - 25.06.2017

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.


Re: giving names to values - SyS - 25.06.2017

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.


Re: giving names to values - Whatname - 25.06.2017

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;




Re: giving names to values - MrCesar - 25.06.2017

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


Re: giving names to values - Whatname - 25.06.2017

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


Re: giving names to values - MrCesar - 25.06.2017

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


Re: giving names to values - UnlikePluto - 25.06.2017

Код:
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;
}