#include <amxmodx>
#include <fakemeta>
#include <zombieplague>

#define PLUGIN "Regeneration ZM HP"
#define VERSION "1.0"
#define AUTHOR "heka"

new Float:g_LastThink[33], bool:ready[33]
new cvar_health, cvar_readytime, cvar_time

new const health_sound[] = "zb/zombi_heal.wav"

public plugin_init()
{
        register_plugin(PLUGIN, VERSION, AUTHOR)
        register_forward(FM_PlayerPostThink, "Player_Think", 1)
        cvar_health = register_cvar("zp_health", "200.0") // Сколько хп востонавливать
        cvar_readytime = register_cvar("zp_health_readytime", "2.0") // Сколько ждать до начала регенерации
        cvar_time = register_cvar("zp_health_time", "1.0") // Сколько идет регенирация
}

public plugin_precache() 
{
	engfunc(EngFunc_PrecacheSound, health_sound)
}

public Player_Think(iPlayer)
{
        if(!is_user_alive(iPlayer) || zp_get_user_zombie(iPlayer))
		return
        
        new Float:Velocity[3]
        pev(iPlayer, pev_velocity, Velocity)
        
        if(vector_length(Velocity) > 0)
        {
		ready[iPlayer] = false
			return
        }
        
        new Float:CurTime
        global_get(glb_time, CurTime)
        
        if(!ready[iPlayer])
        {
		ready[iPlayer] = true
		g_LastThink[iPlayer] = CurTime + get_pcvar_float(cvar_readytime)
        }
        
        if(CurTime < g_LastThink[iPlayer])
		return
        
        new Float:health = floatmin(pev(iPlayer, pev_health) + get_pcvar_float(cvar_health), float(zp_get_zombie_maxhealth(iPlayer)))
        set_pev(iPlayer, pev_health, health)
        engfunc(EngFunc_EmitSound, iPlayer, CHAN_BODY, health_sound, 1.0, ATTN_NORM, 0, PITCH_NORM)
        
        g_LastThink[iPlayer] = CurTime + get_pcvar_float(cvar_time)
}
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ ansicpg1251\\ deff0\\ deflang1058{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ f0\\ fs16 \n\\ par }
*/
