After 2 days of hard work, i was able to add the delay function and the 0hp/kill bug is more or less fixed.
It only occurs when a zombie were slayed or slaped till death (during regeneration)
Now I have 2 request:
- the code badly needs optimizations
- detection of slay and slap (or any other type of damage e.g. napalm grenades) so that the bug is fixed completely
Please explain it very well because my knowledge about pawn is ....
PHP Code:
#include <amxmodx>
#include <fakemeta>
#include <zombieplague>
#include <hamsandwich>
#include <fun>
new g_Status, g_Time, g_Delay, g_Amount, g_ZombiePlague, g_Nemesis, g_FirstZombie, g_LastZombie, bool:gamestarted=false;
new playerhp[33], playerhpOld[33], gotdamage[33];
public plugin_init()
{
register_plugin("ZP: Regeneration", "1.2 Final Fixed (Fixed again!)", "hleV");
register_logevent("logevent_round_end", 2, "1=Round_End");
register_logevent("logevent_round_start", 2, "1=Round_Start");
RegisterHam(Ham_TakeDamage, "player", "bacon_takedamage_player", 1);
g_Status = register_cvar("zp_regeneration", "1");
g_Time = register_cvar("zp_regen_time", "0.1");
g_Delay = register_cvar("zp_regen_delay", "2");
g_Amount = register_cvar("zp_regen_amount", "1");
g_Nemesis = register_cvar("zp_regen_nemesis", "1");
g_FirstZombie = register_cvar("zp_regen_firstzombie", "1");
g_LastZombie = register_cvar("zp_regen_lastzombie", "1");
g_ZombiePlague = get_cvar_pointer("zp_on");
}
public logevent_round_end()
{
gamestarted = false;
}
public logevent_round_start()
{
gamestarted = true;
}
public bacon_takedamage_player(victim, inflictor, attacker, Float:damage, damagetype)
{
if(gamestarted)
{
if (!g_ZombiePlague || !get_pcvar_num(g_Status) || !is_user_connected(victim) || !is_user_alive(victim) || !zp_get_user_zombie(victim))
return;
playerhpOld[victim] = get_user_health(victim);
if (playerhpOld[victim] < 1)
return;
if (!get_pcvar_num(g_Nemesis) && zp_get_user_nemesis(victim))
return;
if (!get_pcvar_num(g_FirstZombie) && zp_get_user_first_zombie(victim))
return;
if (!get_pcvar_num(g_LastZombie) && zp_get_user_last_zombie(victim))
return;
if (damagetype & DMG_FALL)
return;
remove_task(victim);
if (get_user_health(victim) < zp_get_zombie_maxhealth(victim) && !task_exists(victim, 0))
{
set_task(get_pcvar_float(g_Delay), "delay", victim, _, _, "a", 1);
}
}
}
public delay(victim)
{
playerhp[victim] = get_user_health(victim);
if(playerhp[victim] == playerhpOld[victim])
{
gotdamage[victim] = false;
set_task(get_pcvar_float(g_Time), "Regenerate", victim, _, _, "b");
}
}
public Regenerate(victim)
{
if (!g_ZombiePlague || !get_pcvar_num(g_Status) || !is_user_connected(victim) || !is_user_alive(victim) || gotdamage[victim] || !gamestarted)
return;
playerhp[victim] = get_user_health(victim);
if (playerhpOld[victim] < 1)
return;
new NeededHealth = zp_get_zombie_maxhealth(victim) - playerhp[victim];
if (NeededHealth <= get_pcvar_num(g_Amount))
{
set_user_health(victim, playerhp[victim] + NeededHealth);
remove_task(victim);
return;
}
set_user_health(victim, playerhp[victim] + get_pcvar_num(g_Amount));
}