the biggest money pocket
#1

hi, how i can get from the all server players, who have the biggest money pocket?

HTML Code:
for(new p = 0; p < MAX_PLAYERS; p ++)
{
     // what now?
}
Reply
#2

Should be something like this
Code:
new bool:biggest[MAX_PLAYERS];
for(new p = 0; p < MAX_PLAYERS; p ++)
{
     for(p; p<MAX_PLAYERS; p++)
     {
         check all players money and compare it to this player, if someone has more, break this loop and check the other players through the upper loop and set biggest[playerid] = true; and all others to false;
     }
}
Reply
#3

Quote:
Originally Posted by Golimad
View Post
Should be something like this
Code:
new bool:biggest[MAX_PLAYERS];
for(new p = 0; p < MAX_PLAYERS; p ++)
{
     for(p; p<MAX_PLAYERS; p++)
     {
         check all players money and compare it to this player, if someone has more, break this loop and check the other players through the upper loop and set biggest[playerid] = true; and all others to false;
     }
}
can you give me example? Cause I still can't understand
Reply
#4

Code:
new richest = INVALID_PLAYER_ID, data[2];
foreach(Player,i)
{
     data[0] = GetPlayerMoney(i);
     if(data[0] && data[0] > data[1]) richest = i;
}
Source : https://sampforum.blast.hk/showthread.php?tid=169844
Reply
#5

This would require only a bit of logical thinking.
pawn Code:
new richest = INVALID_PLAYER_ID;
new amount = 0;

for(new p = 0; p < MAX_PLAYERS; p ++)
{
     if(GetPlayerMoney(p) > GetPlayerMoney(richest) || richest == INVALID_PLAYER_ID)
     {
        amount = GetPlayerMoney(p);
        richest = p;
    }
}
printf("The richest player is %d with $%d", richest, amount);
Reply
#6

Quote:
Originally Posted by admantis
View Post
This would require only a bit of logical thinking.
pawn Code:
new richest = INVALID_PLAYER_ID;
new amount = 0;

for(new p = 0; p < MAX_PLAYERS; p ++)
{
     if(GetPlayerMoney(p) > GetPlayerMoney(richest) || richest == INVALID_PLAYER_ID)
     {
        amount = GetPlayerMoney(p);
        richest = p;
    }
}
printf("The richest player is %d with $%d", richest, amount);
Little note if using 0.3.7: Using MAX_PLAYERS in loops is outdated in 0.3.7. GetPlayerPoolSize() is to be used.
Reply
#7

That is correct. I don't know if the OP has foreach or 0.3.7, so I am using his same method. I believe in 0.3.7 and any version, foreach is superior.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)