bug with richest players
#1

pawn Код:
CMD:highest(playerid, params[])
{
        new place[5], playaname[5], pdolla[5], richname[5], highestcash = -9999;
        SendClientMessage(playerid, COLOR_GREEN, ".........Top List.........");
        foreach(Player, i)
        {
            if(playerVariables[i][pMoney] > highestcash)
            {
                highestcash = playerVariables[i][pMoney];
                pdolla[0] = playerVariables[i][pMoney];
                place[0] = i;
                richname[0] = GetPlayerName(i, playaname[0], MAX_PLAYER_NAME);
               
            }
        }
        highestcash = -9999;
        foreach(Player, i)
        {
            if(i != place[0])
            if(playerVariables[i][pMoney] > highestcash)
            {
                highestcash = playerVariables[i][pMoney];
                pdolla[1] = playerVariables[i][pMoney];
                place[1] = i;
                richname[1] = GetPlayerName(i, playaname[1], MAX_PLAYER_NAME);
            }
        }
        highestcash = -9999;
        foreach(Player, i)
        {
            if(i != place[0] && i != place[1])
            if(playerVariables[i][pMoney] > highestcash)
            {
                highestcash = playerVariables[i][pMoney];
                place[2] = i;
                pdolla[2] = playerVariables[i][pMoney];
                richname[2] = GetPlayerName(i, playaname[2], MAX_PLAYER_NAME);
               
            }
        }
        highestcash = -9999;
        foreach(Player, i)
        {
            if(i != place[0] && i != place[1] && i != place[2])
            if(playerVariables[i][pMoney] > highestcash)
            {
            highestcash = playerVariables[i][pMoney];
            place[3] = i;
            pdolla[3] = playerVariables[i][pMoney];
            richname[3] = GetPlayerName(i, playaname[3], MAX_PLAYER_NAME);
            }
        }
        highestcash = -9999;
        foreach(Player, i)
        {
            if(i != place[0] && i != place[1] && i != place[2] && i != place[3])
            if(playerVariables[i][pMoney] > highestcash)
            {
                highestcash = playerVariables[i][pMoney];
                place[4] = i;
                pdolla[4] = playerVariables[i][pMoney];
                richname[4] = GetPlayerName(i, playaname[4], MAX_PLAYER_NAME);
            }
        }
        format(szMessage, 256, "1st place [%d]%s    |   $%d", place[0], richname[0], pdolla[0]);
        SendClientMessage(playerid, -1, szMessage);
        if(place[1] != -1)
        {
        format(szMessage, 256, "2nd place [%d]%s    |   $%d", place[1], richname[1], pdolla[1]);
        SendClientMessage(playerid, -1, szMessage);
        }
        if(place[2] != -1)
        {
        format(szMessage, 256, "3rd place [%d]%s    |   $%d", place[2], richname[2], pdolla[2]);
        SendClientMessage(playerid, -1, szMessage);
        }
        if(place[3] != -1)
        {
        format(szMessage, 256, "4th place [%d]%s    |   $%d", place[3], richname[3], pdolla[3]);
        SendClientMessage(playerid, -1, szMessage);
        }
        if(place[4] != -1)
        {
        format(szMessage, 256, "5th place [%d]%s    |   $%d", place[4], richname[4], pdolla[4]);
        SendClientMessage(playerid, -1, szMessage);
        }
        return 1;
}
This is the outcome...
pawn Код:
[02:22:12] .........Top List.........

[02:22:12] 1st place [105]     @@@@@NNNNNiko[duS] | $123456

[02:22:12] 2nd place [107]    @@@@@NNNNNiko[duS] | $123456

[02:22:12] 3rd place [111]   @@@@@NNNNNiko[duS] | $123456

[02:22:12] 4th place [91]  @@@@@NNNNNiko[duS] | $123456

[02:22:12] 5th place [100] @@@@@NNNNNiko[duS] | $123456
Reply
#2

pawn Код:
CMD:richlist(playerid, params[]) //ALL CAN USE
{
    new string[128],
        Slot1 = -1,
        Slot2 = -1,
        Slot3 = -1,
        Slot4 = -1,
        HighestCash = -9999
    ;
    SendClientMessage(playerid, COLOR_GREEN, "Rich List:");

    for(new x=0; x<MAX_PLAYERS; x++)
    if(IsPlayerConnected(x))
    if(GetPlayerMoney(x) >= HighestCash)
    {
        HighestCash = GetPlayerMoney(x);
        Slot1 = x;
    }
    HighestCash = -9999;
    for(new x=0; x<MAX_PLAYERS; x++)
    if(IsPlayerConnected(x) && x != Slot1)
    if(GetPlayerMoney(x) >= HighestCash)
    {
        HighestCash = GetPlayerMoney(x);
        Slot2 = x;
    }
    HighestCash = -9999;
    for(new x=0; x<MAX_PLAYERS; x++)
    if(IsPlayerConnected(x) && x != Slot1 && x != Slot2)
    if(GetPlayerMoney(x) >= HighestCash)
    {
        HighestCash = GetPlayerMoney(x);
        Slot3 = x;
    }
    HighestCash = -9999;
    for(new x=0; x<MAX_PLAYERS; x++)
    if(IsPlayerConnected(x) && x != Slot1 && x != Slot2 && x != Slot3)
    if(GetPlayerMoney(x) >= HighestCash)
    {
        HighestCash = GetPlayerMoney(x);
        Slot4 = x;
    }
    format(string, sizeof(string), "(%d) Player %s - $%d", Slot1, GetName(Slot1), GetPlayerMoney(Slot1));
    SendClientMessage(playerid, COLOR_RED, string);
    if(Slot2 != -1)
    {
        format(string, sizeof(string), "(%d) Player %s - $%d", Slot2, GetName(Slot2), GetPlayerMoney(Slot2));
        SendClientMessage(playerid, COLOR_BLUE, string);
    }
    if(Slot3 != -1)
    {
        format(string, sizeof(string), "(%d) Player %s - $%d", Slot3, GetName(Slot3), GetPlayerMoney(Slot3));
        SendClientMessage(playerid, COLOR_GREEN, string);
    }
    if(Slot4 != -1)
    {
        format(string, sizeof(string), "(%d) Player %s - $%d", Slot4, GetName(Slot4), GetPlayerMoney(Slot4));
        SendClientMessage(playerid, COLOR_YELLOW, string);
    }
    return 1;
}
Reply
#3

I am trying to work on an improved version of this code, but its bugged, i rather not use the code as the you wrote it
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)