/admins dialog command error.
#1

pawn Код:
dcmd_admins(playerid, params[])
{
    #pragma unused params
    foreach(Player, i)
    {
        new level[128], string[128], name[MAX_PLAYER_NAME];
        GetPlayerName(i, name, sizeof(name));

        if(PlayerInfo[i][pAdmin] > 0)
        {
            switch(PlayerInfo[i][pAdmin])
            {
                case 1: level = "Trial Admin";
                case 2: level = "Moderator";
                case 3: level = "Basic Moderator";
                case 4: level = "Head Moderator";
                case 5: level = "Administrator";
                case 6: level = "Head Admin";
                case 7: level = "Lead Admin";
                case 8: level = "Develepor";
                case 9: level = "Co-Owner";
                case 10: level = "Owner";
            }
            format(string, sizeof(string), "%s - %s Level %d\n", name, level, PlayerInfo[i][pAdmin]);
            ShowPlayerDialog(playerid, 78, DIALOG_STYLE_MSGBOX, "{00FF00}Online Admins", string, "Close", "");
            return 1;
        }
        else ShowPlayerDialog(playerid,78,DIALOG_STYLE_MSGBOX,"{00FF00}Online Admins","No Admin Online","Done","");
    }
    return 1;
}
It only shows 1 admin online even if there are more admins online.
Reply
#2

pawn Код:
if(IsPlayerConnected(playerid))
        {
            for (new i = 0; i < MAX_PLAYERS; i++)
            {
                if(IsPlayerConnected(i))
                {
         new level[128], string[128], name[MAX_PLAYER_NAME];
         GetPlayerName(i, name, sizeof(name));

                    if(PlayerInfo[i][pAdmin] > 0)
        {
            switch(PlayerInfo[i][pAdmin])
            {
case 1: level = "Trial Admin";
                case 2: level = "Moderator";
                case 3: level = "Basic Moderator";
                case 4: level = "Head Moderator";
                case 5: level = "Administrator";
                case 6: level = "Head Admin";
                case 7: level = "Lead Admin";
                case 8: level = "Develepor";
                case 9: level = "Co-Owner";
                case 10: level = "Owner";
                }
            format(string, sizeof(string),"%s - %s: %s\n",name, level, PlayerInfo[i][pAdmin]);
                    }
                }
            }
ShowPlayerDialog(playerid,78,DIALOG_STYLE_MSGBOX,"Online admins",string,"Close","");
}
        else ShowPlayerDialog(playerid,78,DIALOG_STYLE_MSGBOX,"{00FF00}Online Admins","No Admin Online","Done","");
    }
Reply
#3

First of all returning a value in a loop will stop the loop. Even if you remove it, it'll show the last admin in a dialog and that's because you do not format the previous text to the current one. And keep in mind that the dialog should be shown outside of the loop otherwise it'll be called as many online admins there are.

pawn Код:
dcmd_admins(playerid, params[])
{
    #pragma unused params
    new level[15], string[150], name[MAX_PLAYER_NAME], count; // declare the variables once - not everytime the loop is called
    foreach(Player, i) // foreach(new i : Player) <--- better this syntax to be used
    {
        if(PlayerInfo[i][pAdmin] > 0)
        {
            GetPlayerName(i, name, sizeof(name)); // no need to get the name if the level is not greater than 0
            switch(PlayerInfo[i][pAdmin])
            {
                case 1: level = "Trial Admin";
                case 2: level = "Moderator";
                case 3: level = "Basic Moderator";
                case 4: level = "Head Moderator";
                case 5: level = "Administrator";
                case 6: level = "Head Admin";
                case 7: level = "Lead Admin";
                case 8: level = "Develepor";
                case 9: level = "Co-Owner";
                case 10: level = "Owner";
            }
            format(string, sizeof(string), "%s%s - %s Level %d\n", string, name, level, PlayerInfo[i][pAdmin]);
            count++;
        }
    }
    // if not 0, show the string we formatted
    if (count) ShowPlayerDialog(playerid, 78, DIALOG_STYLE_MSGBOX, "{00FF00}Online Admins", string, "Close", "");
    else ShowPlayerDialog(playerid,78,DIALOG_STYLE_MSGBOX,"{00FF00}Online Admins","No Admin Online","Done","");
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)