
#include <amxmodx>
#include <amxmisc>
#include <fakemeta_util>

#define PLUGIN "Damage Fire"
#define VERSION "1.0"
#define AUTHOR "NST"

new kills[33][20][4], list_victims[2000], g_hudmsg2, max_len = 15
new num_victims[33] = {0,...};

public plugin_init() 
{
	register_plugin(PLUGIN, VERSION, AUTHOR)
	
	register_event("Damage", "on_damage", "b", "2!0", "3=0", "4!0")
	register_event("TextMsg", "eRestart", "a", "2&#Game_C", "2&#Game_w")
	register_event("SendAudio", "eEndRound", "a", "2&%!MRAD_terwin", "2&%!MRAD_ctwin", "2&%!MRAD_rounddraw")
	register_event("RoundTime", "eNewRound", "bc")

	g_hudmsg2 = CreateHudSyncObj()
}

public on_damage(id)
{
	static attacker; attacker = get_user_attacker(id)
	static damage; damage = read_data(2)

	new i = 0, e = 0, check_e = 0, victim_id = 1
	while (i < 20 && check_e != 1 && victim_id > 0)
	{
		victim_id = kills[attacker][i][0]
		if (victim_id == id && kills[attacker][i][1] != 1) {
			e = i
			check_e = 1
		}

		i += 1
	}
	if (e == 0 && check_e != 1) {
		e = num_victims[attacker]
		num_victims[attacker] += 1
	}
	kills[attacker][e][0] = id
	kills[attacker][e][1] = 0
	kills[attacker][e][2] += damage
	

	set_hudmessage(255, 0, 0, -1.0, 0.55, 2, 0.1, 2.0, 0.1, 0.1, -1)
	ShowSyncHudMsg(attacker, g_hudmsg2, "%i", damage)
	
}

public client_death(killer, victim, wpnindex, hitplace, TK, id)
{
	
// UPDATE VICTIMS OF VICTIM
	new headshot = (hitplace == HIT_HEAD) ? 1 : 0
	new vic_wpn, num_vic = num_victims[killer]
	
	if (headshot && wpnindex) vic_wpn = 1
	else if (wpnindex == CSW_KNIFE) vic_wpn = 2
	else if (wpnindex == CSW_HEGRENADE) vic_wpn = 3
	else vic_wpn = 4
	kills[killer][(num_vic-1)][3] = vic_wpn
	

	for (new e = 0; e < 33; e++)
	{
		for (new ee = 0; ee < num_victims[e]; ee++)
		{
			if (kills[e][ee][0] == victim) kills[e][ee][1] = 1
		}
	}

	
// SHOW VICTIMS OF PLAYER
	show_victims(victim)
}



public eNewRound(id)
{
	if (read_data(1) == floatround(get_cvar_float("mp_roundtime") * 60.0,floatround_floor))
	{
		show_victims(id)
	}
}
public eRestart(id)
{
	eEndRound(id)
}
public eEndRound(id)
{
	//show_victims(id)
}


public show_victims(idpl)
{
	new i = 0, victim_id = 1, num_die = 0
	while (i < 20 && victim_id > 0)
	{
		victim_id = kills[idpl][i][0]
		if (victim_id > 0)
		{
			if (kills[idpl][i][3] > 0 || kills[idpl][i][2] > 0) num_die += 1
			
			new victim_idwpn = kills[idpl][i][3]
			new victim_wpn[10]
			if (victim_idwpn == 1) victim_wpn = "[HS]"
			else if (victim_idwpn == 2) victim_wpn = "[KF]"
			else if (victim_idwpn == 3) victim_wpn = "[HE]"
			else victim_wpn = ""
	
			new victim_name[33], victim_row[33], victim_name_fix[33]
			get_user_name(kills[idpl][i][0],victim_name,33)
			new num_name = strlen(victim_name)
			if (num_name > max_len) {
				copy(victim_name_fix,(max_len-3),victim_name)
				add (victim_name_fix,max_len,"...")
			}
			else victim_name_fix = victim_name
			
			format (victim_row ,33, "%s: %i %s^n", victim_name_fix, kills[idpl][i][2], victim_wpn) 
			add (list_victims,1999,victim_row)
			kills[idpl][i][0] = 0
			kills[idpl][i][1] = 0
			kills[idpl][i][2] = 0
			kills[idpl][i][3] = 0
		}
		i += 1
	}
	new num_player = i-1
	if (num_player > 0) 
	{
		format (list_victims ,2000, "%i Player / %i Die^n%s", num_player, num_die, list_victims)
		show_menu(idpl, 5, list_victims, 5, "list_victims")
	}
	
	num_victims[idpl] = 0
	list_victims = ""
	
}
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1045\\ f0\\ fs16 \n\\ par }
*/
