Create command /admins in dialog
#1

Hi I'm making a command to see the online admins on the server , this is the code

Код:
CMD:admins(){
    new string[256];
    new fstring[64];
    for(new i=0; i<MAX_PLAYERS; i++)
    {
        if(Admin[playerid]>= 0)
        {
            GetPlayerName(i,adminname, sizeof(adminname));
            format(fstring, sizeof(fstring),"%s (%i) - {FF0000}Level: %i{FFFFFF}\n", adminname, i,Admin[playerid]);
            strcat(string, fstring, sizeof(string));
        }
    }
    ShowPlayerDialog(playerid,1,DIALOG_STYLE_MSGBOX,"Online Admins",string,"OK","");
    return 1;
}

Then to try it in the server gives me so






What I want is when the player put / admins, you show admins who are connected as in the picture below



Thank you for your attention and your help
Reply
#2

Quote:
Originally Posted by Z4firo
Посмотреть сообщение
Hi I'm making a command to see the online admins on the server , this is the code

Код:
CMD:admins(playerid){
    new string[256];
    new fstring[64];
    for(new i=0; i<MAX_PLAYERS; i++)
    {
        if(Admin[playerid]>= 0)
        {
            GetPlayerName(i,adminname, sizeof(adminname));
            format(fstring, sizeof(fstring),"%s (%i) - {FF0000}Level: %i{FFFFFF}\n", adminname, i,Admin[playerid]);
            strcat(string, fstring, sizeof(string));
        }
    }
    ShowPlayerDialog(playerid,1,DIALOG_STYLE_MSGBOX,"Online Admins",string,"OK","");
    return 1;
}
You are checking Admin[playerid], and you must check if the player connected also
also, you do (Admin[i] >= 0), also non admins will be formatted here is the right code
increase string size a little bit more
PHP код:
CMD:admins(playerid){
    new 
string[300];
    new 
fstring[64];
    for(new 
i=0; i<MAX_PLAYERS; i++)
    {
        if(
Admin[i] > 0 && IsPlayerConnected(i))
        {
            
GetPlayerName(i,adminname, sizeof(adminname));
            
format(fstring, sizeof(fstring),"%s (%i) - {FF0000}Level: %i{FFFFFF}\n", adminname, i,Admin[i]);
            
strcat(string, fstring, sizeof(string));
        }
    }
    
ShowPlayerDialog(playerid,1,DIALOG_STYLE_MSGBOX,"Online Admins",string,"OK","");
    return 
1;
} 
Reply
#3

Keep the first one. The second one is a bit messy.
Reply
#4

Quote:
Originally Posted by Shinja
Посмотреть сообщение
You are checking Admin[playerid], and you must check if the player connected also
also, you do (Admin[i] >= 0), also non admins will be formatted here is the right code
increase string size a little bit more
PHP код:
CMD:admins(playerid){
    new 
string[300];
    new 
fstring[64];
    for(new 
i=0; i<MAX_PLAYERS; i++)
    {
        if(
Admin[i] > 0 && IsPlayerConnected(i))
        {
            
GetPlayerName(i,adminname, sizeof(adminname));
            
format(fstring, sizeof(fstring),"%s (%i) - {FF0000}Level: %i{FFFFFF}\n", adminname, i,Admin[i]);
            
strcat(string, fstring, sizeof(string));
        }
    }
    
ShowPlayerDialog(playerid,1,DIALOG_STYLE_MSGBOX,"Online Admins",string,"OK","");
    return 
1;
} 
I put the code but when you try it on the server I get: unknown command
Reply
#5

Strange.. Try this
PHP код:
CMD:admins(){
    new 
string[300], fstring[64], adminname[25];
    for(new 
i=0; i<MAX_PLAYERS; i++)
    {
        if(
Admin[i] > 0 && IsPlayerConnected(i))
        {
            
GetPlayerName(i,adminname, sizeof(adminname));
            
format(fstring, sizeof(fstring),"%s (%i) - {FF0000}Level: %i{FFFFFF}\n", adminname, i,Admin[i]);
            
strcat(string, fstring, sizeof(string));
        }
    }
    
ShowPlayerDialog(playerid,1,DIALOG_STYLE_MSGBOX,"Online Admins",string,"OK","");
    return 
1;
} 
Reply
#6

Hello.

This is the right code:

PHP код:

CMD
:admins(playerid, params[])
{
    new 
string[500], t = 0, aname[MAX_PLAYER_NAME];
    
    for(new 
i = 0, j = GetPlayerPoolSize(); i <= j; i++)
    {
        if(!
IsPlayerConnected(i)) continue;
        if(!
Admin[i]) continue;
        
        
GetPlayerName(i, aname, sizeof(aname));
        
format(string, sizeof(string), "%s%s (%d) - {FF0000}Level: %d{FFFFFF}\n", string, aname, i, Admin[i]);
        
t++;
        
ShowPlayerDialog(playerid, 1, DIALOG_STYLE_MSGBOX, "Online admins", string, "Close", ""); 
    }
    if(!
t) return SendClientMessage(playerid, -1, "There are no admins.");
    
    return 
1;
} 
Reply
#7

Quote:
Originally Posted by Shinja
Посмотреть сообщение
Strange.. Try this
PHP код:
CMD:admins(){
    new 
string[300], fstring[64], adminname[25];
    for(new 
i=0; i<MAX_PLAYERS; i++)
    {
        if(
Admin[i] > 0 && IsPlayerConnected(i))
        {
            
GetPlayerName(i,adminname, sizeof(adminname));
            
format(fstring, sizeof(fstring),"%s (%i) - {FF0000}Level: %i{FFFFFF}\n", adminname, i,Admin[i]);
            
strcat(string, fstring, sizeof(string));
        }
    }
    
ShowPlayerDialog(playerid,1,DIALOG_STYLE_MSGBOX,"Online Admins",string,"OK","");
    return 
1;
} 
How is it strange?
Код:
CMD:admins(){
Reply
#8

Quote:
Originally Posted by WhiteGhost
Посмотреть сообщение
How is it strange?
Код:
CMD:admins(){
Strange because it must work dude
Reply


Forum Jump:


Users browsing this thread: