/* SwitchMode v0.4 */
/* Руссифицировано */

#include <amxmodx>
#include <amxmisc>

#define PLUGIN "SwitchMode"
#define VERSION "0.4"
#define AUTHOR "ZETA [M|E|N]"

new configini[81],text[65],line,num,i
new fmode[3],chosen_mode[3],plugin[21]
new mode[8],pb,gg,zm,cw,dm,sh,wc,sj
new main_menu,choose_menu

public plugin_init() {
	register_plugin("SwitchMode","0.4","ZETA [M|E|N]")
	register_clcmd("say /mode","func_switch_mode",ADMIN_CVAR,"")
}

public plugin_cfg() {
	get_configsdir(configini,81)
	format(configini,80,"%s/SwitchMode.ini",configini)
	
	main_menu=menu_create("SwitchMode","main_menu_handler")
	
	for(line=0;read_file(configini,line,text,64,num);line++) {
		if(num>0 && text[0]!=';') {
			parse(text,fmode,sizeof(fmode))
			if(pb!=1) {
				if(equali(fmode,"pb")) {
					pb=1;mode[0]=++i
					menu_additem(main_menu,"\wPublic")
				}
			}
			if(gg!=1) {
				if(equali(fmode,"gg")) {
					gg=1;mode[1]=++i
					menu_additem(main_menu,"\wGunGame")
				}
			}
			if(zm!=1) {
				if(equali(fmode,"zm")) {
					zm=1;mode[2]=++i
					menu_additem(main_menu,"\wZombieMod")
				}
			}
			if(cw!=1) {
				if(equali(fmode,"cw")) {
					cw=1;mode[3]=++i
					menu_additem(main_menu,"\wClanWar")
				}
			}
			if(dm!=1) {
				if(equali(fmode,"dm")) {
					dm=1;mode[4]=++i
					menu_additem(main_menu,"\wDeathMatch")
				}
			}
			if(sh!=1) {
				if(equali(fmode,"sh")) {
					sh=1;mode[5]=++i
					menu_additem(main_menu,"\wSuperHero")
				}
			}
			if(wc!=1) {
				if(equali(fmode,"wc")) {
					wc=1;mode[6]=++i
					menu_additem(main_menu,"\wWarCraft")
				}
			}
			if(sj!=1) {
				if(equali(fmode,"sj")) {
					sj=1;mode[7]=++i
					menu_additem(main_menu,"\wSoccerJam")
				}
			}
		}
	}
	menu_setprop(main_menu,MPROP_PERPAGE,0)
}

public func_switch_mode(id,level,cid) {
	if(!cmd_access(id,level,cid,0))
	return PLUGIN_HANDLED
	
	menu_display(id,main_menu,0)
	return PLUGIN_HANDLED
}

public main_menu_handler(id,main_menu,item) {
	item++

	for(i=0;i<8;i++) {
		if(mode[i]==item) {
			if(mode[0]==mode[i]) chosen_mode="pb"
			if(mode[1]==mode[i]) chosen_mode="gg"
			if(mode[2]==mode[i]) chosen_mode="zm"
			if(mode[3]==mode[i]) chosen_mode="cw"
			if(mode[4]==mode[i]) chosen_mode="dm"
			if(mode[5]==mode[i]) chosen_mode="sh"
			if(mode[6]==mode[i]) chosen_mode="wc"
			if(mode[7]==mode[i]) chosen_mode="sj"
		}
	}
	
	choose_menu=menu_create("Действие","choose_menu_handler")
	menu_additem(choose_menu,"Включить")
	menu_additem(choose_menu,"Выключить")
	menu_setprop(choose_menu,MPROP_PERPAGE,0)
	
	menu_display(id,choose_menu,0)
	return PLUGIN_HANDLED
}

public choose_menu_handler(id,choose_menu,item) {
	item++
	
	switch(item) {
		case 1:{
			for(line=0;read_file(configini,line,text,64,num);line++) {
				if(num>0&&text[0]!=';') {
					parse(text,fmode,sizeof(fmode),plugin,sizeof(plugin))
					if(equali(chosen_mode,fmode)) {
						server_cmd("amxx unpause %s",plugin)
					}
				}
			}
			server_cmd("sv_restart 1")
			return PLUGIN_HANDLED
		}
		case 2:{
			for(line=0;read_file(configini,line,text,64,num);line++) {
				if(num>0&&text[0]!=';') {
					parse(text,fmode,sizeof(fmode),plugin,sizeof(plugin))
					if(equali(chosen_mode,fmode)) {
						server_cmd("amxx pause %s",plugin)
					}
				}
			}
			server_cmd("sv_restart 1")
			return PLUGIN_HANDLED
		}
	}
	return PLUGIN_HANDLED
}
