Help /admins
#7

This is how I would do it:

pawn Code:
new const AdminLevelName[][] = {
    "User",
    "Semi Administrator [Level 1]",
    "Semi Administrator [Level 2]",
    "Semi Administrator [Level 3]",
    "Administrator",
    "Vice Head Admin",
    "Head Admin"
};
new AdminLevel[MAX_PLAYERS char];

CMD:admins(playerid)
{
    new admins_string[500], count;
    for (new i; i < MAX_PLAYERS; i++) //I would actually use foreach, but sticking to your way for now
    {
        if (!IsPlayerConnected(i) || IsPlayerNPC(i) || !AdminLevel{i}) continue;
       
        new pName[MAX_PLAYER_NAME];
        GetPlayerName(i, pName, MAX_PLAYER_NAME);
        format(admins_string, sizeof(admins_string), "%s%s: %s (ID: %d)\n", admins_string, AdminLevelName[AdminLevel{i}], pName, i);
        count++;
    }
    if (!count)
        ShowPlayerDialog(playerid, 7777, DIALOG_STYLE_MSGBOX, "Online Administrators", "There are currently no administrators online", "OK", "");
    else ShowPlayerDialog(playerid, 7777, DIALOG_STYLE_MSGBOX, "Online Administrators", admins_string, "OK", "");
    return 1;
}
I would not actually do it exactly like that, but according to your code, I would change it to something like this.
Note the next few things:

1) There is an array named "AdminLevelName". By using AdminLevelName[0] it would return "User", AdminLevelName[1] would return "Semi Administrator [Level 1]" etcetera. Rather than switching between two variables, you can now get the level name from the array.
2) Note how I used "const" for AdminLevelName; because of this, you can't alter the array after creating it to prevent problems
3) I use 'AdminLevel' to hold someone's level. Note how I used 'MAX_PLAYERS char' instead of 'MAX_PLAYERS'. This decreases the array size by 4 (what it basically does is MAX_PLAYERS / 4)
4) As an addition to 3), I use {playerid} (or {i}, in this scenario) instead of [playerid] (or [i]).
By using curly brackets ({}) instead of the regular ones ([]) you access a single byte instead of a whole cell.
One cell uses 4 bytes. Whereas 1 byte, well, uses 1 byte. When accessing a single byte you can only use values from 0 up to 255. Since AdminLevel is, in this scenario, is 0 up to 6, I'm accessing a single byte instead of a whole cell. This saves 4 times the space it otherwise would use.
Reply


Messages In This Thread
Help /admins - by KamilPolska - 27.06.2020, 15:31
Re: Help /admins - by ilogbc - 27.06.2020, 15:39
Re: Help /admins - by Lexless - 27.06.2020, 15:44
Re: Help /admins - by KamilPolska - 28.06.2020, 13:28
Re: Help /admins - by Kwarde - 28.06.2020, 15:13
Re: Help /admins - by KamilPolska - 28.06.2020, 17:55
Re: Help /admins - by Kwarde - 28.06.2020, 18:13
Re: Help /admins - by Chams - 28.06.2020, 18:47
Re: Help /admins - by KamilPolska - 05.07.2020, 17:39
Re: Help /admins - by DarkMaster - 09.07.2020, 11:13

Forum Jump:


Users browsing this thread: 1 Guest(s)