Get highest value?
#1

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.
Reply
#2

I'm in hurry, (not sure tho, try this)

PHP код:
new HighestValuepname[MAX_PLAYER_NAME];

for(new 
0MAX_PLAYERSi++)
{
    if(
PlayerValue[i] > HighestValue || i==0)
    
        
GetPlayerName(ipnamesizeof(pname));
        
HighestValue PlayerValue[i];
    }
}

printf("Highest value owner: %d. Value: %d"pnameHighestValue); 
Reply
#3

What value do you want to get exactly, their player id, or a variable, like money or etc?
Reply
#4

money and etc
Reply
#5

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;
}
Reply
#6

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 >.
Reply
#7

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.
Reply
#8

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)