SA-MP Forums Archive
the biggest money pocket - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: the biggest money pocket (/showthread.php?tid=567280)



the biggest money pocket - rOps - 12.03.2015

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?
}



Re : the biggest money pocket - Golimad - 12.03.2015

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;
     }
}



Re: Re : the biggest money pocket - rOps - 12.03.2015

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


Re : the biggest money pocket - Golimad - 12.03.2015

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


Respuesta: the biggest money pocket - admantis - 12.03.2015

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);



Re: Respuesta: the biggest money pocket - oliverrud - 12.03.2015

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.


Respuesta: the biggest money pocket - admantis - 12.03.2015

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.