#include <amxmodx>

public plugin_init() 
	register_plugin("restart","1.3","Skillax")
	

new g_playercount,g_botcount
	
public client_connect(id)
{
	if (is_user_bot(id) || is_user_hltv(id))
		g_botcount++
	else
		g_playercount++
}


public check_restart()
{
	new currentdate[12], lastrestarted[12]
	get_time("%d/%m/%Y",currentdate,11)

	if (!vaultdata_exists("lastrestarted")) 
		set_vaultdata("lastrestarted",currentdate)

	get_vaultdata("lastrestarted",lastrestarted,11)
	
	if (!equal(currentdate,lastrestarted)) 
	{
		if (g_playercount == 0)
		{
			set_vaultdata("lastrestarted",currentdate)
			log_amx("Restarting: (Last Restart: %s) (Clients: %d) (Bots: %d)",lastrestarted,g_playercount,g_botcount)
			server_cmd("exit") 
		}
	}
	return PLUGIN_HANDLED
}

public client_disconnect(id)
{
	if (is_user_bot(id) || is_user_hltv(id))
		g_botcount--
	else
		g_playercount--
	set_task (1.0,"check_restart")
}
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang2057\\ f0\\ fs16 \n\\ par }
*/
