#include <amxmodx>

/*
Name:		Knife_round_1
Version:	2.0
Author:		jas0n & Sp0oN
Date:		17.04.10

Внимание: В первую очередь выбирайте "knife only" мод. c4/granades не обязательно!.

Cvars:		kr_mode <0|1|2|3> (default "1")
				0: knife only
				1: knife + c4
				2: knife + granades
				3: knife + c4 + granades
			kr_timer <sec> (default "0")
				* If value less then 30 sec this function disabled
*/

new const PLUGIN[] = "Knife_round_1"
new const VERSION[] = "2.0"
new const AUTHOR[] = "jas0n & S.p.0_o.N"

new const g_HudMsgStart[] = "Первый раунд на ножах!"
new const g_HudMsgEnd[] = "Закупай оружие и в бой!"

new bool:g_IsKnifeRound
new bool:g_IsCommencing
new g_Mode, p_Mode
new g_Timer, p_Timer
new g_SyncMsgObj

public plugin_init()
{
	register_plugin(PLUGIN, VERSION, AUTHOR)

	register_event("TextMsg", "evGameCommencing", "a", "2=#Game_Commencing")
	register_event("CurWeapon", "evCurWeapon", "be", "1=1", "2!29")
	register_event("HLTV", "evNewRound", "a", "1=0", "2=0")
	register_logevent("evStartRound", 2, "1=Round_Start")
	register_logevent("evRestartRound", 2, "1&Restart_Round_")

	g_Mode = register_cvar("kr_mode", "1")
	g_Timer = register_cvar("kr_timer", "0")
	g_SyncMsgObj = CreateHudSyncObj()
}

public plugin_cfg() {
	p_Mode = get_pcvar_num(g_Mode)
	p_Timer = get_pcvar_num(g_Timer)
}

public evGameCommencing() {
	g_IsCommencing = true
}

public evNewRound() {
	if(!g_IsKnifeRound)
		return
	
	if(task_exists(348916))
		remove_task(348916)

	set_hudmessage(0, 225, 0, -1.0, 0.30, 2, 2.0, 6.0, _, _, -1)
	ShowSyncHudMsg(0, g_SyncMsgObj, g_HudMsgEnd)
		
	g_IsCommencing = false
	g_IsKnifeRound = false

	pause("ad")
}

public evStartRound() {
	if (!g_IsCommencing)
		return

	g_IsKnifeRound = true

	if (p_Timer >= 30)
		set_task(float(p_Timer), "evNewRound", 348916)

	set_hudmessage(0, 225, 0, -1.0, 0.30, 2, 2.0, 6.0, _, _, -1)
	ShowSyncHudMsg(0, g_SyncMsgObj, g_HudMsgStart)
}

public client_spawn(id) {
	if (!g_IsCommencing)
		return
	
	force_knife(id)
}

public evRestartRound() {
	if (!g_IsKnifeRound)
		return

	g_IsKnifeRound = false
}

public evCurWeapon(id) {
	if (!g_IsCommencing)
		return

	static weapon
	weapon = get_user_weapon(id)

	switch(p_Mode) {
		case 1: if (weapon == CSW_C4) return
		case 2: if (weapon == CSW_HEGRENADE || weapon == CSW_FLASHBANG || weapon == CSW_SMOKEGRENADE) return
		case 3: if (weapon == CSW_C4 || weapon == CSW_HEGRENADE || weapon == CSW_FLASHBANG || weapon == CSW_SMOKEGRENADE) return
	}

	force_knife(id)
}

force_knife(id)
{
	engclient_cmd(id, "weapon_knife")
}
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1049\\ f0\\ fs16 \n\\ par }
*/