#include <amxmodx>
#include <amxmisc> 
native	bte_wpn_get_mod_running()
native	bte_wpn_get_weapon_limit()
native	MH_SendClientModRunning(id,i)
native	MH_SendClientWeaponLimit(id,i)

enum _:BTE_MOD
{
	BTE_MOD_NONE=0,
	BTE_MOD_TD,
	BTE_MOD_ZE,
	BTE_MOD_NPC,
	BTE_MOD_ZB1,
	BTE_MOD_ZE,
	BTE_MOD_GD,
	BTE_MOD_DR
}
enum _:BTE_WEAPON_LIMIT
{
	WEAPON_LIMIT_NO=0,
	WEAPON_LIMIT_SNIPER,
	WEAPON_LIMIT_PISTOL,
	WEAPON_LIMIT_GRENADE,
	WEAPON_LIMIT_KNIFE
}


new const MOD_NAME[][]={"NONE","TD","ZE","NPC","ZB1","GD","DR","","",""}
#define TASK_WAITTEXT	1451
#define TASK_SENDMODE	1551
//new iSendMod[33];
new g_isZb3 = 0;

public plugin_init()
{
	register_dictionary("bte_other.bte")
	register_plugin("BTE TIP", "1.0", "BTE TEAM");
	register_event("HLTV", "Event_HLTV", "a", "1=0", "2=0")
	register_event("TeamInfo","Event_TeamInfo","a")

	new config_dir[64], url_zb3[64]
	get_configsdir(config_dir, charsmax(config_dir))
	format(url_zb3, charsmax(url_zb3), "%s/plugins-zb3.ini", config_dir)
	
	if (file_exists(url_zb3)) g_isZb3 = 1
	else g_isZb3 = 0;
	
	server_cmd("mp_flashlight 1");
}
public Event_TeamInfo()
{
	static id;
	id = read_data(1)
	
	set_task(1.0, "Task_SendMode", TASK_SENDMODE + id);
}

public Event_HLTV()
{
	/*client_print(0,print_chat,"%L",LANG_PLAYER,"BTE_TIP_WPN_KEYBUYWEAPONS")
	new szIndex[64]
	format(szIndex,63,"BTE_TIP_MOD_%s",MOD_NAME[bte_wpn_get_mod_running()])
	
	client_print(0,print_chat,"%L",LANG_PLAYER,szIndex)*/
	for(new i=1;i<=32;i++)
	{
		set_task(1.0, "Task_SendMode", TASK_SENDMODE + i);
	}
}
public client_putinserver(id)
{
	//iSendMod[id] = 0;
	if(GetPlayer()>=2 || bte_wpn_get_mod_running() == BTE_MOD_NPC)
	{
		for(new i=1;i<=32;i++)
		{
			if(task_exists(TASK_WAITTEXT + i))
				remove_task(TASK_WAITTEXT + i)
		}
	}
	else
	{
		if(bte_wpn_get_mod_running() != BTE_MOD_ZE && bte_wpn_get_mod_running() != BTE_MOD_NPC)
			set_task(1.0, "Task_WaitText", TASK_WAITTEXT + id, _, _, "b");
	}
	//set_task(1.0, "Task_SendMode", TASK_SENDMODE + id);
}
stock GetPlayer()
{
	new a = 0;
	for(new i=1;i<33;i++)
	{
		if(is_user_connected(i))	a += 1;
	}
	return a;
}
public Task_WaitText(iTask)
{
	new id = iTask - TASK_WAITTEXT
	client_print(id, print_center, "%L", LANG_PLAYER, "BTE_WAITING");
}
public Task_SendMode(iTask)
{
	new id = iTask - TASK_SENDMODE
	//if(!iSendMod[id])
	//{
	switch (bte_wpn_get_mod_running())
	{
		case BTE_MOD_NONE :	MH_SendClientModRunning(id,1);
		case BTE_MOD_TD	:	MH_SendClientModRunning(id,2);
		case BTE_MOD_ZE : 	MH_SendClientModRunning(id,10);
		case BTE_MOD_NPC :	MH_SendClientModRunning(id,5);
		case BTE_MOD_ZB1 :	
		{
			if(g_isZb3)	MH_SendClientModRunning(id,11);
			else MH_SendClientModRunning(id,3);
		}			
		case BTE_MOD_GD :	MH_SendClientModRunning(id,8);
		case BTE_MOD_DR :	MH_SendClientModRunning(id,9);
	}
	
	MH_SendClientWeaponLimit(id,bte_wpn_get_weapon_limit());
		
		//iSendMod[id] = 1;
	//}
}



