#include <amxmodx>
#include <amxmisc>

// Plugin Version
#define VERSION	"1.8"

// Define the access for admin commands
#define ACCESS ADMIN_KICK

new Float:g_LastRestart[33];

// Count cvars
new g_Map[32], g_Hostname, g_Time, g_Sound, g_SayText


public plugin_init()
{
	// Register plugin
	register_plugin("Round Restart", VERSION, "God@Dorin");
	
	// Register plugin version
	register_cvar("restart_version", VERSION, FCVAR_SERVER|FCVAR_SPONLY);
	set_cvar_string("restart_version", VERSION);
	
	// Register admin commands
	register_clcmd("say /rrlive","say_restart",ACCESS)
	register_clcmd("say_team /rrlive","say_restart",ACCESS)
	register_clcmd("say /rr","say_restart",ACCESS)
	register_clcmd("say_team /rr","say_restart",ACCESS)
	register_clcmd("say /live","say_restart",ACCESS)
	register_clcmd("say_team /live","say_restart",ACCESS)
	register_clcmd("say /restart","say_restart",ACCESS)
	register_clcmd("say_team /restart","say_restart",ACCESS)
	
	// Register language file
	register_dictionary("round_restart.txt");
	
	// Register plugin cvars
	g_Time = register_cvar("restart_waittime","20.0" )	// # of second between 2 consecutive restarts
	g_Hostname = get_cvar_pointer("hostname")		
	g_Sound = register_cvar("restart_sound", "1")		// 0- Sound Disabled | 1- Vox word Sounds | 2- feelgood.wav sound
	
	g_SayText = get_user_msgid("SayText")
	get_mapname(g_Map, charsmax(g_Map))
}

public say_restart(id,level,cid )
{
	if(!cmd_access(id,level,cid,2))
	{
		return PLUGIN_CONTINUE;
	}
	new Float:Time = get_gametime();
	
	if(Time - g_LastRestart[id] < get_pcvar_float(g_Time))
	{
		client_printc(id,"%L", id, "RR_WAIT");
		return PLUGIN_CONTINUE;
	}
	g_LastRestart[id] = Time;
	
	new hostname[64];
	get_pcvar_string(g_Hostname, hostname, charsmax(hostname));
	
	server_cmd("sv_restart 3")
	client_printc(0, "%L", id, "RR_MSG", hostname)
	client_printc(0, "%L", id, "RR_MSG2", g_Map)
	client_printc(0, "%L", id, "RR_MSG3")
	client_printc(0, "%L", id, "RR_MSG4")
	
	new iSoundMode = get_pcvar_num(g_Sound)
	
	switch( iSoundMode ) {
		case 1: {
			client_cmd(0,"speak ^"loading environment on to your computer^"")
		}
		case 2: { 
			client_cmd(0,"speak ^"loading environment on to your computer^"")
		}
	}
	return PLUGIN_CONTINUE;
}

stock client_printc(const id, const string[], {Float, Sql, Resul,_}:...) {
	
	new msg[191], players[32], count = 1;
	vformat(msg, sizeof msg - 1, string, 3);
	
	replace_all(msg,190,"!g","^4");
	replace_all(msg,190,"!y","^1");
	replace_all(msg,190,"!t","^3");
	
	if(id)
		players[0] = id;
	else
		get_players(players,count,"ch");
	
	new index;
	for (new i = 0 ; i < count ; i++)
	{
		index = players[i];
		message_begin(MSG_ONE_UNRELIABLE, g_SayText,_, index);
		write_byte(index);
		write_string(msg);
		message_end();  
	}  
}
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1048\\ f0\\ fs16 \n\\ par }
*/
