SA-MP Forums Archive
I need help getting the admin online totals - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: I need help getting the admin online totals (/showthread.php?tid=291737)



I need help getting the admin online totals - GAMER_PS2 - 21.10.2011

I need help getting admin online totals on my /admins

here is the code

pawn Код:
CMD:admins(playerid,params[])
{
    new string[128],count = 0,level,adminname[MAX_PLAYER_NAME];
    level = PlayerInfo[playerid][pAdmin];
    GetPlayerName(playerid,adminname,128);
    for(new i = 0;i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
           if(PlayerInfo[playerid][pAdmin] >= 0)
           {
              switch(PlayerInfo[playerid][pAdmin])
              {
                 case 1: AdmRank = "Trial Moderator";
                 case 2: AdmRank = "Moderator";
                 case 3: AdmRank = "Global Moderator";
                 case 4: AdmRank = "Trial Manager";
                 case 5: AdmRank = "Header Administrator";
                 case 6: AdmRank = "Senior Administrator";
                 case 7: AdmRank = "Junior Administrator";
                 case 8: AdmRank = "Scripter/Mapper";
                 case 9: AdmRank = "Co-Owner";
              }
              if(PlayerInfo[playerid][pAdmin] >= 10)
              {
                 AdmRank = "Server Owner";
              }
              format(string,sizeof(string),"%s(ID:%d) | Level:%d - %s\n\nTotal Admins Online: %i",adminname,i,level,AdmRank,count);
              ShowPlayerDialog(i,523,0,""white"Admins Online:",string,"OK","");
              count++;
           }
        }
        else if(count == 0)
        {
            ShowPlayerDialog(i,524,0,""white"Admins Online",""red"No Admins Online!","OK","");
        }
    }
    return 1;
}
Note:Give me the good answer or code in ZCMD Format not in strcmp

And Please Respond Fast


Re: I need help getting the admin online totals - JaTochNietDan - 21.10.2011

The problem is that you're displaying the dialog each time the loop is run, instead you want to build the string of online administrators and then display the dialog when the loop is finished, otherwise it will not work as you're intending. Take a look at strcat's documentation on using it to build your string.


Re: I need help getting the admin online totals - GAMER_PS2 - 21.10.2011

dude thanks for advice anyway can you help me up?


Re: I need help getting the admin online totals - Ensconce - 21.10.2011

He told you exactly what was wrong with your script, is that not help enough? Also it is not advisable to use else statements in loops.


Re: I need help getting the admin online totals - MP2 - 21.10.2011

pawn Код:
for(new i=0; i<GetMaxPlayers(); i++)
{
    if(!IsPlayerConnected(i)) continue; // Not connected, continue
    if(!pLevel[i]) continue; // Not admin, continue
    if(!count) format(string, sizeof(string), "%s", pName[i]); // The first
    else format(string, sizeof(string), "\n%s", pName[i]); // Not the first, start with \n
    count++;
}
if(!count) return ShowPlayerDialog(.. no admins online ..); // No admins, display the 'no admins' dialog and stop the script there (return)
ShowPlayerDialog(playerid, dialogid, DIALOG_STYLE_LIST, "Admins Online:", string, "OK", ""); // Script carried on, show list of admins
Rushed, should work though.


Re: I need help getting the admin online totals - JaTochNietDan - 21.10.2011

Quote:
Originally Posted by MP2
Посмотреть сообщение
pawn Код:
for(new i=0; i<GetMaxPlayers(); i++)
{
    if(!IsPlayerConnected(i)) continue; // Not connected, continue
    if(!pLevel[i]) continue; // Not admin, continue
    if(!count) format(string, sizeof(string), "%s", pName[i]); // The first
    else format(string, sizeof(string), "\n%s", pName[i]); // Not the first, start with \n
    count++;
}
if(!count) return ShowPlayerDialog(.. no admins online ..); // No admins, display the 'no admins' dialog and stop the script there (return)
ShowPlayerDialog(playerid, dialogid, DIALOG_STYLE_LIST, "Admins Online:", string, "OK", ""); // Script carried on, show list of admins
Rushed, should work though.
That won't work as intended, the end result will only be a single administrators name showing. This is because you're simply overwriting the string every time you format it, like I explained earlier, you should look into using strcat.


Re: I need help getting the admin online totals - MP2 - 21.10.2011

My mistake, correction:

pawn Код:
for(new i=0; i<GetMaxPlayers(); i++)
{
    if(!IsPlayerConnected(i)) continue; // Not connected, continue
    if(!pLevel[i]) continue; // Not admin, continue
    if(!count) format(string, sizeof(string), "%s", pName[i]); // The first
    else format(string, sizeof(string), "%s\n%s", string, pName[i]); // Not the first, start with \n
    count++;
}
if(!count) return ShowPlayerDialog(.. no admins online ..); // No admins, display the 'no admins' dialog and stop the script there (return)
ShowPlayerDialog(playerid, dialogid, DIALOG_STYLE_LIST, "Admins Online:", string, "OK", ""); // Script carried on, show list of admins
I used strcat before and it fucked stuff up, so I just stick to format.