22.08.2012, 13:00
Well, of course it'll be more efficient to use a loop instead of doing it in OnPlayerDeath if you're needing to know the player with fewest deaths only when the round ends, but if you want to i.e. display a text draw with the name of the player with the fewest deaths it's a lot more efficient to use OnPlayerDeath instead.
Something like this: (untested code, but I hope you get the point)
Something like this: (untested code, but I hope you get the point)
pawn Код:
static fewestdeaths_player = INVALID_PLAYER_ID, fewestdeaths_count, deaths[MAX_PLAYERS];
stock GetPlayerWithFewestDeaths()
return fewestdeaths_player;
public OnPlayerDeath(playerid, killerid, reason)
{
deaths[playerid]++;
if(fewestdeaths_player == playerid)
{
fewestdeaths_player = INVALID_PLAYER_ID;
fewestdeaths_count++;
}
if(fewestdeaths_player == INVALID_PLAYER_ID)
{
new loneplayer = INVALID_PLAYER_ID;
foreach(Player, id)
{
if(deaths[id] < fewestdeaths_count)
{
if(loneplayer == INVALID_PLAYER_ID)
{
loneplayer = id;
}
else
{
fewestdeaths_count = deaths[id];
loneplayer = INVALID_PLAYER_ID;
break;
}
}
}
if(loneplayer != INVALID_PLAYER_ID)
{
fewestdeaths_player = loneplayer;
fewestdeaths_count = deaths[loneplayer];
}
}
return 1;
}