How to get Highest deaths with player name in a Round - 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: How to get Highest deaths with player name in a Round (
/showthread.php?tid=653428)
How to get Highest deaths with player name in a Round -
TadePoleMG - 04.05.2018
Hi all
If a round starts like team deathmatch.Then,
At last on round finish, how to get highest deaths of player.
Help me rep++.
Thank You.
Re: How to get Highest deaths with player name in a Round -
Lokii - 04.05.2018
PHP код:
#include <a_samp>
new p_Deaths[MAX_PLAYERS] = {0, ...};
public OnPlayerDisconnect(playerid, reason)
{
p_Deaths[playerid] = 0; //reset player deaths
return 1;
}
public OnPlayerDeath(playerid, killerid, reason)
{
p_Deaths[playerid] ++; //+1 death when player dies
return 1;
}
forward onroundend(); //on round end
public onroundend() //on round end
{
new str[85], name[MAX_PLAYER_NAME], last_player = -1, last_score; //set top score to 0 at first and player to -1
for(new i = 0, j = GetPlayerPoolSize(); i <= j; i++) //loop
{
if(!IsPlayerConnected(i) || IsPlayerNPC(i) || p_Deaths[i] <= last_score) //if player not connected, npc or got same score as previous player or less (skip)
last_player = i; //set the last player with best score
}
//after we got the top player lets get his name and send message to all that he died the most
GetPlayerName(last_player, name, sizeof(name));
format(str, sizeof(str), "%s {FFFFFF}died the most this round {FF0000}%d {FFFFFF}deaths", name, p_Deaths[last_player]);
SendClientMessageToAll(0xFFFF00FF, str);
return 1;
}
Re: How to get Highest deaths with player name in a Round -
TadePoleMG - 04.05.2018
Thank You.
Re: How to get Highest deaths with player name in a Round -
jlalt - 04.05.2018
a fix on @Lokii solution. not skipping and never assigning last_score to a value.
PHP код:
if(!IsPlayerConnected(i) || IsPlayerNPC(i) || p_Deaths[i] <= last_score || (last_player != -1 && p_Deaths[i] <= p_Deaths[last_player] )) continue; //if player not connected, npc or got same score as previous player or less (skip)
last_player = i; //set the last player with best score
last_score = p_Deaths[i];