#include <amxmodx>
#include <amxmisc>
#include <fun>
#include <hamsandwich>

#define VERSION 1.2

new g_enable, knife_fight, g_maxplayers, g_IsBot[33],
g_IsConnected[33], g_msgsync

public plugin_init()
{
	register_plugin("Knife Fight", "VERSION", "alan_el_more")
	register_cvar("kf_version", "VERSION", FCVAR_SERVER)
	register_dictionary("Knife_Fight.txt")
	g_enable = register_cvar("kf_enable", "1")
	register_clcmd("say /kn", "cmdkf", ADMIN_KICK)
	register_clcmd("buy", "block_buy")
	register_clcmd("buyammo1", "block_buy")
	register_clcmd("buyammo2", "block_buy")
	register_clcmd("buyequip", "block_buy")
	register_clcmd("cl_autobuy", "block_buy")
	register_clcmd("cl_rebuy", "block_buy")
	register_clcmd("cl_setautobuy", "block_buy")
	register_clcmd("cl_setrebuy", "block_buy")
	register_event("HLTV", "event_round_start", "a", "1=0", "2=0")
	RegisterHam(Ham_Spawn, "player", "fw_PlayerSpawn_Post", 1)
	RegisterHam(Ham_Touch, "weaponbox", "fw_TouchWeapon")
	RegisterHam(Ham_Touch, "armoury_entity", "fw_TouchWeapon")
	RegisterHam(Ham_Touch, "weapon_shield", "fw_TouchWeapon")
	g_msgsync = CreateHudSyncObj()
	g_maxplayers = get_maxplayers()
}

public cmdkf(id, level, cid)
{
	if(get_pcvar_num(g_enable))
	{
		if (!cmd_access(id, level, cid, 1))
			return PLUGIN_HANDLED;
		
		if(knife_fight)
		{
			new name[33]
			get_user_name(id, name, 32)
			set_hudmessage(255, 0, 0, 0.3, 0.0, 1, 0.0, 5.0, 1.0, 1.0, -1)
			ShowSyncHudMsg(0, g_msgsync, "[KN] %L", LANG_PLAYER, "HUD_DISABLE", name)
			
			knife_fight = false
		}
		else
		{
			new name[33]
			get_user_name(id, name, 32)
			set_hudmessage(255, 0, 0, 0.3, 0.0, 1, 0.0, 5.0, 1.0, 1.0, -1)
			ShowSyncHudMsg(0, g_msgsync, "[KN] %L", LANG_PLAYER, "HUD_ENABLE", name)
			
			knife_fight = true
			
			for(new id = 1;id <= g_maxplayers;id++)
			{
				if(is_user_alive(id))
				{
					strip_user_weapons(id)
					give_item(id, "weapon_knife")
				}
			}
		}		
	}
	else
		client_print(id, print_chat, "[KN] %L", id, "KF_DISABLE")
	
	return PLUGIN_CONTINUE
}

public event_round_start()
{
	if(knife_fight)
	{
		set_hudmessage(255, 0, 0, 0.4, 0.0, 1, 0.0, 5.0, 1.0, 1.0, -1)
		ShowSyncHudMsg(0, g_msgsync, "[KN] %L", LANG_PLAYER, "HUD_KF")
	}
}

// Ham Player Spawn Post Forward
public fw_PlayerSpawn_Post(id)
{
	// Not Alive
	if (!is_user_alive(id))
		return;
	
	if(get_pcvar_num(g_enable) && knife_fight)
	{
		strip_user_weapons(id)
		give_item(id, "weapon_knife")
	}
}

public fw_TouchWeapon(weapon, id)
{
	if (knife_fight && (1 <= id <= g_maxplayers) && !g_IsBot[id])
		return HAM_SUPERCEDE;
	
	return HAM_IGNORED;
}

public client_putinserver(id)
{
	g_IsConnected[id] = true;
	
	g_IsBot[id] = is_user_bot(id)
}

public block_buy(id)
{
	if(!knife_fight)
		return PLUGIN_CONTINUE
	
	return PLUGIN_HANDLED
}
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang3082\\ f0\\ fs16 \n\\ par }
*/
