Get highest value? - 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: Get highest value? (
/showthread.php?tid=624634)
Get highest value? -
rOps - 20.12.2016
So, as you see I created another theme with new question

how to get from the all server players one player, who have highest value?
Код HTML:
new HighestValue, HighestPlayerValueID;
for(new i = 0; i < MAX_PLAYERS; ++ i)
{
if(PlayerValue[i] > HighestValue)
{
HighestPlayerValueID = i;
HighestValue = PlayerValue[HighestPlayerValueID];
}
}
printf("Highest value owner: %d. Value: %d", HighestPlayerValueID, HighestValue);
I tried this code, but it don't works correctly.
Re: Get highest value? -
Eoussama - 20.12.2016
I'm in hurry,
(not sure tho, try this)
PHP код:
new HighestValue, pname[MAX_PLAYER_NAME];
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(PlayerValue[i] > HighestValue || i==0)
GetPlayerName(i, pname, sizeof(pname));
HighestValue = PlayerValue[i];
}
}
printf("Highest value owner: %d. Value: %d", pname, HighestValue);
Re: Get highest value? -
Jack_Leslie - 20.12.2016
What value do you want to get exactly, their player id, or a variable, like money or etc?
Re: Get highest value? -
rOps - 20.12.2016
money and etc
Re: Get highest value? -
ranme15 - 20.12.2016
Quote:
Originally Posted by rOps
money and etc
|
I guess that would work.
Код:
GetHighestValue()
{
new highest = 0;
for(new i = 0, j = GetPlayerPoolSize(); i <= j; i ++)
if(PlayerMoney[i] >= highest) highest = PlayerMoney[i];
return highest;
}
Re: Get highest value? -
SickAttack - 20.12.2016
Quote:
Originally Posted by ranme15
I guess that would work.
Код:
GetHighestValue()
{
new highest = 0;
for(new i = 0, j = GetPlayerPoolSize(); i <= j; i ++)
if(PlayerMoney[i] >= highest) highest = PlayerMoney[i];
return highest;
}
|
No need for >=, just >.
Re: Get highest value? -
ranme15 - 20.12.2016
Quote:
Originally Posted by SickAttack
No need for >=, just >.
|
Thats for his decision, whether he wants to replace the highest value by the lastest IDs having the equal highest value or not.
Re: Get highest value? -
SickAttack - 20.12.2016
Quote:
Originally Posted by ranme15
Thats for his decision, whether he wants to replace the highest value by the lastest IDs having the equal highest value or not.
|
That would be stupid. A player is a player, no need to set that so it's the last player it detects. He should use a loop that starts from the player pool size to 0 in that case.