Whos got the fewest deaths?
#7

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


Messages In This Thread
Whos got the fewest deaths? - by Timmeyable - 21.08.2012, 15:15
Re: Whos got the fewest deaths? - by Jochemd - 21.08.2012, 15:29
Re: Whos got the fewest deaths? - by Finn - 21.08.2012, 15:39
Re: Whos got the fewest deaths? - by Jochemd - 21.08.2012, 15:42
AW: Whos got the fewest deaths? - by Timmeyable - 21.08.2012, 15:56
Re: Whos got the fewest deaths? - by Jochemd - 21.08.2012, 16:26
Re: Whos got the fewest deaths? - by Finn - 22.08.2012, 13:00
Re: Whos got the fewest deaths? - by [MM]RoXoR[FS] - 22.08.2012, 14:34

Forum Jump:


Users browsing this thread: 1 Guest(s)