Sort admins help | +rep
#1

hello, i have cmd /admins

i want make system where type cmd /admins, server send me dialog where is list of online admins. but sorting him from higher to lower admin level. like:

Admin1, level:6
admin2, level:6
admin3, level:5
admin4, level:4
admin5, level:3
... ....

now sorting him from ID like:

Admin5[ID:0], level:4
Admin3:[ID:1], level:5
Admin1;[ID:2], level:6

here is cmd for /admins:

Code:
CMD:admins(playerid, params[])
{
    if(IsLogged[playerid] == false) return SendClientMessage(playerid, COLOR_RED, "[SERVER]: "COL_WHITE"Moras biti ulogiran kako bi mogao koristiti komande!");
 	new string[256];
 	new fstring[64];
	new adm = 0;
	
    foreach(Player, i)
    {
	    if(PlayerInfo[i][pAdmin] == 0) adm++;
		{
        if(PlayerInfo[i][pAdmin] == 6)
        {
            format(fstring, sizeof(fstring),""COL_ORANGE"%s"COL_GREY" [ID: %d] [Admin Level: %d]\n", GetName(i), i, PlayerInfo[i][pAdmin]);
            strcat(string, fstring, sizeof(string));
        }
        else if(PlayerInfo[i][pAdmin] == 5)
        {
            format(fstring, sizeof(fstring),""COL_ORANGE"%s"COL_GREY" [ID: %d] [Admin Level: %d]\n", GetName(i), i, PlayerInfo[i][pAdmin]);
            strcat(string, fstring, sizeof(string));
        }
        if(adm == 0) return SCM(playerid, COLOR_ORANGE, "[SERVER]: "COL_WHITE"Trenutno nema Admina/Gamemastera online!");
		}
    }
    ShowPlayerDialog(playerid,DIALOG_ADMINSLISTP,DIALOG_STYLE_MSGBOX,""COL_ORANGE"ONLINE ADMINS",string,"ZATVORI","");
    return 1;
}
Reply
#2

bump
Reply
#3

You can get this scripting help , maybe you should look for a scripter to script it for you. Go to the Server Support section of the forums and then there is a sticky topic named Looking for scripters / helpers , then go in there and post.
Reply
#4

I use this:

pawn Code:
COMMAND:admins(playerid,params[])
{
    new id[MAX_PLAYER_NAME], string[128];
    SendClientMessage(playerid, 0xFFAE00FF, " ");
    SendClientMessage(playerid, 0xFFAE00FF, "----' Online Admins '----");
    for___loop(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
          if(PlayerInfo[i][pAdmin] > 0)
          {
          if(cover[i] == 0)
          {
                switch(PlayerInfo[i][pAdmin])
                {
                case 1: AdmRank = "Trial Moderator";
                case 2: AdmRank = "Moderator";
                case 3: AdmRank = "Master Moderator";
                case 4: AdmRank = "Trial Administrator";
                case 5: AdmRank = "Administrator";
                case 6: AdmRank = "Master Administrator";
                case 7: AdmRank = "Head Administrator";
                case 8: AdmRank = "Trusted Administrator";
                case 9: AdmRank = "Co-Owner";
                case 10: AdmRank = "Owner";
                }
                if(OnDuty[i] >= 0)
                {
                  switch(OnDuty[i])
                  {
                  case 0: OnDutyType = "{FFD900}Admin {00FBFF}Off Duty";
                  case 1: OnDutyType = "{FFD900}Admin {FF0000}On Duty";
                  }
                  GetPlayerName(i, id, sizeof(id));
                  format(string, sizeof(string), "%s (%d) ({FF0000}%s{00FF00}) - %s", id, i, AdmRank, OnDutyType);
                  SendClientMessage(playerid, 0x00FF00FF, string);
                  }
             }
             else if(!IsPlayerConnected(i) && PlayerInfo[i][pAdmin] <= 0)
             {
               SendClientMessage(playerid, 0xFFAE00FF, "There Are No Admins Online");
             }
           }
         }
    }
    return 1;
}
Reply
#5

Maybe not best sorting method but should works ok
pawn Code:
BubbleSort(array[], ids[], a_size = sizeof(array))
{
    new temp[2];
    for(new i=0,j; i < a_size; i++)
        for(j=0; j < (a_size-i); j++)
            if(array[j] < array[j+1])
            {
                temp[0] = array[j];
                temp[1] = ids[j];
                array[j] = array[j+1];
                ids[j] = ids[j+1];
                array[j+1] = temp[0];
                ids[j+1] = temp[1];
            }
}

CMD:admins(playerid, params[])
{
    if(!IsLogged[playerid]) SendClientMessage(playerid, COLOR_RED, "[SERVER]: "COL_WHITE"Moras biti ulogiran kako bi mogao koristiti komande!");
    else
    {
        new AdmRank[MAX_ADMINS], AdmID[MAX_ADMINS], adm;
        foreach(Player, i)
        {
            if(PlayerInfo[i][pAdmin] > 0 && adm < MAX_AMINS)
            {
                AdmRank[adm] = PlayerInfo[i][pAdmin];
                AdmID[adm++] = i;
            }
        }

        if(adm == 0) SCM(playerid, COLOR_ORANGE, "[SERVER]: "COL_WHITE"Trenutno nema Admina/Gamemastera online!");
        else
        {

            BubbleSort(AdmRank, AdmID, adm); // sorting lvls & ids

            static TempStr[80],descStr[80 char],szStr[(80 * MAX_ADMINS) char];
            szStr[0] = EOS;
            for(new i=0; i < adm; i++)
            {
                // if(IsPlayerConnected(AdmID[i])) no needed but?
                // {
                format(TempStr, sizeof(TempStr),""COL_ORANGE"%s"COL_GREY" [ID: %d] [Admin Level: %d]\n", GetName(AdmID[i]), AdmID[i], PlayerInfo[AdmID[i]][pAdmin]);
                strpack(descStr,TempStr);
                strcat(szStr,descStr);
                // }
            }
            ShowPlayerDialog(playerid,DIALOG_ADMINSLISTP,DIALOG_STYLE_MSGBOX,""COL_ORANGE"ONLINE ADMINS",szStr,"ZATVORI","");
        }
    }
    return 1;
}
Reply
#6

This was my (annoying) attempt at it. I think quicksort is a pretty easy method. Not sure if it's outdated, but it definitely works.

pawn Code:
CMD:admins(playerid, params[])
{
    if(!IsLogged[playerid]) return SendClientMessage(playerid, COLOR_RED, "[SERVER]: "COL_WHITE"Moras biti ulogiran kako bi mogao koristiti komande!");
    new
        sort[10][2] = {{INVALID_PLAYER_ID, 0},{INVALID_PLAYER_ID, 0},{INVALID_PLAYER_ID, 0},{INVALID_PLAYER_ID, 0},{INVALID_PLAYER_ID, 0},{INVALID_PLAYER_ID, 0},{INVALID_PLAYER_ID, 0},{INVALID_PLAYER_ID, 0},{INVALID_PLAYER_ID, 0},{INVALID_PLAYER_ID, 0}},
        j = 0
    ;
    foreach(new i : Player)
    {
        if(j >= sizeof(sort)) break;
        if(!PlayerInfo[i][pAdmin]) continue;
        sort[j][0] = i;
        sort[j][1] = PlayerInfo[i][pAdmin];
        ++j;
    }
    if(!j) return SCM(playerid, COLOR_ORANGE, "[SERVER]: "COL_WHITE"Trenutno nema Admina/Gamemastera online!");
    new fstr[70], string[700];
    SortArray(sort, 0, sizeof(sort));
    for(new k = 0; k < j; k++)
    {
        if(sort[k][0] == INVALID_PLAYER_ID) continue;
        format(fstr, sizeof(fstr), COL_ORANGE"%s"COL_GREY" [ID: %d] [Admin Level: %d]\n", GetName(sort[k][0]), sort[k][0], sort[k][1]);
        strcat(string, fstr);
    }
    ShowPlayerDialog(playerid, DIALOG_ADMINSLISTP, DIALOG_STYLE_MSGBOX, ""COL_ORANGE"ONLINE ADMINS", string, "ZATVORI", "");
    return 1;
}

stock SortArray(array[][], left, right)
{
    new
        tempLeft = left,
        tempRight = right,
        pivot = array[(left + right) / 2][1],
        tempVar
    ;
    while(tempLeft <= tempRight)
    {
        while(array[tempLeft][1] < pivot) tempLeft++;
        while(array[tempRight][1] > pivot) tempRight--;

        if(tempLeft <= tempRight)
        {
            tempVar = array[tempLeft][0], array[tempLeft][0] = array[tempRight][0], array[tempRight][0] = tempVar;
            tempVar = array[tempLeft][1], array[tempLeft][1] = array[tempRight][1], array[tempRight][1] = tempVar;
            tempLeft++, tempRight--;
        }
    }
    if(left < tempRight) SortArray(array, left, tempRight);
    if(tempLeft < right) SortArray(array, tempLeft, right);
}
NOTE: SortArray is an edited version of quickSort, which I take no credit for.
Reply
#7

Long back ago I had some problem too..

https://sampforum.blast.hk/showthread.php?tid=567792&page=2
Check at pages you get the answer.

Try searching at ****** once or search system at forums..
And don't bump before 24hrs of no reply.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)