#include <amxmodx>
#include <amxmisc>
#include <fun>
#include <halomod>

#define PLUGIN "HaloMod Healing"
#define VERSION HALOVERSION
#define AUTHOR "Soccdoodcss"

#define healingid(%1) %1
#define unglowid(%1) %1+33

new pGlow, pHeal

public plugin_init()
{
	register_plugin(PLUGIN, VERSION, AUTHOR)
	
	register_event("Damage", "onDamage", "be")
	
	pGlow = register_cvar("halo_glow", "1", FCVAR_SERVER)
	pHeal = register_cvar("halo_heal", "1", FCVAR_SERVER)
}

public onDamage(id)
{
	if(!is_halo_on() || !is_user_alive(id) || !get_pcvar_num(pHeal))
		return PLUGIN_HANDLED
	
	new parm[2]
	parm[0] = id
	parm[1] = get_user_health(id)
	
	user_glow(id, 255,215,0)
	
	if(task_exists(unglowid(id)))
		remove_task(unglowid(id))
	set_task(0.5, "user_unglow", unglowid(id))
	
	if(task_exists(healingid(id)))
		remove_task(healingid(id))
	set_task(5.0, "healing", healingid(id), parm, 2)
	
	return PLUGIN_HANDLED
}

public healing(parm[])
{	
	new id = parm[0]
	if(!is_halo_on() || !is_user_alive(id) || !get_pcvar_num(pHeal))
	{
		user_unglow(id)
		return PLUGIN_HANDLED
	}
	
	new init_health = parm[1]
	new health = get_user_health(id)
	if(health == init_health && health < 100)
	{
		user_glow(id, 255, 255, 255)
		new i_heal = 5
		if(health<=100-i_heal)
			set_user_health(id, health + i_heal)
		
		else
		{
			set_user_health(id, 100)
			user_unglow(id)
			return PLUGIN_HANDLED
			
		}
		parm[1] += i_heal
		set_task(0.1, "healing", healingid(id), parm, 2)
	}
	else
		user_unglow(id)
	
	return PLUGIN_HANDLED
}

public user_glow(id, red, green, blue)
{
	if(is_user_alive(id) && get_pcvar_num(pGlow))
		set_user_rendering(id, kRenderFxGlowShell, red, green, blue, kRenderNormal,25)
}	

public user_unglow(id)
{	
	if(id>32)
		id-=33
	user_glow(id, 0,0,0)
}
