/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>
#include <file>
#include <fun>

#define PLUGIN "Glow Menu"
#define VERSION "1.1"
#define AUTHOR "Demon RR"
#define MAX_COLORS 100

//This plugin allows glowing capablities for all players through the use of a menu.
//All colors for glowing must be in the file "configs/Glowcolors.txt" in the form of
//					Color	RED	GREEN	BLUE
//where Color is the name of the color to appear in the menu
//and RED GREEN BLUE are RGB values between 0 and 255
//each must be on its own seperate line and there should be no empty lines in between colors or at the end of the file


//by default 100 is the maximum amount of colors allowed in. That can be change by changing MAX_COLORS to a different value


//Changelog

//1.1
//changed so file now uses get_configsdir
//added amx_reloadglow to reload the Glowcolors.txt instead of restarting the server
//uses isalnum to for the file reader instead of the ascii characters (doesnt affect anything at all, just less code)
new mGlowMenu // Menu
new mcbGlowMenu // Menu Callback
new ColorStrings[MAX_COLORS][10]
new Colors[MAX_COLORS][3]
new Path[100]

public freadword(file, dest[])
{
	new tempchar
	new c = 0
	fread(file, tempchar, BLOCK_CHAR)
	while(isalnum(tempchar) && (feof(file) == 0))
	{
		dest[c] = tempchar
		c++
		fread(file, tempchar, BLOCK_CHAR)
	}
	return 1
}

public plugin_init() 
{
	/* Menu Glow Menu */
	/* Use menu_display(id, mGlowMenu, 0) to show the menu to an user. */
	mGlowMenu = menu_create("Glow Menu", "mh_GlowMenu")
	mcbGlowMenu = menu_makecallback("mcb_GlowMenu")
	
	get_configsdir(Path, 99)
	add(Path,strlen(Path) + 15, "/Glowcolors.txt")
	new filelen = file_size(Path,1)
	new filehandle = fopen(Path, "r")
	new tempcolor[4]
	new i
	new c
	for(i=0;i < filelen;i++)
	{
		for(c = 0; c <= 3; c++)
		{
			if(c == 0)
			{
				freadword(filehandle, ColorStrings[i])
				menu_additem(mGlowMenu, ColorStrings[i], "ma_GlowMenu", ADMIN_ALL, mcbGlowMenu)
			}
			else
			{
				freadword(filehandle, tempcolor)
				Colors[i][c - 1] = str_to_num(tempcolor)
			}
		}
	}
	menu_additem(mGlowMenu, "Stop glowing", "ma_GlowMenu", ADMIN_ALL, mcbGlowMenu)
	/* Menu End */

	register_plugin(PLUGIN, VERSION, AUTHOR)
	register_concmd("say glow","player_glow",ADMIN_ALL, "Makes you glow a color.")
	register_concmd("amx_reloadglow", "reloadglow", ADMIN_KICK, "Reloads the Glowcolors.txt file")
}

public reloadglow(id, level, cid)
{
	if (!cmd_access(id, level, cid,1))
	{
		return PLUGIN_HANDLED
	}
	new filelen = file_size(Path,1)
	new filehandle = fopen(Path, "r")
	new tempcolor[4]
	new i
	new c
	menu_destroy(mGlowMenu)
	mGlowMenu = menu_create("Glow Menu", "mh_GlowMenu")
	mcbGlowMenu = menu_makecallback("mcb_GlowMenu")
	for(i=0;i < filelen;i++)
	{
		for(c = 0; c <= 3; c++)
		{
			if(c == 0)
			{
				freadword(filehandle, ColorStrings[i])
				menu_additem(mGlowMenu, ColorStrings[i], "ma_GlowMenu", ADMIN_ALL, mcbGlowMenu)
			}
			else
			{
				freadword(filehandle, tempcolor)
				Colors[i][c - 1] = str_to_num(tempcolor)
			}
		}
	}
	menu_additem(mGlowMenu, "Stop glowing", "ma_GlowMenu", ADMIN_ALL, mcbGlowMenu)
	return PLUGIN_HANDLED
}

public player_glow(id)
{
	menu_display(id, mGlowMenu, 0)
	return PLUGIN_HANDLED
}

/* Menu Glow Menu */

public mh_GlowMenu(id, menu, item) 
{
	new iPlayerName[33]
	get_user_name(id, iPlayerName,32)
	if(menu_items(mGlowMenu) == item + 1)
	{
		set_user_rendering(id, kRenderFxNone)
		set_hudmessage(255, 255, 255, 0.02, 0.54, 0, 6.0, 12.0)
		show_hudmessage(0, "%s is no longer glowing!", iPlayerName)
	}
	else
	{
		set_user_rendering(id, kRenderFxGlowShell,Colors[item][0],Colors[item][1],Colors[item][2],kRenderNormal,15)
		set_hudmessage(Colors[item][0],Colors[item][1],Colors[item][2], 0.02, 0.54, 0, 6.0, 12.0)
		show_hudmessage(0, "%s is glowing %s!",iPlayerName, ColorStrings[item])
	}
	/* This event is called when someone presses a key on this menu */
}
public ma_GlowMenu(id) {
	/* This event is called when an item was selected */
}

public mcb_GlowMenu(id, menu, item) {
	/* This is the callback-event, here you can set items enabled or disabled. */
	/* If you want to enable an item, use: return ITEM_ENABLED */
	/* If you want to disable an item, use: return ITEM_DISABLED */
}


public client_putinserver(id)
{
	set_task(20.0, "announce_glow",id)
}

public announce_glow(id)
{
	client_print(id, print_chat, "This server is running GLOW plugin. Say 'glow' to start glowing.")
}
