22.08.2010, 21:09
It checks if the variable richestplayer is set to INVALID_PLAYER_ID or not.
My code can be done via foreach aswell, didn't know the OP is using it;
My code can be done via foreach aswell, didn't know the OP is using it;
pawn Код:
stock GetRichestPlayer()
{
new richestplayer = INVALID_PLAYER_ID;
foreach(Player, playerid)
{
if(richestplayer != INVALID_PLAYER_ID)
{
if(GetPlayerMoney(richestplayer) < GetPlayerMoney(playerid))
{
richestplayer = playerid;
}
}
else
{
richestplayer = playerid;
}
}
return richestplayer;
}
//Or as you guys seem to like shorter code:
stock GetRichestPlayer()
{
new r = INVALID_PLAYER_ID;
foreach(Player, i)
{
if(r == INVALID_PLAYER_ID || GetPlayerMoney(r) < GetPlayerMoney(i))
{
r = i;
}
}
return r;
}