#include <amxmodx>
#include <amxmisc>
#include <halomod>

#define PLUGIN "HaloMod Sprees"
#define VERSION HALOVERSION
#define AUTHOR "Soccdoodcss"

#define MAXSPREE 6
#define MAXMULTI 9 

#define WEAPNUM 31
#define WEAPONSPREES 9

#define SPREESOUNDS 1
#define MULTISOUNDS 2

#define OTHER 0
#define PISTOL 1
#define SMG 2
#define SHOTGUN 3
#define RIFLE 4
#define SNIPER 5
#define MG 6
#define SWORD 7
#define GRENADE 8

new uSpree[33], uMulti[33]

new weapSpree[33][WEAPONSPREES]

new gWeaponType[WEAPNUM] = {
	OTHER,
	PISTOL,  //CSW_P228
	OTHER,
	SNIPER,  //CSW_SCOUT
	GRENADE,   //CSW_HEGRENADE
	SHOTGUN,  //CSW_XM1014
	OTHER,   //CSW_C4
	SMG, //CSW_MAC10
	RIFLE,  //CSW_AUG
	GRENADE,   //CSW_SMOKEGRENADE
	PISTOL, //CSW_ELITE
	PISTOL, //CSW_FIVESEVEN
	SMG, //CSW_UMP45
	SNIPER,  //CSW_SG550
	RIFLE,  //CSW_GALIL
	RIFLE,  //CSW_FAMAS
	PISTOL, //CSW_USP
	PISTOL, //CSW_GLOCK18
	SNIPER,  //CSW_AWP
	SMG, //CSW_MP5NAVY
	MG, //CSW_M249
	SHOTGUN,  //CSW_M3
	RIFLE,  //CSW_M4A1
	SMG, //CSW_TMP
	SNIPER,  //CSW_G3SG1
	GRENADE,   //CSW_FLASHBANG
	PISTOL,  //CSW_DEAGLE
	RIFLE,  //CSW_SG552
	RIFLE,  //CSW_AK47
	SWORD,   //CSW_KNIFE
	SMG  //CSW_P90
}

new gWeaponSpree[WEAPONSPREES][] = {
	"Other",
	"Pistol",
	"SMG",
	"Shotgun",
	"Rifle",
	"Sniper",
	"Machine Gun",
	"Sword",
	"Grenade"
}

new gSpreeName[MAXSPREE][] ={
	"Killing Spree",
	"Killing Frenzy",
	"Running Riot",
	"Rampage",
	"Untouchable",
	"Invincible"
}

new gMultiName[MAXMULTI][] ={
	"Double Kill",
	"Triple Kill",
	"Overkill",
	"Killtacular",
	"Killtrocity",
	"Killamanjaro",
	"Killtastrophe",
	"Killapocalypse",
	"Killionaire"
}

new gMultiSound[MULTISOUNDS][]={
	"doublekill",
	"triplekill"
}

new gSpreeSound[SPREESOUNDS][]={
	"killingspree"
}

public plugin_precache()
{
	//Multi Sounds
	precache_generic("sound/halomodv3/doublekill.mp3")
	precache_generic("sound/halomodv3/triplekill.mp3")
	
	//Spree Sounds
	precache_generic("sound/halomodv3/killingspree.mp3")
}

public plugin_init()
{
	register_plugin(PLUGIN, VERSION, AUTHOR)
	
	register_event("DeathMsg", "onDeath", "a")
}

public onDeath()
{
	if(!is_halo_on())
		return PLUGIN_HANDLED
	
	new attacker = read_data(1)
	new id = read_data(2)
	
	endMulti(id)
	endSpree(id)
	if(id!=attacker && (get_user_team(id)!=get_user_team(attacker) || get_cvar_num("mp_friendlyfire") == 1) && is_user_connected(attacker))
	{
		if(task_exists(attacker))
			remove_task(attacker)
		
		new weapid = get_user_weapon(attacker)
		new weaptype = gWeaponType[weapid]
		nextSpree(attacker, weaptype)
		nextMulti(attacker)
		set_task(4.0, "endMulti", attacker)
	}
	
	return PLUGIN_HANDLED
}

public endSpree(id)
{
	uSpree[id] = 0
	for(new x = 0; x <= 8; x++)
		weapSpree[id][x] = 0
}

public endMulti(id)
{
	uMulti[id] = 0
}

public nextSpree(id, weaptype)
{
	uSpree[id]++
	weapSpree[id][weaptype]++
	checkSpree(id, weaptype)
	
	if(uSpree[id]%5==0 && uSpree[id]>=5 && uSpree[id]<=30)
		saySpree(id, (uSpree[id]/5)-1)
}

public nextMulti(id)
{
	uMulti[id]++
	if(uMulti[id]>=2 && uMulti[id] <= 10)
		sayMulti(id)
}

public sayMulti(id)
{
	if(is_user_alive(id))
	{
		new name[31]
		new trueMult = uMulti[id]-2
		get_user_name(id, name, 30)
		client_print(0, print_chat, "[Halo][Multi] %s: %s", gMultiName[trueMult], name)
		if(trueMult >= 0 && trueMult < MULTISOUNDS)
			play_sound(0, gMultiSound[trueMult])
		
	}
}

public saySpree(id, spree)
{
	if(is_user_alive(id))
	{
		new name[31]
		get_user_name(id, name, 30)
		client_print(0, print_chat, "[Halo][Spree] %s: %s", gSpreeName[spree], name)
		if(spree >= 0 && spree < SPREESOUNDS)
			play_sound(0, gSpreeSound[spree])
		
	}
}

public sayWeapSpree(id, spree[])
{
	if(is_user_alive(id))
	{
		new name[31]
		get_user_name(id, name, 30)
		client_print(0, print_chat, "[Halo][Spree] %s: %s", spree, name)
		
	}
}

public checkSpree(id, weaptype)
{
	if(weapSpree[id][weaptype]==5)
		sayWeapSpree(id, gWeaponSpree[weaptype])
}

public client_authorized(id)
{
	if(!is_halo_on())
		return PLUGIN_HANDLED
	
	endSpree(id)
	endMulti(id)
	
	return PLUGIN_HANDLED
}
