How to create a top dmg per round?
#1

Hello, is there someone who can explain to me how to do a top damage per round?

I use the variable: PlayerInfo [playerid] [RDmg]

What I want to do is that every time a round ends, it shows the 3 players that did the most damage, this I want it to appear in the chat, something like in A / D.

I hope I can count on your help, thanks all those watching my post.
Reply
#2

Sort all player's damage array using this include:
https://sampforum.blast.hk/showthread.php?tid=343172
Then get the 1st to 3rd array.

Or by looping through players and compare their damage to the best ones at the end of round.

This is a rough example:
Код:
#define TOP_DAMAGE_SIZE 3 // 3 positions
// On round ends
new Float:damagesRank[TOP_DAMAGE_SIZE] = {0.0, ...}, topDamagers[TOP_DAMAGE_SIZE] = {INVALID_PLAYER_ID, ...}; // these variables holds the current record
for (new i, j = GetPlayerPoolSize(); i <= j; i++)
{
	if (IsPlayerConnected(i) && !IsPlayerNPC(i)) // also add condition to check if the player is in the match
	{
		for (new x; x < TOP_DAMAGE_SIZE; x++)
		{
			if (PlayerInfo[i][RDmg] > damagesRank[x] && i != topDamagers[x])
			{
				if (x+1 < TOP_DAMAGE_SIZE && damagesRank[x+1] > damagesRank[x]) // push if it's better than next rank
				{
					damagesRank[x+1] = damagesRank[x];
					topDamagers[x+1] = topDamagers[x];
				}
				damagesRank[x] = PlayerInfo[i][RDmg]; // record the round top damage of x(+1)-th to this player's amount big
				topDamagers[x] = i; // record the round top damager of x(+1)-th to this player's id
			}
		}
	}
}
if (damagesRank[0] != 0.0) // make sure the most damage is not zero
{
	SendClientMessageToAll(-1, "Round finished with top damages dealt:");
	new string[144], playerName[MAX_PLAYER_NAME];
	for (new x; x < TOP_DAMAGE_SIZE; x++)
	{
		if (topDamagers[x] != INVALID_PLAYER_ID) // make sure the damage dealt at x(+1)-th position was done by a player
		{
			GetPlayerName(topDamagers[x], playerName, sizeof(playerName));
			format(string, sizeof(string), "#%d. %.2f damages by %s (ID:%d)", x+1, damagesRank[x], playerName, topDamagers[x]); // we want to start at 1, not 0
			SendClientMessageToAll(-1, string); // show this x(+1)-th position to everyone
		}
	}
}
else
{
	SendClientMessageToAll(-1, "Round finished. Nobody dealt any damage");
}
// reset the players PlayerInfo[playerid][RDmg] here
I guess your RDmg is a float, otherwise, change it to match the RDmg array tag.

Sorry, not tested, i hope it works but i'm not sure it will work properly. I don't know how to achieve this to get 3 positions, most likely the example code above would not push a 1st record to 2nd one, when the next player would have smaller damage, the previous players record is likely to be erased instead of being placed in 2nd.

If it's buggy, then i suggest you to use the include. Sorry for my bad english.
Reply
#3

Yes your code works but always sends the results of a single player, but no problem, thanks for the help.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)