Show the top ten richest people.
#1

How to show the top ten richest people?
Reply
#2

I don't know what you mean, but you could do a loop to check who's riches ingame right now else you'll have to loop through all your saved accounts and look up the richest one.
Reply
#3

Do you mean top ten richest people online, or in the entire server? (Like you want to load through player accounts)
Reply
#4

Quote:
Originally Posted by Steven82
View Post
Do you mean top ten richest people online, or in the entire server? (Like you want to load through player accounts)
The top ten players who has the highest amount of money(GivePlayerMoney).

Edit: Something likes this but for 10 players.

pawn Code:
new CurrentHighest = 0;
new HighestPlayerID;
for(new i=0; i<MAX_PLAYERS; i++)
{
    if (GetPlayerMoney(i) > CurrentHighest)
    {
        HighestPlayerID = i;
        CurrentHighest = GetPlayerMoney(i);
       
    }
}
Reply
#5

Okay what they are asking was.

Did you want this list you are talking about to ONLY display the top ten richest players that ARE currently online?
OR
Did you want this list you are talking about to display the top ten richest players that ARE Online AND Offline?
Reply
#6

Something like this?

pawn Code:
dcmd_richlist(playerid,params[])
{
    #pragma unused params
    if(AccInfo[playerid][Level] >= 1)
    {
        new string[128], Slot1 = -1, Slot2 = -1, Slot3 = -1, Slot4 = -1;
        new HighestCash = -9999;
        SendClientMessage(playerid,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)  %s - $%d", Slot1,PlayerName2(Slot1),GetPlayerMoney(Slot1));
        SendClientMessage(playerid,COLOR_WHITE,string);
        if(Slot2 != -1){
        format(string, sizeof(string), "(%d)  %s - $%d", Slot2,PlayerName2(Slot2),GetPlayerMoney(Slot2));
        SendClientMessage(playerid,COLOR_WHITE,string);
        }
        if(Slot3 != -1){
        format(string, sizeof(string), "(%d)  %s - $%d", Slot3,PlayerName2(Slot3),GetPlayerMoney(Slot3));
        SendClientMessage(playerid,COLOR_WHITE,string);
        }
        if(Slot4 != -1){
        format(string, sizeof(string), "(%d) %s - $%d", Slot4,PlayerName2(Slot4),GetPlayerMoney(Slot4));
        SendClientMessage(playerid,COLOR_WHITE,string);
        }
        return 1;
    }
    else return ErrorMessages(playerid, 1);
}
Reply
#7

Quote:
Originally Posted by kbalor
View Post
Something like this?

pawn Code:
dcmd_richlist(playerid,params[])
{
    #pragma unused params
    if(AccInfo[playerid][Level] >= 1)
    {
        new string[128], Slot1 = -1, Slot2 = -1, Slot3 = -1, Slot4 = -1;
        new HighestCash = -9999;
        SendClientMessage(playerid,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)  %s - $%d", Slot1,PlayerName2(Slot1),GetPlayerMoney(Slot1));
        SendClientMessage(playerid,COLOR_WHITE,string);
        if(Slot2 != -1){
        format(string, sizeof(string), "(%d)  %s - $%d", Slot2,PlayerName2(Slot2),GetPlayerMoney(Slot2));
        SendClientMessage(playerid,COLOR_WHITE,string);
        }
        if(Slot3 != -1){
        format(string, sizeof(string), "(%d)  %s - $%d", Slot3,PlayerName2(Slot3),GetPlayerMoney(Slot3));
        SendClientMessage(playerid,COLOR_WHITE,string);
        }
        if(Slot4 != -1){
        format(string, sizeof(string), "(%d) %s - $%d", Slot4,PlayerName2(Slot4),GetPlayerMoney(Slot4));
        SendClientMessage(playerid,COLOR_WHITE,string);
        }
        return 1;
    }
    else return ErrorMessages(playerid, 1);
}
Any better way of doing it?
Reply
#8

Well, if you don't mind using third party includes, using this: https://sampforum.blast.hk/showthread.php?tid=343172
you could outperform the code above at the cost of memory.

pawn Code:
new RichList[MAX_PLAYERS][2];

stock FindRichest()
{
     RichList = {{0,0}...}; // Reset the array in case you only want online players to show up, u probs gotta rely on a loop there.. this doesn't work I am sure but you get the point.
    foreach(new p : Player) // obv if u dont have foreach, yanno
    {
        RichList[p][0] = GetPlayerMoney(p);
        RichList[p][1] = p;
    }
    SortDeepArray(RichList, 0);
    // richest are:
    RichList[200][1], RichList[199][1], RichList[198][1], RichList[197][1]
}
The code above is more or less pseudo code and probably doesn't work the way I wrote it but I am sure you get the picture =).

Regards.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)