Quote:
Originally Posted by Sergei
@Finn,
?
Код:
new richest = INVALID_PLAYER_ID, data[2];
foreach(Player,i)
{
data[0] = GetPlayerMoney(i);
if(data[0] && data[0] > data[1]) richest = i;
}
This would do the job.
|
Yours doesn't even work. You aren't assigning data[1]. Your use of the array for data[] is also slower than individual variables.
The OP can't even code this function and you expect him to add in foreach?
Quote:
Originally Posted by Finn
Why so many variables?
pawn Код:
stock GetRichestPlayer() { new richestplayer = INVALID_PLAYER_ID;
for(new playerid; playerid < MAX_PLAYERS; playerid++) { if(IsPlayerConnected(playerid)) { if(richestplayer != INVALID_PLAYER_ID) { if(GetPlayerMoney(richestplayer) < GetPlayerMoney(playerid)) { richestplayer = playerid; } } else { richestplayer = playerid; } } }
return richestplayer; }
|
3 embedded ifs and 2 calls to GetPlayerMoney? Mine is still far more efficient.