SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 23/11/2017, 12:31 PM   #1
rakinz
Little Clucker
 
Join Date: Oct 2016
Posts: 39
Reputation: 0
Question Admins Dialog

Code:
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?
rakinz is offline   Reply With Quote
Old 23/11/2017, 12:58 PM   #2
BiosMarcel
High-roller
 
BiosMarcel's Avatar
 
Join Date: Jul 2012
Location: Germany
Posts: 1,231
Reputation: 201
Default Re: Admins Dialog

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
BiosMarcel is offline   Reply With Quote
Old 23/11/2017, 01:16 PM   #3
rakinz
Little Clucker
 
Join Date: Oct 2016
Posts: 39
Reputation: 0
Default Re: Admins Dialog

Quote:
Originally Posted by BiosMarcel View Post
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?
rakinz is offline   Reply With Quote
Old 23/11/2017, 03:18 PM   #4
jasperschellekens
Big Clucker
 
Join Date: Dec 2016
Posts: 189
Reputation: 12
Default Re: Admins Dialog

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

Code:
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;
}
jasperschellekens is offline   Reply With Quote
Old 23/11/2017, 03:28 PM   #5
billy1337samp
Banned
 
Join Date: Jun 2016
Posts: 53
Reputation: 9
Default Re: Admins Dialog

PHP Code:
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.
billy1337samp is offline   Reply With Quote
Old 23/11/2017, 07:08 PM   #6
thefirestate
Big Clucker
 
Join Date: Sep 2014
Location: Bulgaria
Posts: 174
Reputation: 10
Default Re: Admins Dialog

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:

Code:
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.
thefirestate is offline   Reply With Quote
Old 23/11/2017, 07:35 PM   #7
Lucases
Big Clucker
 
Join Date: Jul 2017
Posts: 175
Reputation: 6
Default Re: Admins Dialog

Use a loop to find online admins and use strcat
Lucases is offline   Reply With Quote
Old 23/11/2017, 09:23 PM   #8
rakinz
Little Clucker
 
Join Date: Oct 2016
Posts: 39
Reputation: 0
Red face Re: Admins Dialog

Quote:
Originally Posted by thefirestate View Post
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:

Code:
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
rakinz is offline   Reply With Quote
Old 23/11/2017, 09:33 PM   #9
CodeStyle175
Huge Clucker
 
CodeStyle175's Avatar
 
Join Date: Apr 2014
Posts: 225
Reputation: 12
Default Re: Admins Dialog

PHP Code:
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;

CodeStyle175 is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[Ajuda] Admins em Dialog /Admins GuiKommander Português/Portuguese 15 08/01/2017 05:35 PM
/admins in dialog Sh4d0w2 Scripting Help 1 01/12/2015 05:12 PM
[Pedido] /admins em dialog Baraka Português/Portuguese 4 21/06/2014 04:07 PM
Online admins dialog /admins help please. SilentSoul Scripting Help 8 28/08/2013 09:33 PM
/admins dialog Total online admins do help:( y@sin1 Scripting Help 10 14/01/2012 04:58 PM


All times are GMT. The time now is 12:24 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.