/*================================================================================
	
	-------------------------------------------
	-*- [AMX] Effects Killer | by Re.Act!ve -*- 

	- No Sprites
	- Show DHUD
	-------------------------------------------

	~~~~~~~~~~~~~~~
	- Credits -
	~~~~~~~~~~~~~~~
	Re.Act!ve 			This Build Plugin

	~~~~~~~~~~~~~~~
	- Changelog -
	~~~~~~~~~~~~~~~
	v. 1.0	 - First Plugin Released, version released
	v. 1.1	- Fix bugs, and stable version released.
	v. 1.2 	- Testing...
	v. 1.3	- All Fix bugs
	v. 1.4	- Update hud & dhud messages
================================================================================*/
#include <amxmodx>
#include <fakemeta>
#include <dhudmessage>

#define RELAY				0.5
#define MULTIPLE_RELAY 		1.2
#define MAX_PLAYERS 		33
#define TASK_KILL_LEVEL 		2055
#define TASK_KILL_MULTIPLE 	2058
new bool:g_firstBlood, player_kills[2][MAX_PLAYERS], Float:iPlayerTimeFreeze[MAX_PLAYERS]	// 0 - level, 1 - xN
new cvar_kill_first, cvar_hud_enable, cvar_time_killing, gMaxPlayers, Float:fHudAngle[MAX_PLAYERS], Float:fdHudAngle[MAX_PLAYERS]

new const MultiKill_sound[][] =
{
	"misc/EK_sounds/EK_level1.wav",	// 1 level (3 kills) 0
	"misc/EK_sounds/EK_level2.wav", 	// 2 level (4 kills) 1 
	"misc/EK_sounds/EK_level3.wav", 	// 3 level (5 kills) 2
	"misc/EK_sounds/EK_level4.wav", 	// 4 level (6 kills) 3
	"misc/EK_sounds/EK_level5.wav", 	// 5 level (7 kills) 4
	"misc/EK_sounds/EK_level6.wav", 	// 6 level (8 kills) 5
	"misc/EK_sounds/EK_level7.wav", 	// 7 level (9 kills) 6
	"misc/EK_sounds/EK_level8.wav", 	// MAX level (10 kills and more) 7
	"misc/EK_sounds/EK_double.wav", 	// double kill 8
	"misc/EK_sounds/EK_triple.wav", 	// triple kill 9
	"misc/EK_sounds/EK_ultra.wav", 		// ultra kill 10
	"misc/EK_sounds/EK_rampage.wav",	// rampage 11
	"misc/EK_sounds/EK_firstblood.wav"	// first kill 12
}

new gLangMsg[][] = { 
	"EK_LEVEL1", "EK_LEVEL2", "EK_LEVEL3", "EK_LEVEL4", "EK_LEVEL5", "EK_LEVEL6", "EK_LEVEL7", "EK_LEVEL8",
	"EK_DOUBLE", "EK_TRIPLE", "EK_ULTRA", "EK_RAMPAGE", "EK_FIRST"
}

public plugin_init() 
{
	register_plugin("[AMX] Effects Killer", "1.4", "Re.Act!ve")
	
	register_event("HLTV", "event_round_start", "a", "1=0", "2=0")
	register_event("DeathMsg", "event_DeathMsg", "a")	
	cvar_kill_first = register_cvar("ek_first_kill", "1")	// < 1 | 0 >
	cvar_hud_enable = register_cvar("ek_hud_enable","1")	// < 1 | 0 >
	cvar_time_killing = register_cvar("ek_time_killcount_freeze", "5.0")

	gMaxPlayers = get_maxplayers()

	// Dictionary lang file
	register_dictionary("amx_effects_killer.txt")
}

public plugin_precache()
	for(new i=0; i < sizeof MultiKill_sound; i++)
		precache_sound(MultiKill_sound[i])

public event_DeathMsg()
{	static attacker, victim
	attacker = read_data(1)
	victim = read_data(2)

	if (attacker == victim || !is_user_connected(attacker)) 
		return PLUGIN_HANDLED

	if(get_pcvar_num(cvar_kill_first) != 0 && !g_firstBlood)
	{
		g_firstBlood = true;
		show_msg(0, -1.0, 0.4, 200, 100, 0, attacker, gLangMsg[12])
		client_cmd(attacker,"spk %s", MultiKill_sound[12])
	}

	if(get_gametime() > iPlayerTimeFreeze[attacker]) {
		player_kills[1][attacker] = 0;
		fdHudAngle[attacker] = 0.0
	}

	iPlayerTimeFreeze[attacker] = get_gametime() + get_pcvar_float(cvar_time_killing)
	player_kills[0][attacker]+=1;	
	player_kills[1][attacker]+=1;	
	player_kills[0][victim] = 0;

	if(task_exists(attacker+TASK_KILL_LEVEL)) remove_task(attacker+TASK_KILL_LEVEL)
	if(task_exists(attacker+TASK_KILL_MULTIPLE)) remove_task(attacker+TASK_KILL_MULTIPLE)

	set_task(RELAY, "EK_level_kill_player", attacker+TASK_KILL_LEVEL)
	set_task(RELAY+MULTIPLE_RELAY, "EK_multiple_kill_player", attacker+TASK_KILL_MULTIPLE)

	return PLUGIN_CONTINUE
}

public EK_level_kill_player(taskid)
{
	new iNum, id=taskid-TASK_KILL_LEVEL
	// Debug
	//client_print(id, print_chat, "Kills Level: %d", player_kills[0][id])
	// Kill is 3 count
	iNum = player_kills[0][id] - 3
	
	if(iNum>=0) {
		if(iNum>7) iNum = 7;
		show_msg(0, -1.0, 0.24+fHudAngle[id], 200, 100, 0, id, gLangMsg[iNum])
		client_cmd(id,"spk %s", MultiKill_sound[iNum])

		if(fHudAngle[id]<0.6) fHudAngle[id]+=0.03
		else fHudAngle[id] = 0.0
	}

	remove_task(taskid)
}

public EK_multiple_kill_player(taskid)
{
	new id=taskid-TASK_KILL_MULTIPLE
	new iNum

	if(player_kills[1][id]>1) {
		iNum = player_kills[1][id]+6;
		if(iNum>11) iNum = 11;
		show_msg(1, -1.0, 0.15+fdHudAngle[id], 0, 200, 0, id, gLangMsg[iNum])
		client_cmd(id,"spk %s", MultiKill_sound[iNum])

		fdHudAngle[id]+=0.05
	}

	remove_task(taskid)
}

public show_msg(dhud, Float:x, Float:y, r, g, b, killer, msg[])
	if (get_pcvar_num(cvar_hud_enable))
		switch(dhud)
		{
			case 0: {
				set_hudmessage(r, g, b, x, y, 1, 0.0, 2.8, 0.2, 1.0, -1)
				show_hudmessage(killer, "%L", LANG_PLAYER, msg);
			}
			case 1: {
				set_dhudmessage(r, g, b, x, y, 2, 1.0, 2.8,0.03,0.05,false)
				show_dhudmessage(killer, "%L", LANG_PLAYER, msg);
			}
		}


public event_round_start() {
	g_firstBlood = false;
	for(new id=1;id<=gMaxPlayers;id++) {
		player_kills[0][id]=0;	player_kills[1][id]=0;
	}
}

/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1033\\ f0\\ fs16 \n\\ par }
*/