| Freddy2304 |
06-05-2010 13:53 |
[ZP] Regeneration: some bugs
(I've posted it here because I think the bugs have nothing to do with ZP)
First of all, I edited this regeneration plugin because the regeneration was caused by every single hit (10 hits = 10x 10hp/sec - now fixed).
But there is an other bug: when you die during regeneration, you will spawn with 0 hp next round.
Original code:
PHP Code:
#include <amxmodx> #include <fakemeta> #include <zombieplague>
new g_Status, g_Time, g_Amount, g_ZombiePlague, g_Nemesis, g_FirstZombie, g_LastZombie;
public plugin_init() { register_plugin("ZP: Regeneration", "1.2 Final Fixed", "hleV");
g_Status = register_cvar("zp_regeneration", "1"); g_Time = register_cvar("zp_regen_time", "1"); g_Amount = register_cvar("zp_regen_amount", "10"); g_Nemesis = register_cvar("zp_regen_nemesis", "1"); g_FirstZombie = register_cvar("zp_regen_firstzombie", "1"); g_LastZombie = register_cvar("zp_regen_lastzombie", "1");
register_event("Damage", "SetRegeneration", "be", "2>0");
g_ZombiePlague = get_cvar_pointer("zp_on"); }
public SetRegeneration(Client) { if (!g_ZombiePlague || !get_pcvar_num(g_Status) || !is_user_connected(Client) || !is_user_alive(Client) || !zp_get_user_zombie(Client)) return;
new Health = get_user_health(Client);
if (Health < 1) return;
if (!get_pcvar_num(g_Nemesis) && zp_get_user_nemesis(Client)) return;
if (!get_pcvar_num(g_FirstZombie) && zp_get_user_first_zombie(Client)) return;
if (!get_pcvar_num(g_LastZombie) && zp_get_user_last_zombie(Client)) return; if (damagetype & DMG_FALL) return; remove_task(Client); if (get_user_health(Client) < zp_get_zombie_maxhealth(Client)) set_task(get_pcvar_float(g_Time), "Regenerate", Client, _, _, "b"); }
public Regenerate(Client) { if (!g_ZombiePlague || !get_pcvar_num(g_Status) || !is_user_connected(Client) || !is_user_alive(Client)) return;
new Health = get_user_health(Client);
if (Health < 1) return;
new NeededHealth = zp_get_zombie_maxhealth(Client) - Health;
if (NeededHealth <= get_pcvar_num(g_Amount)) { set_pev(Client, pev_health, Health + float(NeededHealth)); remove_task(Client);
return; }
set_pev(Client, pev_health, Health + get_pcvar_float(g_Amount)); }
My version (maybe i included too much but that's not the point):
PHP Code:
#include <amxmodx> #include <fakemeta> #include <zombieplague> #include <hamsandwich> #include <fun> #include <fakemeta_util>
new g_Status, g_Time, g_Amount, g_ZombiePlague, g_Nemesis, g_FirstZombie, g_LastZombie; //new g_Delay
public plugin_init() { register_plugin("ZP: Regeneration", "1.2 Final Fixed", "hleV"); RegisterHam(Ham_TakeDamage, "player", "bacon_takedamage_player"); g_Status = register_cvar("zp_regeneration", "1"); g_Time = register_cvar("zp_regen_time", "1"); //g_Delay = register_cvar("zp_regen_delay", "2"); g_Amount = register_cvar("zp_regen_amount", "10"); g_Nemesis = register_cvar("zp_regen_nemesis", "1"); g_FirstZombie = register_cvar("zp_regen_firstzombie", "1"); g_LastZombie = register_cvar("zp_regen_lastzombie", "1");
//register_event("Damage", "SetRegeneration", "be", "2>0"); g_ZombiePlague = get_cvar_pointer("zp_on"); }
/* public SetRegeneration(Client) { if (!g_ZombiePlague || !get_pcvar_num(g_Status) || !is_user_connected(Client) || !is_user_alive(Client) || !zp_get_user_zombie(Client)) return;
new Health = get_user_health(Client);
if (Health < 1) return;
if (!get_pcvar_num(g_Nemesis) && zp_get_user_nemesis(Client)) return;
if (!get_pcvar_num(g_FirstZombie) && zp_get_user_first_zombie(Client)) return;
if (!get_pcvar_num(g_LastZombie) && zp_get_user_last_zombie(Client)) return;
if (get_user_health(Client) < zp_get_zombie_maxhealth(Client) && !task_exists(Client, 0)) set_task(get_pcvar_float(g_Time), "Regenerate", Client, _, _, "b"); } */
public bacon_takedamage_player(victim, inflictor, attacker, Float:damage, damagetype) { if (!g_ZombiePlague || !get_pcvar_num(g_Status) || !is_user_connected(victim) || !is_user_alive(victim) || !zp_get_user_zombie(victim)) return;
new Health = get_user_health(victim);
if (Health < 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_Time), "Regenerate", victim, _, _, "b"); }
public Regenerate(Client) { if (!g_ZombiePlague || !get_pcvar_num(g_Status) || !is_user_connected(Client) || !is_user_alive(Client)) return;
new Health = get_user_health(Client);
if (Health < 1) return;
new NeededHealth = zp_get_zombie_maxhealth(Client) - Health;
if (NeededHealth <= get_pcvar_num(g_Amount)) { //set_pev(Client, pev_health, Health + float(NeededHealth)); //set_user_health(Client, Health + NeededHealth); fm_set_user_health(Client, Health + NeededHealth); remove_task(Client);
return; }
//set_pev(Client, pev_health, Health + get_pcvar_float(g_Amount)); //set_user_health(Client, Health + get_pcvar_num(g_Amount)); fm_set_user_health(Client, Health + get_pcvar_num(g_Amount)); }
As you can see, I tried several methods to set the health but each of them had bugs.
e.g.
PHP Code:
// 0hp after respawn set_pev(Client, pev_health, Health + float(NeededHealth));
// player dies after respawn when he was killed while regeneration was activ the round before set_user_health(Client, Health + NeededHealth);
// same thing here fm_set_user_health(Client, Health + NeededHealth);
I already used the search function but I couldn't find an answer.
And another request:
Can someone add a delay before regeneration starts. I really don't know how to do that.
e.g.
zombie got damage -> 2 seconds without damage -> regeneration starts
Thank you in advance
Freddy2304
|