#include <amxmodx>
#include <amxmisc>

#define PLUGIN "[ZP] Server Cvars"
#define VERSION "1.0"
#define AUTHOR "Felix_Font"

#define ADMIN_FLAG ADMIN_RCON

new enable, restart, cfgdir[32];

public plugin_init() 
{
	register_plugin(PLUGIN, VERSION, AUTHOR);
	register_clcmd("zp_cvars_rr","console_load");
	enable =	register_cvar("zp_cvars_enable", "1");
	restart =	register_cvar("zp_cvars_restart", "1");
	get_configsdir(cfgdir, charsmax(cfgdir))
}

public plugin_cfg()
{
	if(get_pcvar_num(enable) == 1)
	{
		server_cmd("exec %s/zp_cvars.cfg", cfgdir)
	}
	else
	{
		console_print(0, "Config zp_cvars.cfg not loaded. Load cvars disabled!")
	}
	return PLUGIN_CONTINUE;
}
	
public console_load(id)
{
	if(get_pcvar_num(enable) == 1)
	{	
		if(get_pcvar_num(restart) == 1)
		{
			if (get_user_flags(id) & ADMIN_FLAG)
			{
				server_cmd("exec %s/zp_cvars.cfg", cfgdir)
				console_print(0, "[Cvars] zp_cvars.cfg restart by admin!")
				console_print(id, "[Cvars] zp_cvars.cfg successfully restarted")
			}
			else
			{
				console_print(id, "[Cvars] You are not admin! After 3 unsuccessful attempt to execute a command for the administrator you will be banned!")
			}
		}
		else
		{
			console_print(0, "[Cvars] Restart cvars not enabled (OFF)")
		}
	}
	else
	{
		console_print(id, "[Cvars] Plugin not enabled (OFF)")
	}
	return PLUGIN_CONTINUE;
}