Jump to content

Question

Posted

salut, as dori un sfat sau o parere cum as putea face comanda /top in ordine descrescatoare, mafia cu cele mai multe turfuri sa fie afisata prima si cea cu cele mai putine ultima

 

CMD:top(playerid, params[]) {
    new 
        p=0,t=0,s=0,r=0,a=0, b=0,x = 0, y = 0, z = 0;
    foreach(new i : GangTurfs) {
        if(TurfInfo[i][zOwned] == 15) t++;
        if(TurfInfo[i][zOwned] == 16) p++;
        if(TurfInfo[i][zOwned] == 17) s++;
        if(TurfInfo[i][zOwned] == 18) r++;
        if(TurfInfo[i][zOwned] == 19) a++;
        if(TurfInfo[i][zOwned] == 20) b++;
        if(TurfInfo[i][zOwned] == 21) x++;
        if(TurfInfo[i][zOwned] == 22) y++;
        if(TurfInfo[i][zOwned] == 23) z++;
    }
    SendClientMessage(playerid,COLOR_WHITE,"---------- Top Gangs ----------");
    SendClientMessage(playerid,COLOR_WHITE, "{%s}%s {FFFFFF}- %d turfs", GetFactionColor(15), FactionName(15), t);
    SendClientMessage(playerid,COLOR_WHITE, "{%s}%s {FFFFFF}- %d turfs", GetFactionColor(16), FactionName(16), p);
    SendClientMessage(playerid,COLOR_WHITE, "{%s}%s {FFFFFF}- %d turfs", GetFactionColor(17), FactionName(17), s);
    SendClientMessage(playerid,COLOR_WHITE, "{%s}%s {FFFFFF}- %d turfs", GetFactionColor(18), FactionName(18), r);
    SendClientMessage(playerid,COLOR_WHITE, "{%s}%s {FFFFFF}- %d turfs", GetFactionColor(19), FactionName(19), a);
    SendClientMessage(playerid,COLOR_WHITE, "{%s}%s {FFFFFF}- %d turfs", GetFactionColor(20), FactionName(20), b);
    SendClientMessage(playerid,COLOR_WHITE, "{%s}%s {FFFFFF}- %d turfs", GetFactionColor(21), FactionName(21), x);
    SendClientMessage(playerid,COLOR_WHITE, "{%s}%s {FFFFFF}- %d turfs", GetFactionColor(22), FactionName(22), y);
    SendClientMessage(playerid,COLOR_WHITE, "{%s}%s {FFFFFF}- %d turfs", GetFactionColor(23), FactionName(23), z);
    SendClientMessage(playerid,COLOR_WHITE,"-------------------------------------");
    return 1;
}

2 answers to this question

Recommended Posts

  • 0
Posted (edited)
/* ESTE DOAR UN EXEMPLU CUM POTI REALIZA */

#define MAX_GANGS 9

/* pui enum-urile tale */
enum GangData {
    GangID,
    GangTurfCount
};

new 
  GangInfo[MAX_GANGS][GangData];

CMD:top(playerid, params[]) {
 
    new 
      gangIDs[MAX_GANGS] = {15, 16, 17, 18, 19, 20, 21, 22, 23},
      GangCount[MAX_GANGS],

    new 
        i, j;

    for (i = 0; i < MAX_GANGS; i++) {
        GangInfo[i][GangID] = gangIDs[i];
        GangInfo[i][GangTurfCount] = 0;
    }

    foreach (new i : GangTurfs) {
        for (j = 0; j < MAX_GANGS; j++) {
            if (TurfInfo[i][zOwned] == GangInfo[j][GangID]) {
                GangInfo[j][GangTurfCount]++;
                break;
            }
        }
    }
  
    for (i = 0; i < MAX_GANGS - 1; i++) {
        for (j = i + 1; j < MAX_GANGS; j++) {
            if (GangInfo[i][GangTurfCount] < GangInfo[j][GangTurfCount]) {
                new tempID = GangInfo[i][GangID];
                new tempCount = GangInfo[i][GangTurfCount];
                GangInfo[i][GangID] = GangInfo[j][GangID];
                GangInfo[i][GangTurfCount] = GangInfo[j][GangTurfCount];
                GangInfo[j][GangID] = tempID;
                GangInfo[j][GangTurfCount] = tempCount;
            }
        }
    }
    SendClientMessage(playerid, COLOR_WHITE, "---------- Top Gangs ----------");
    for (i = 0; i < MAX_GANGS; i++)
    {
        SendClientMessage(playerid, COLOR_WHITE, "{%s}%s {FFFFFF}- %d turfs",
                          GetFactionColor(GangInfo[i][GangID]),
                          FactionName(GangInfo[i][GangID]),
                          GangInfo[i][GangTurfCount]);
    }
    SendClientMessage(playerid, COLOR_WHITE, "-------------------------------------");
    return 1;
}

 

Edited by khain.dev

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. For more details you can also review our Terms of Use and Privacy Policy.