/* AMX Mod script
*
* (c) 2003, T(+)rget & f117bomb
* This file is provided as is (no warranties)
*
* Info:
*		[ATAC] Extension to configure all settings using an in-game menu
*
* 1.0: 
*      Initial Release
*/
#include <amxmod>
#include <amxmisc>
//----------------------------------------------------------------------------------------------
new MenuPage[33]
new Float:Menu0 = 0.1
new Menu1 = 1
new Menu5 = 5
new Menu30 = 30
new Menu250 = 250
//----------------------------------------------------------------------------------------------
public plugin_init()
{
	register_plugin("ATAC Config", "1.0", "T(+)rget & f117bomb")
	register_clcmd("say /atacmenu", "amx_atac_menu", ADMIN_MENU, "- [ATAC]: Configuration Menu")
	register_menucmd(register_menuid("[ATAC]"), 1023, "action_atac_set")
}
//----------------------------------------------------------------------------------------------
public amx_atac_menu(id, level, cid)
{
	if(!cmd_access(id, level, cid, 1)) 
		return PLUGIN_HANDLED

	MenuPage[id] = 1
	show_atac_set(id)
	return PLUGIN_HANDLED
}
//----------------------------------------------------------------------------------------------
show_atac_set(id)
{
	new menuoption[10][64], smenu[64], menubody[512]
	new keys = (1<<0)|(1<<1)|(1<<2)|(1<<3)|(1<<4)|(1<<5)|(1<<6)|(1<<7)|(1<<8)|(1<<9)
	for(new z = 0; z < 10; ++z) menuoption[z][0] = 0 // clear string
	
	switch(MenuPage[id])
	{
		case 1:
		{
			format(smenu, 63, "Setup Menu")
			format(menuoption[0], 63, "\w1. Punishments^n")
			format(menuoption[1], 63, "\w2. Team Attack^n")
			format(menuoption[2], 63, "\w3. Team Kill^n")
			format(menuoption[3], 63, "\w4. Extra Options^n^n")
			format(menuoption[9], 63, "\w0. Exit")
			keys -= (1<<4)|(1<<5)|(1<<6)|(1<<7)|(1<<8)
		}
		case 2:
		{
			new option = get_cvar_num("atac_options")
			format(smenu, 63, "Punishments Menu\R1/2")
			format(menuoption[0], 63, "\w1. Slap\R\y%s^n", (option & (1<<0) != (1<<0)) ? "OFF" : "ON")
			format(menuoption[1], 63, "\w2. Slap To 1 HP\R\y%s^n", (option & (1<<1) != (1<<1)) ? "OFF" : "ON")
			format(menuoption[2], 63, "\w3. Slay Next Round\R\y%s^n", (option & (1<<2) != (1<<2)) ? "OFF" : "ON")
			format(menuoption[3], 63, "\w4. Jail\R\y%s^n", (option & (1<<3) != (1<<3)) ? "OFF" : "ON")
			format(menuoption[4], 63, "\w5. Chicken\R\y%s^n", (option & (1<<4) != (1<<4)) ? "OFF" : "ON")
			format(menuoption[5], 63, "\w6. Bury\R\y%s^n", (option & (1<<5) != (1<<5)) ? "OFF" : "ON")
			format(menuoption[6], 63, "\w7. Glow\R\y%s^n^n", (option & (1<<6) != (1<<6)) ? "OFF" : "ON")
			format(menuoption[7], 63, "\w8. More^n^n")
			format(menuoption[8], 63, "\w9. Back^n")
			format(menuoption[9], 63, "\w0. Exit")
		}
		case 3:
		{
			new option = get_cvar_num("atac_options")
			format(smenu, 63, "Punishments Menu\R2/2")
			format(menuoption[0], 63, "\w1. Time Bomb\R\y%s^n", (option & (1<<7) != (1<<7)) ? "OFF" : "ON")
			format(menuoption[1], 63, "\w2. Blind\R\y%s^n", (option & (1<<8) != (1<<8)) ? "OFF" : "ON")
			format(menuoption[2], 63, "\w3. Rocket\R\y%s^n", (option & (1<<9) != (1<<9)) ? "OFF" : "ON")
			format(menuoption[3], 63, "\w4. Drop\R\y%s^n", (option & (1<<10) != (1<<10)) ? "OFF" : "ON")
			format(menuoption[4], 63, "\w5. Fire\R\y%s^n", (option & (1<<11) != (1<<11)) ? "OFF" : "ON")
			format(menuoption[5], 63, "\w6. Drug\R\y%s^n^n", (option & (1<<12) != (1<<12)) ? "OFF" : "ON")
			format(menuoption[8], 63, "\w9. Back^n")
			format(menuoption[9], 63, "\w0. Exit")
			keys -= (1<<6)|(1<<7)
		}
		case 4:
		{
			new noTAallowed = get_cvar_num("atac_tanotallowedfor")
			format(smenu, 63, "Team Attack Menu")
			format(menuoption[0], 63, "\w1. Team Attack Control\R\y%s^n", get_cvar_num("atac_tacontrol") ? "ON" : "OFF")
			format(menuoption[1], 63, "\w2. Violations\R\y%i^n", get_cvar_num("atac_ta_equal_v"))
			format(menuoption[2], 63, noTAallowed ? "\w3. Not Allowed For\R\y%i SECS^n" : "\w3. Not Allowed For\R\yOFF^n", noTAallowed)
			format(menuoption[3], 63, "\w4. Slay On Max Violations\R\y%s^n", get_cvar_num("atac_slayonmaxtas") ? "ON" : "OFF")
			format(menuoption[4], 63, "\w5. Slapping\R\y%s^n", get_cvar_num("atac_ta_slap") ? "ON" : "OFF")
			format(menuoption[5], 63, "\w6. Mirror Damage\R\y%s^n", get_cvar_num("atac_ta_mirrordmg") ? "ON" : "OFF")
			format(menuoption[6], 63, "\w7. Restore Health\R\y%s^n^n", get_cvar_num("atac_ta_restore") ? "ON" : "OFF")
			format(menuoption[8], 63, "\w9. Back^n")
			format(menuoption[9], 63, "\w0. Exit")
			keys -= (1<<7)
		}
		case 5:
		{
			new bantype[7], banvia = get_cvar_num("atac_banvia"), bantime = get_cvar_num("atac_bantime")
			if(banvia == 1)
				copy(bantype, 6, "AUTHID")
			
			else if(banvia == 2)
				copy(bantype, 6, "IP")
			
			else if(banvia == 3)
				copy(bantype, 6, "KICK")

			format(smenu, 63, "Team Kill Menu")
			format(menuoption[0], 63, "\w1. Team Kill Control\R\y%s^n", get_cvar_num("atac_tkcontrol") ? "ON" : "OFF")
			format(menuoption[1], 63, "\w2. Violations\R\y%i^n", get_cvar_num("atac_tk_before_ban"))
			format(menuoption[2], 63, "\w3. Punishment Menu\R\y%s^n", get_cvar_num("atac_menu") ? "ON" : "OFF")
			format(menuoption[3], 63, "\w4. Banning Type\R\y%s^n", bantype)
			
			if(banvia == 3)
			{
				format(menuoption[4], 63, bantime ? "\d5. Ban Time\R%i MINS^n" : "\d5. Ban Time\RPERMANENT^n", bantime)
				keys -= (1<<4)
			}
			else
				format(menuoption[4], 63, bantime ? "\w5. Ban Time\R\y%i MINS^n" : "\w5. Ban Time\R\yPERMANENT^n", bantime)
			
			format(menuoption[5], 63, "\w6. Save Upon Reconnect\R\y%s^n", get_cvar_num("atac_savetks") ? "ON" : "OFF")
			format(menuoption[6], 63, "\w7. Admins Immune\R\y%s^n", get_cvar_num("atac_admins_immune") ? "ON" : "OFF")
			format(menuoption[7], 63, "\w8. Live Player Status\R\y%s^n^n", get_cvar_num("atac_status") ? "ON" : "OFF")
			format(menuoption[8], 63, "\w9. Back^n")
			format(menuoption[9], 63, "\w0. Exit")
		}
		case 6:
		{
			new bmode = get_cvar_num("atac_bomb_mode")
			if(!bmode)
				keys -= (1<<5)

			format(smenu, 63, "Extra Options Menu")
			format(menuoption[0], 63, "\w1. Slap Time\R\y%g SEC^n", get_cvar_float("atac_slap_freq"))
			format(menuoption[1], 63, "\w2. Slaps\R\y%i^n", get_cvar_num("atac_slap_amount"))
			format(menuoption[2], 63, "\w3. Slapping Power\R\y%i^n", get_cvar_num("atac_slap_power"))
			format(menuoption[3], 63, "\w4. Jail Time\R\y%i SECS^n", get_cvar_num("atac_jail_time"))
			format(menuoption[4], 63, "\w5. Bomb Effects Others\R\y%s^n", bmode ? "ON" : "OFF")
			format(menuoption[5], 63, bmode ? "\w6. Bomb Explosion Radius\R\y%i^n" : "\d6. Bomb Explosion Radius\R%i^n", get_cvar_num("atac_bomb_range"))
			format(menuoption[6], 63, "\w7. Fire Effects Others\R\y%s^n", get_cvar_num("atac_fire_mode") ? "ON" : "OFF")
			format(menuoption[7], 63, "\w8. Name Changing\R\y%s^n^n", get_cvar_num("atac_handlenames") ? "ON" : "OFF")
			format(menuoption[8], 63, "\w9. Back^n")
			format(menuoption[9], 63, "\w0. Exit")
		}
	}
	format(menubody, 511, "\y[ATAC] %s:^n^n%s%s%s%s%s%s%s%s%s%s", smenu, 
		menuoption[0], menuoption[1], menuoption[2], menuoption[3], menuoption[4], menuoption[5], menuoption[6], menuoption[7], menuoption[8], menuoption[9])
	show_menu(id, keys, menubody)
	return PLUGIN_HANDLED
}
//----------------------------------------------------------------------------------------------
public action_atac_set(id, key)
{
	if(MenuPage[id] == 1)
	{
		switch(key)  
		{
			case 0: MenuPage[id] = 2
			case 1: MenuPage[id] = 4
			case 2: MenuPage[id] = 5
			case 3: MenuPage[id] = 6
			case 9:
			{
				// Menu Fix (Popup)
				MenuPage[id] = 0
				return PLUGIN_HANDLED
			}
		}
		// Bypass Update System
		show_atac_set(id)
		return PLUGIN_HANDLED
	}
	if(MenuPage[id] == 2)
	{
		new option = get_cvar_num("atac_options")
		switch(key)
		{
			case 0:
			{
				if(option & (1<<0) != (1<<0))
				{
					option += (1<<0)
					set_cvar_num("atac_options", option)
				}
				else
				{
					option -= (1<<0)
					set_cvar_num("atac_options", option)
				}
			}
			case 1:
			{
				if(option & (1<<1) != (1<<1))
				{
					option += (1<<1)
					set_cvar_num("atac_options", option)
				}
				else
				{
					option -= (1<<1)
					set_cvar_num("atac_options", option)
				}
			}
			case 2:
			{
				if(option & (1<<2) != (1<<2))
				{
					option += (1<<2)
					set_cvar_num("atac_options", option)
				}
				else
				{
					option -= (1<<2)
					set_cvar_num("atac_options", option)
				}
			}
			case 3:
			{
				if(option & (1<<3) != (1<<3))
				{
					option += (1<<3)
					set_cvar_num("atac_options", option)
				}
				else
				{
					option -= (1<<3)
					set_cvar_num("atac_options", option)
				}
			}
			case 4:
			{
				if(option & (1<<4) != (1<<4))
				{
					option += (1<<4)
					set_cvar_num("atac_options", option)
				}
				else
				{
					option -= (1<<4)
					set_cvar_num("atac_options", option)
				}
			}
			case 5:
			{
				if(option & (1<<5) != (1<<5))
				{
					option += (1<<5)
					set_cvar_num("atac_options", option)
				}
				else
				{
					option -= (1<<5)
					set_cvar_num("atac_options", option)
				}
			}
			case 6:
			{
				if(option & (1<<6) != (1<<6))
				{
					option += (1<<6)
					set_cvar_num("atac_options", option)
				}
				else
				{
					option -= (1<<6)
					set_cvar_num("atac_options", option)
				}
			}
			case 7: 
			{
				MenuPage[id] = 3
				// Bypass Update System
				show_atac_set(id)
				return PLUGIN_HANDLED
			}
			case 8: 
			{
				MenuPage[id] = 1
				// Bypass Update System
				show_atac_set(id)
				return PLUGIN_HANDLED
			}
			case 9: 
			{
				// Menu Fix (Popup)
				MenuPage[id] = 0
				return PLUGIN_HANDLED
			}
		}
	}
	if(MenuPage[id] == 3)
	{
		new option = get_cvar_num("atac_options")
		switch(key)
		{
			case 0:
			{
				if(option & (1<<7) != (1<<7))
				{
					option += (1<<7)
					set_cvar_num("atac_options", option)
				}
				else
				{
					option -= (1<<7)
					set_cvar_num("atac_options", option)
				}
			}
			case 1:
			{
				if(option & (1<<8) != (1<<8))
				{
					option += (1<<8)
					set_cvar_num("atac_options", option)
				}
				else
				{
					option -= (1<<8)
					set_cvar_num("atac_options", option)
				}
			}
			case 2:
			{
				if(option & (1<<9) != (1<<9))
				{
					option += (1<<9)
					set_cvar_num("atac_options", option)
				}
				else
				{
					option -= (1<<9)
					set_cvar_num("atac_options", option)
				}
			}
			case 3:
			{
				if(option & (1<<10) != (1<<10))
				{
					option += (1<<10)
					set_cvar_num("atac_options", option)
				}
				else
				{
					option -= (1<<10)
					set_cvar_num("atac_options", option)
				}
			}
			case 4:
			{
				if(option & (1<<11) != (1<<11))
				{
					option += (1<<11)
					set_cvar_num("atac_options", option)
				}
				else
				{
					option -= (1<<11)
					set_cvar_num("atac_options", option)
				}
			}
			case 5:
			{
				if(option & (1<<12) != (1<<12))
				{
					option += (1<<12)
					set_cvar_num("atac_options", option)
				}
				else
				{
					option -= (1<<12)
					set_cvar_num("atac_options", option)
				}
			}
			case 8: 
			{
				MenuPage[id] = 2
				// Bypass Update System
				show_atac_set(id)
				return PLUGIN_HANDLED
			}
			case 9: 
			{
				// Menu Fix (Popup)
				MenuPage[id] = 0
				return PLUGIN_HANDLED
			}
		}
	}
	if(MenuPage[id] == 4)
	{
		switch(key)
		{
			case 0:
			{
				if(get_cvar_num("atac_tacontrol"))
					set_cvar_num("atac_tacontrol", 0)
				
				else
					set_cvar_num("atac_tacontrol", 1)
			}
			case 1:
			{
				new TAequal = get_cvar_num("atac_ta_equal_v")
				if(TAequal + Menu1 > 9 || TAequal > 9)
					set_cvar_num("atac_ta_equal_v", 1)
				
				else
				{	
					TAequal += Menu1
					set_cvar_num("atac_ta_equal_v", TAequal)
				}
			}
			case 2:
			{
				new noTAallowed = get_cvar_num("atac_tanotallowedfor")
				if(noTAallowed + Menu1 > 30 || noTAallowed > 30) 
					set_cvar_num("atac_tanotallowedfor", 0)
				
				else
				{	
					noTAallowed += Menu1
					set_cvar_num("atac_tanotallowedfor", noTAallowed)
				}
			}
			case 3:
			{
				if(get_cvar_num("atac_slayonmaxtas"))
					set_cvar_num("atac_slayonmaxtas", 0)
				
				else
					set_cvar_num("atac_slayonmaxtas", 1) 
			}
			case 4:
			{
				if(get_cvar_num("atac_ta_slap"))
					set_cvar_num("atac_ta_slap", 0)
				
				else
					set_cvar_num("atac_ta_slap", 1)
			}
			case 5:
			{
				if(get_cvar_num("atac_ta_mirrordmg"))
					set_cvar_num("atac_ta_mirrordmg", 0)
				
				else
					set_cvar_num("atac_ta_mirrordmg", 1)
			}
			case 6:
			{
				if(get_cvar_num("atac_ta_restore"))
					set_cvar_num("atac_ta_restore", 0)
				
				else
					set_cvar_num("atac_ta_restore", 1)
			}
			case 8:
			{
				MenuPage[id] = 1
				// Bypass Update System
				show_atac_set(id)
				return PLUGIN_HANDLED
			}
			case 9: 
			{
				// Menu Fix (Popup)
				MenuPage[id] = 0
				return PLUGIN_HANDLED
			}
		}
	}
	if(MenuPage[id] == 5)
	{
		switch(key)
		{
			case 0:
			{
				if(get_cvar_num("atac_tkcontrol"))
					set_cvar_num("atac_tkcontrol", 0)
				
				else
					set_cvar_num("atac_tkcontrol", 1)
			}
			case 1:
			{
				new TKequal = get_cvar_num("atac_tk_before_ban")
				if(TKequal + Menu1 > 30 || TKequal > 30)
					set_cvar_num("atac_tk_before_ban", 1)
				
				else
				{	
					TKequal += Menu1
					set_cvar_num("atac_tk_before_ban", TKequal)
				}
			}
			case 2:
			{
				if(get_cvar_num("atac_menu"))
					set_cvar_num("atac_menu", 0)
				
				else
					set_cvar_num("atac_menu", 1)
			}
			case 3:
			{
				new banvia = get_cvar_num("atac_banvia")
				if(banvia == 1)
					set_cvar_num("atac_banvia", 2)
				
				else if(banvia == 2)
					set_cvar_num("atac_banvia", 3)
				
				else if(banvia == 3)
					set_cvar_num("atac_banvia", 1)
			}
			case 4:
			{
				new bantime = get_cvar_num("atac_bantime")
				if(bantime + Menu30 > 300 || bantime > 300)
					set_cvar_num("atac_bantime", 0)
				
				else
				{	
					bantime += Menu30
					set_cvar_num("atac_bantime", bantime)
				}
			}
			case 5:
			{
				if(get_cvar_num("atac_savetks"))
					set_cvar_num("atac_savetks", 0)
				
				else
					set_cvar_num("atac_savetks", 1)
			}
			case 6:
			{
				if(get_cvar_num("atac_admins_immune"))
					set_cvar_num("atac_admins_immune", 0)
				
				else
					set_cvar_num("atac_admins_immune", 1)
			}
			case 7:
			{
				if(get_cvar_num("atac_status"))
					set_cvar_num("atac_status", 0)
				
				else
					set_cvar_num("atac_status", 1)
			}
			case 8:
			{
				MenuPage[id] = 1
				// Bypass Update System
				show_atac_set(id)
				return PLUGIN_HANDLED
			}
			case 9: 
			{
				// Menu Fix (Popup)
				MenuPage[id] = 0
				return PLUGIN_HANDLED
			}
		}
	}
	if(MenuPage[id] == 6)
	{
		switch(key)
		{
			case 0:
			{
				new Float:slaptime = get_cvar_float("atac_slap_freq")
				if(slaptime + Menu0 > 2.0 || slaptime > 2.0)
					set_cvar_float("atac_slap_freq", 0.1)
				
				else
				{	
					slaptime += Menu0
					set_cvar_float("atac_slap_freq", slaptime)
				}
			}
			case 1:
			{
				new slaps = get_cvar_num("atac_slap_amount")
				if(slaps + Menu1 > 30 || slaps > 30)
					set_cvar_num("atac_slap_amount", 1)
				
				else
				{	
					slaps += Menu1
					set_cvar_num("atac_slap_amount", slaps)
				}
			}
			case 2:
			{
				new spower = get_cvar_num("atac_slap_power")
				if(spower + Menu1 > 30 || spower > 30)
					set_cvar_num("atac_slap_power", 0)
				
				else
				{	
					spower += Menu1
					set_cvar_num("atac_slap_power", spower)
				}
			}
			case 3:
			{
				new jtime = get_cvar_num("atac_jail_time")
				if(jtime + Menu5 > 90 || jtime > 90)
					set_cvar_num("atac_jail_time", 15)
				
				else
				{	
					jtime += Menu5
					set_cvar_num("atac_jail_time", jtime)
				}
			}
			case 4:
			{
				if(get_cvar_num("atac_bomb_mode"))
					set_cvar_num("atac_bomb_mode", 0)
				
				else
					set_cvar_num("atac_bomb_mode", 1)
			}
			case 5:
			{
				new bradius = get_cvar_num("atac_bomb_range")
				if(bradius + Menu250 > 3000 || bradius > 3000)
					set_cvar_num("atac_bomb_range", 250)
				
				else
				{	
					bradius += Menu250
					set_cvar_num("atac_bomb_range", bradius)
				}
			}
			case 6:
			{
				if(get_cvar_num("atac_fire_mode"))
					set_cvar_num("atac_fire_mode", 0)
				
				else
					set_cvar_num("atac_fire_mode", 1)
			}
			case 7:
				set_cvar_num("atac_handlenames", get_cvar_num("atac_handlenames")? 0 : 1)
			case 8:
			{
				MenuPage[id] = 1
				// Bypass Update System
				show_atac_set(id)
				return PLUGIN_HANDLED
			}
			case 9: 
			{
				// Menu Fix (Popup)
				MenuPage[id] = 0
				return PLUGIN_HANDLED
			}
		}
	}
	update_menu()
	return PLUGIN_HANDLED
}
//----------------------------------------------------------------------------------------------
update_menu()
{
	new admins[32], inum
	get_players(admins, inum)

	for(new i = 0; i < inum; ++i) 
		if(MenuPage[admins[i]] > 0) 
			show_atac_set(admins[i])
}