Hello. Got into a stupid situation.
I can't make the damage top 3 players.
The first place works, on 2 and 3 place a random player takes both places with zero damage.
PHP Code:
#include <sourcemod>
#include <sdktools>
new Damage[65];
new String:DamageP[16] = "dmg_health";
public void OnPluginStart()
{
HookEvent("player_hurt", hurt, EventHookMode_Post);
HookEvent("round_end", RoundEnd, EventHookMode_PostNoCopy);
}
public hurt(Handle:event, const String:name[], bool:dontBroadcast)
{
new dmg = GetClientOfUserId(GetEventInt(event,"attacker"));
if (dmg)
{
Damage[dmg] += GetEventInt(event,DamageP);
}
}
public RoundEnd(Handle:event, const String:name[], bool:dontBroadcast)
{
new first = 0, second = 0, third = 0;
Damage[0] = 0;
for (new i = 1; i <= MaxClients; i++)
if (IsClientInGame(i))
{
if (Damage[i] > Damage[first]) first = i;
else if (Damage[i] == Damage[first]) first = i;
}
for (new i = 1; i <= MaxClients; i++)
if (IsClientInGame(i))
{
if (Damage[i] < Damage[first]) second = i;
else if ((Damage[i] == Damage[second]) && (Damage[second] < Damage[first])) second = i;
}
for (new i = 1; i <= MaxClients; i++)
if (IsClientInGame(i))
{
if (Damage[i] < Damage[second]) third = i;
else if ((Damage[i] == Damage[third]) && (Damage[third] < Damage[second])) third = i;
}
decl String:firstName[257];
decl String:secondName[257];
decl String:thirdName[257];
GetClientName(first, firstName, 50);
GetClientName(second, secondName, 50);
GetClientName(third, thirdName, 50);
PrintToChatAll("1 %s - dmg %i", firstName, Damage[first]);
PrintToChatAll("2 %s - dmg %i", secondName, Damage[second]);
PrintToChatAll("3 %s - dmg %i", thirdName, Damage[third]);
for (int i = 1; i <= MaxClients; i++)
{
Damage[i] = 0;
}
}