#include <amxmodx>

#define VERSION "1.0"
new g_Cvar_HE, g_Cvar_FB, g_Cvar_SG, g_Trail;

public plugin_init()
{
    register_plugin("Grenade Trail", VERSION, "xPaw")
    g_Cvar_HE = register_cvar("amx_trail_he", "255000000")
    g_Cvar_FB = register_cvar("amx_trail_fb", "255255255")
    g_Cvar_SG = register_cvar("amx_trail_sg", "000255000")
    register_cvar("amx_trail_ver", VERSION,FCVAR_SERVER)
}

public plugin_precache()
{
    g_Trail = precache_model("sprites/smoke.spr")
}

public grenade_throw(id, gid, wid)
{
	new r, g, b, grenade, color[10]
	switch(wid)
	{
		case CSW_HEGRENADE:	grenade = g_Cvar_HE
		case CSW_FLASHBANG:	grenade = g_Cvar_FB
		case CSW_SMOKEGRENADE:	grenade = g_Cvar_SG
	}
	get_pcvar_string(grenade, color, 9)
	new c = str_to_num(color)
	r = c / 1000000
	c %= 1000000
	g = c / 1000
	b = c % 1000

	message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
	write_byte(TE_BEAMFOLLOW)
	write_short(gid)
	write_short(g_Trail)
	write_byte(10)
	write_byte(5)
	write_byte(r)
	write_byte(g)
	write_byte(b)
	write_byte(192)
	message_end()
}