#include <amxmodx>
#include <reapi>
#define HEALTH_ADD_STEP 5.0 // Сколько добавлять HP за один шаг
#define HEALTH_MAX_STEPS 4 // Сколько шагов для восстановления
#define HEALTH_MAX_LIMIT 100.0 // Максимальное кол-во хп у игрока
enum st
{
count_steps,
Float:origin[3]
}
new g_UserData[33][st];
#define GetButtonIsDuck(%0) (get_entvar(%0, var_button) & IN_DUCK && get_entvar(%0, var_oldbuttons) & IN_DUCK)
public plugin_init()
{
register_plugin("Player Health Regen", "1.1", "neugomon");
RegisterHookChain(RG_CSGameRules_RestartRound, "CSGameRules_RestartRound_Post", true);
RegisterHookChain(RG_CBasePlayer_Spawn, "CBasePlayer_Spawn_Post", true);
RegisterHookChain(RG_CBasePlayer_Killed, "CBasePlayer_Killed_Post", true);
}
public client_putinserver(id)
g_UserData[id][count_steps] = HEALTH_MAX_STEPS;
public CSGameRules_RestartRound_Post()
for(new i = 1; i < sizeof g_UserData; i++)
g_UserData[i][count_steps] = HEALTH_MAX_STEPS;
public CBasePlayer_Spawn_Post(const id)
if(is_user_alive(id))
set_task(1.0, "CheckPlayer", id, .flags = "b");
public CBasePlayer_Killed_Post(const victim, killer)
remove_task(victim);
public CheckPlayer(id)
{
if(!is_user_connected(id))
remove_task(id);
else if(!g_UserData[id][count_steps])
remove_task(id);
else if(GetButtonIsDuck(id))
{
new Float:fOrigin[3];
get_entvar(id, var_origin, fOrigin);
if(
g_UserData[id][origin][0] == fOrigin[0] &&
g_UserData[id][origin][1] == fOrigin[1] &&
g_UserData[id][origin][2] == fOrigin[2]
)
{
new Float:hp = Float:get_entvar(id, var_health);
if(hp < HEALTH_MAX_LIMIT)
{
set_entvar(id, var_health, (hp + HEALTH_ADD_STEP > HEALTH_MAX_LIMIT) ? HEALTH_MAX_LIMIT : hp + HEALTH_ADD_STEP);
if(--g_UserData[id][count_steps] == 0)
remove_task(id);
}
}
g_UserData[id][origin][0] = fOrigin[0];
g_UserData[id][origin][1] = fOrigin[1];
g_UserData[id][origin][2] = fOrigin[2];
}
}