staff command is wrongfully coded, shows only 1 admin instead of more...
#7

Quote:
Originally Posted by Calisthenics
View Post
This is your code:
pawn Code:
if (IsPlayerAdmin(i))
{
    admrank = "{FF0000}RCON Admin";
}
else
{
    switch (PlayerInfo[i][AdminLevel])
    {
        case 1:
            admrank = "{FFFF00}Moderator";
        case 2:
            admrank = "{008000}Administrator";
        case 3:
            admrank = "{3366FF}Manager";
    }
    GetPlayerName(i, pname, sizeof(pname));
    format(string, sizeof(string), "{FFFFFF}%s (ID: %d) | Level: %d | Rank: %s", pname, i, PlayerInfo[i][AdminLevel], admrank);
    ++count;
}
- If the player is RCON admin, nothing happens (not getting the name and adding them into the list).
- If the player is not RCON admin, it gets the name even if the level is 0 and it uses as rank the previous value (if any).
- `string` is overwritten every time. Using:
pawn Code:
format(string, sizeof (string), "%s ...", string, ...);
keeps the previous text. Alternative way is format+strcat.
- Not new lines.

The correct steps are shown below:
pawn Code:
if (IsPlayerAdmin(i))
{
    GetPlayerName(i, pname, sizeof(pname));
    format(string, sizeof(string), "%s{FFFFFF}%s (ID: %d) {FF0000}RCON Admin\n", string, pname, i);
    ++count;

    // If RCON:
        // - get name
        // - re-format text
        // - increase counter
}
else
{
    switch (PlayerInfo[i][AdminLevel])
    {
        // If the player is not admin, skip the current player and go to the next so..
        // the code below will not have any effect (will not be executed at all) to non admins
        case 0: continue; // <--'
        case 1: admrank = "{FFFF00}Moderator";
        case 2: admrank = "{008000}Administrator";
        case 3: admrank = "{3366FF}Manager";
    }
    GetPlayerName(i, pname, sizeof(pname));
    format(string, sizeof(string), "%s{FFFFFF}%s (ID: %d) | Level: %d | Rank: %s\n", string, pname, i, PlayerInfo[i][AdminLevel], admrank);
    ++count;

    // If admin:
        // - get name
        // - re-format text
        // - increase counter
    // If NOT admin:
        // - skip it - continue to the next player
}
i tried your corrected code once again, but this time, it won't even show the dialog

here's how i recoded it:

pawn Code:
CMD:staff(playerid, params[])
{
    #pragma unused params
    if(PlayerInfo[playerid][LoggedIn] == true)
    {
        new string[192];
        new admrank[32];
        new count;
        new pname[MAX_PLAYER_NAME];
        for(new i; i<MAX_PLAYERS; i++)
        {
            if(IsPlayerConnected(i))
            {
                if (IsPlayerAdmin(i))
                {
                    GetPlayerName(i, pname, sizeof(pname));
                    format(string, sizeof(string), "%s{FFFFFF}%s (ID: %d) {FF0000}RCON Admin\n", string, pname, i);
                    ++count;
                }
                else
                {
                    switch(PlayerInfo[i][AdminLevel])
                    {
                        case 0: continue;
                        case 1: admrank = "{FFFF00}Moderator";
                        case 2: admrank = "{008000}Administrator";
                        case 3: admrank = "{3366FF}Manager";
                    }
                    GetPlayerName(i, pname, sizeof(pname));
                    format(string, sizeof(string), "%s{FFFFFF}%s (ID: %d) | Level: %d | Rank: %s\n", string, pname, i, PlayerInfo[i][AdminLevel], admrank);
                    ++count;
                }
            }
        }
        if(count == 0) return format(string, sizeof(string), "{FF0000}There are currently no staff online.");
        ShowPlayerDialog(playerid, DIALOGID0+2, DIALOG_STYLE_MSGBOX, "{FFFFFF}Server staff currently online:", string, "Okay", "");
        return 1;
    } else return SendClientMessage(playerid, COLOR_RED, "ERROR: Account must be registered in order to use commands.");
}
EDIT: turns out that i recoded the code you sent me yesterday wrong i guess, and the problem that wasn't displaying the dialog was at the
pawn Code:
if(count == 0) return format(string, sizeof(string), "{FF0000}There are currently no staff online.");
i removed the return since there was already a "return 1;" at the end if i'm not wrong and yes, it shows more than 1 staff, thanks so much bud, hah it seems like i'm actually learning something

p.s: still want you to explain how you made it allow to have more than 1 staff on the dialog
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)