Whos got the fewest deaths? - Timmeyable - 21.08.2012
Hi,
I want to know how I can find out which player has the fewest deaths.
The deaths are saved via SetPVarInt.
Example:
Let's say Player 1 has died 10 times. Player 2 compared to only 8 times.
A timer find out which player has the fewest deaths from all players.
In this case that would be the second player. A message should be send to all
players like: Player 2 won the game.
I think i need a loop through all the players but I do not know how to do it.
I hope you know what i mean
-Tim
Re: Whos got the fewest deaths? -
Jochemd - 21.08.2012
You have two vars;
* A var which stores the player with the least deaths (default = 0)
* A var which stores the deaths of this player (default = 999999999999 or something).
Use a loop to loop through each player. Each round you check if the deaths of the player is lower than the saved deaths. If this is true, set the vars.
I hope I gave you an idea
Re: Whos got the fewest deaths? -
Finn - 21.08.2012
Why would you use a timer if
OnPlayerDeath callback is called automatically each time someone dies?
Re: Whos got the fewest deaths? -
Jochemd - 21.08.2012
Quote:
Originally Posted by Finn
Why would you use a timer if OnPlayerDeath callback is called automatically each time someone dies?
|
He said this will happen when the round ends
AW: Whos got the fewest deaths? - Timmeyable - 21.08.2012
Exactly Jochemd.
Thanks, i test it out.
Re: Whos got the fewest deaths? -
Jochemd - 21.08.2012
By the way, isn't it better to check for a kill/death ratio?
Код:
ratio = kills/deaths
Re: Whos got the fewest deaths? -
Finn - 22.08.2012
Quote:
Originally Posted by Jochemd
He said this will happen when the round ends
|
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)
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;
}
Re: Whos got the fewest deaths? -
[MM]RoXoR[FS] - 22.08.2012
You can use my top player's include by inserting deaths as data and getting playerid acc to ascending order.