Detecting who has the most kills - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Detecting who has the most kills (
/showthread.php?tid=326208)
Detecting who has the most kills -
new121 - 16.03.2012
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);
Re: Detecting who has the most kills -
Psymetrix - 16.03.2012
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
}
Re: Detecting who has the most kills -
new121 - 16.03.2012
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;
}
Re: Detecting who has the most kills -
coole210 - 16.03.2012
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
}
Re: Detecting who has the most kills -
Psymetrix - 16.03.2012
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
}
Re: Detecting who has the most kills -
new121 - 16.03.2012
Alright thanks man, +plus rep.