Detecting who has the most kills
#1

Ok so I am making a tdm style game mode, I have a timer set up that when its over I want it to loop through all online players and see who has the most kills, but how would I do this? I know how to set the timer I just don't know how I see who on the server has the most kills, under OnPlayerDeath I have this for adding kills to the killer and adding deaths to the person who was killed


pawn Код:
kill = GetPVarInt(killerid, "Kills");
    death = GetPVarInt(playerid, "Deaths");
    kills = kill ++;
    deaths = death ++;
    SetPVarInt(killerid, "Kills", kills);
    SetPVarInt(playerid, "Deaths", deaths);
Reply
#2

pawn Код:
stock GetHighestKills()
{
    new kills, player = INVALID_PLAYER_ID;
    for (new i, j = GetMaxPlayers(); i < j; i++)
    {
        if (IsPlayerConnected(i))
        {
            if (GetPVarInt(i, "Kills") > kills)
            {
                player = i;
                kills = GetPVarInt(i, "Kills");
            }
        }
    }
    return player;
}
pawn Код:
new bestkiller = GetHighestKills();

if (bestkiller != INVALID_PLAYER_ID)
{
    // Do something
}
Reply
#3

Alright but would this work to get the players name iwth the highest kills?

pawn Код:
stock GetHighestKills()
{
    new player = INVALID_PLAYER_ID;
    new kills;
    for (new i; i < MAX_PLAYERS; i++)
    {
        if (IsPlayerConnected(i))
        {
            if (GetPVarInt(i, "Kills") > kills)
            {
                player = i;
                kills = GetPVarInt(i, "Kills");
                GetPlayerName(i, hk, sizeof(hk));
            }
        }
    }
    return player;
}
Reply
#4

Just add the name here, not in the function.

pawn Код:
new bestkiller = GetHighestKills();

if (bestkiller != INVALID_PLAYER_ID)
{
new name[30];
GetPlayerName(bestkiller,name,sizeof(name));
    // Do something
}
Reply
#5

Do it outside the function.
pawn Код:
new bestkiller = GetHighestKills();

if (bestkiller != INVALID_PLAYER_ID)
{
    new name[MAX_PLAYER_NAME];
    GetPlayerName(bestkiller, name, sizeof(name));
    // name now contains the players name
}
Reply
#6

Alright thanks man, +plus rep.
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)