Admins Dialog
#1

Код:
CMD:admins(playerid, params[])
{
	new count = 0;
	for(new i = 0; i < MAX_PLAYERS; i++)
	{
		if(!IsPlayerConnected(i)) continue;
		if(!PlayerInfo[i][pAdmin]) continue;
		new string[90], playersname[MAX_PLAYER_NAME];
		GetPlayerName(i, playersname, sizeof(playersname));
		switch(PlayerInfo[i][pAdmin])
		{
			case 1: format(string, sizeof(string), "{FF9900}%s (ID:%i) - Level: %d | Junior Administrator |\n", playersname, i, PlayerInfo[i][pAdmin]);
			case 2: format(string, sizeof(string), "{FF9900}%s (ID:%i) - Level: %d | Senior Administrator |\n", playersname, i, PlayerInfo[i][pAdmin]);
			case 3: format(string, sizeof(string), "{FF9900}%s (ID:%i) - Level: %d | Advisor Administrator |\n", playersname, i, PlayerInfo[i][pAdmin]);
			case 4: format(string, sizeof(string), "{FF0000}%s (ID:%i) - Level: %d | Head Administrator |\n", playersname, i, PlayerInfo[i][pAdmin]);
			case 5: format(string, sizeof(string), "{1E90FF}%s (ID:%i) - Level: %d | Server Founder |\n", playersname, i, PlayerInfo[i][pAdmin]);
			default: continue;
		}
		ShowPlayerDialog(playerid, DIALOG_ONLINEADMINS, DIALOG_STYLE_MSGBOX,""COL_YELLOW"SEF :: "COL_WHITE"Online Administrators",string,"Okay","Cancel");
		count++;
	}
	if(!count) ShowPlayerDialog(playerid, DIALOG_NOONLINEADMINS, DIALOG_STYLE_MSGBOX,""COL_YELLOW"SEF :: "COL_WHITE"Online Administrators","There aren't any online admins.","Okay","Cancel");
	return 1;
}
How can I fix this code, and make it work for more then one player?
Reply
#2

If you ask like this i doubt anyone will help, also, i hope no one will.

People like you gotta learn how to ask questions:

1. What is the problem
2. Your code
3. What have you tried
4. Have you already tried generalizing your case trying it with an MCVE
Reply
#3

Quote:
Originally Posted by BiosMarcel
Посмотреть сообщение
If you ask like this i doubt anyone will help, also, i hope no one will.

People like you gotta learn how to ask questions:

1. What is the problem
2. Your code
3. What have you tried
4. Have you already tried generalizing your case trying it with an MCVE
1. When I use the command ingame the dialog can show only one 'case' and it's the fifth one.
2. I've showed the code, there are no problems with compiling it.
3. I've made it with clientmessages before, but now I would like to learn how to make it with dialogs.
4. What is MCVE?
Reply
#4

I don't know how your admin system works you might have to change it a little.

Код:
CMD:admins(playerid,params[])
{
	new count=0;
 	new string[128],name[50];
	for(new i=0; i < MAX_PLAYERS; i++)
	if(IsPlayerConnected(i))
 	{
  		if(PlayerInfo[i][pAdmin] > 0)
   		{
	    	if(PlayerInfo[i][pAdmin]==1){name="Junior Administrator";}
    		if(PlayerInfo[i][pAdmin]==2){name="Senior Administrator";}
			if(PlayerInfo[i][pAdmin]==3){name="Advisor Administrator";}
			if(PlayerInfo[i][pAdmin]==4){name="Head Administrator";}
			if(PlayerInfo[i][pAdmin]==5){name="Server Founder";}
			format(string,128,"%s - %s",playersname,name);
   			ShowPlayerDialog(playerid, DIALOG_ONLINEADMINS, DIALOG_STYLE_MSGBOX,""COL_YELLOW"SEF :: "COL_WHITE"Online Administrators",string,"Okay","Cancel");
			count++;
		}
 	}
 	else
 	{
 	    ShowPlayerDialog(playerid, DIALOG_NOONLINEADMINS, DIALOG_STYLE_MSGBOX,""COL_YELLOW"SEF :: "COL_WHITE"Online Administrators","There aren't any online admins.","Okay","Cancel");
 	}
	return 1;
}
Reply
#5

PHP код:
CMD:admins(playerid,params[])
{
    new 
d_header[50], d_content[144], d_count 0d_name[MAX_PLAYER_NAME 1]; //d_ = dialog
    
for(new 0GetPlayerPoolSize(); i<=ji++)
{
    if(
PlayerInfo[i][pAdmin])
 {
        
GetPlayerName(id_namesizeof(d_name));
        
format(d_contentsizeof(d_content), "%s%s [%d]\n"d_contentd_namei);
        
d_count++;
   }
}
    if(
d_count == 0)
        
ShowPlayerDialog(playerid1DIALOG_STYLE_LIST"[notice]""There are no online admins at the moment!""Close""");
    else
    {
        
format(d_headersizeof(d_header), "[admins] - {FFFF00}%d {FFFFFF}admin(s)"d_count);
        
ShowPlayerDialog(playerid1DIALOG_STYLE_LISTd_headerd_content"Close""");
    }
    return 
1;

how i'd do it. not exactly what you wanted.
Reply
#6

Right, apparently no-one is going to show you how to properly do it so, first things first! When you format your string you are formatting it for every administrator yet it overwrites the previous one meaning that if you have 5 admins online with the id of 1,5,7,20 and 35 you'd show dialog that only id 35 is currently online as an administrator. The thing you are looking for is a separate string let's say the default one is "string" the one with all admins will be "stringcomplete" and you're going to insert the new admin into the stringcomplete while keeping the record of the old one, usually this is a good enough explanation but I am going to present you a code and while I don't like coding for people because I think this slows down their brain work and doesn't make them learn more, this time I feel like visual code would help you more so here it is:

Код:
CMD:admins(playerid, params[])
{
	new count = 0, stringcomplete[1500]; //the reason stringcomplete is 1500 is because if you have more admins you might run out of space so with 1500 you definitely won't any time soon.
	for(new i = 0; i < GetPlayerPoolSize(); i++) //MAX_PLAYERS is bad habit, either use foreach include or loop via 0.3.7 native GetPlayerPoolSize()
	{
		if(!IsPlayerConnected(i)) continue;
		if(!PlayerInfo[i][pAdmin]) continue;
		new string[90], playersname[MAX_PLAYER_NAME];
		GetPlayerName(i, playersname, sizeof(playersname));
		switch(PlayerInfo[i][pAdmin])
		{
			case 1: format(string, sizeof(string), "{FF9900}%s (ID:%i) - Level: %d | Junior Administrator |\n", playersname, i, PlayerInfo[i][pAdmin]);
			case 2: format(string, sizeof(string), "{FF9900}%s (ID:%i) - Level: %d | Senior Administrator |\n", playersname, i, PlayerInfo[i][pAdmin]);
			case 3: format(string, sizeof(string), "{FF9900}%s (ID:%i) - Level: %d | Advisor Administrator |\n", playersname, i, PlayerInfo[i][pAdmin]);
			case 4: format(string, sizeof(string), "{FF0000}%s (ID:%i) - Level: %d | Head Administrator |\n", playersname, i, PlayerInfo[i][pAdmin]);
			case 5: format(string, sizeof(string), "{1E90FF}%s (ID:%i) - Level: %d | Server Founder |\n", playersname, i, PlayerInfo[i][pAdmin]);
			default: continue;
		}
		count++;
                format(stringcomplete, sizeof(stringcomplete), "%s%s", stringcomplete, string); //method 1 with format
                strcat(stringcomplete, string); //method 2 with strcat, use the one you feel like, I don't know which one performs better but they both should do the same job.
	}
        if(count > 0) ShowPlayerDialog(playerid, DIALOG_ONLINEADMINS, DIALOG_STYLE_MSGBOX,""COL_YELLOW"SEF :: "COL_WHITE"Online Administrators",stringcomplete,"Okay","Cancel"); //You can feel free to showplayerdialog once the whole loop is done not for every single player you loop through.
	if(count == 0) ShowPlayerDialog(playerid, DIALOG_NOONLINEADMINS, DIALOG_STYLE_MSGBOX,""COL_YELLOW"SEF :: "COL_WHITE"Online Administrators","There aren't any online admins.","Okay","Cancel");
	return 1;
}
There might be some warning with spaces or typos I haven't tested it, I just wrote it on the run in the reply tab without trying it in pawn.
Reply
#7

Use a loop to find online admins and use strcat
Reply
#8

Quote:
Originally Posted by thefirestate
Посмотреть сообщение
Right, apparently no-one is going to show you how to properly do it so, first things first! When you format your string you are formatting it for every administrator yet it overwrites the previous one meaning that if you have 5 admins online with the id of 1,5,7,20 and 35 you'd show dialog that only id 35 is currently online as an administrator. The thing you are looking for is a separate string let's say the default one is "string" the one with all admins will be "stringcomplete" and you're going to insert the new admin into the stringcomplete while keeping the record of the old one, usually this is a good enough explanation but I am going to present you a code and while I don't like coding for people because I think this slows down their brain work and doesn't make them learn more, this time I feel like visual code would help you more so here it is:

Код:
CMD:admins(playerid, params[])
{
	new count = 0, stringcomplete[1500]; //the reason stringcomplete is 1500 is because if you have more admins you might run out of space so with 1500 you definitely won't any time soon.
	for(new i = 0; i < GetPlayerPoolSize(); i++) //MAX_PLAYERS is bad habit, either use foreach include or loop via 0.3.7 native GetPlayerPoolSize()
	{
		if(!IsPlayerConnected(i)) continue;
		if(!PlayerInfo[i][pAdmin]) continue;
		new string[90], playersname[MAX_PLAYER_NAME];
		GetPlayerName(i, playersname, sizeof(playersname));
		switch(PlayerInfo[i][pAdmin])
		{
			case 1: format(string, sizeof(string), "{FF9900}%s (ID:%i) - Level: %d | Junior Administrator |\n", playersname, i, PlayerInfo[i][pAdmin]);
			case 2: format(string, sizeof(string), "{FF9900}%s (ID:%i) - Level: %d | Senior Administrator |\n", playersname, i, PlayerInfo[i][pAdmin]);
			case 3: format(string, sizeof(string), "{FF9900}%s (ID:%i) - Level: %d | Advisor Administrator |\n", playersname, i, PlayerInfo[i][pAdmin]);
			case 4: format(string, sizeof(string), "{FF0000}%s (ID:%i) - Level: %d | Head Administrator |\n", playersname, i, PlayerInfo[i][pAdmin]);
			case 5: format(string, sizeof(string), "{1E90FF}%s (ID:%i) - Level: %d | Server Founder |\n", playersname, i, PlayerInfo[i][pAdmin]);
			default: continue;
		}
		count++;
                format(stringcomplete, sizeof(stringcomplete), "%s%s", stringcomplete, string); //method 1 with format
                strcat(stringcomplete, string); //method 2 with strcat, use the one you feel like, I don't know which one performs better but they both should do the same job.
	}
        if(count > 0) ShowPlayerDialog(playerid, DIALOG_ONLINEADMINS, DIALOG_STYLE_MSGBOX,""COL_YELLOW"SEF :: "COL_WHITE"Online Administrators",stringcomplete,"Okay","Cancel"); //You can feel free to showplayerdialog once the whole loop is done not for every single player you loop through.
	if(count == 0) ShowPlayerDialog(playerid, DIALOG_NOONLINEADMINS, DIALOG_STYLE_MSGBOX,""COL_YELLOW"SEF :: "COL_WHITE"Online Administrators","There aren't any online admins.","Okay","Cancel");
	return 1;
}
There might be some warning with spaces or typos I haven't tested it, I just wrote it on the run in the reply tab without trying it in pawn.
This one very helped me, thanks a lot bro!!! really appreciate that. +rep
Reply
#9

PHP код:
gname(pid){
    new 
s[24];
    
GetPlayerName(pid,s,24);
    return 
s;
}
CMD:admins(pid){
    new 
s[1000],arrRanks[][]={"Junior Administrator","Senior Administrator","Advisor Administrator","Head Administrator","Server Founder"};
    foreach(
Player,i)if(PlayerInfo[i][pAdmin])format(s,sizeof(s),"%s{FF9900}%s (ID:%i) - Level: %d | %s |\n",s,gname(i),i,PlayerInfo[i][pAdmin],arrRanks[PlayerInfo[i][pAdmin]-1];
    
ShowPlayerDialog(playeridDIALOG_ONLINEADMINSDIALOG_STYLE_MSGBOX""COL_YELLOW"SEF :: "COL_WHITE"Online Administrators",
    
strlen(s)?s:("There aren't any online admins."),
    
"Okay","Cancel");
    return 
1;

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)