#include <amxmodx>
#include <amxmisc>

#define Plugin "Map MOTD"
#define Version "0.1"
#define Author "Doombringer"

#define IS_FILE 1

new cvar, url, file[132]

public plugin_init()
{
	register_plugin(Plugin, Version, Author)
	
	register_clcmd("say", "check_say")
	register_clcmd("say_team", "check_say")
	
	cvar = register_cvar("MM_enabled", "1")	
	url = register_cvar("MM_url", "http://www.mysite.com")
	
	new mapname[64]
	get_mapname(mapname, 63)
	
	#if IS_FILE == 1
	{
		new configsdir[64]	
		get_configsdir(configsdir, 63)
				
		formatex(file, 131,"%s/mapmotd/%s.txt", configsdir, mapname)
	}
	#else
	{	
		new page_url[164]
		get_pcvar_string(url, page_url, 163)
		
		formatex(file, 131,"%s/%s.txt", page_url, mapname)
	}	
	#endif
}

public check_say(id)
{
	if(get_pcvar_num(cvar) < 1)
	return PLUGIN_CONTINUE
	
	new args[32]
	read_args(args, 31)
	
	if(contain(args, "/mm") != -1)
	{
		#if IS_FILE == 1
		if(!file_exists(file))
		{
			client_print(id, print_chat,"Sorry, but there is no map MOTD for this map!")
			return PLUGIN_CONTINUE	
		}
		#endif
		
		show_motd(id, file, "Map MOTD")
	}
	
	return PLUGIN_CONTINUE
}