30.06.2014, 18:32
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;
}