Raised This Month: $ Target: $400
 0% 

[ZP] Regeneration: some bugs


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Freddy2304
Junior Member
Join Date: Dec 2006
Old 06-05-2010 , 13:53   [ZP] Regeneration: some bugs
Reply With Quote #1

(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_Statusg_Timeg_Amountg_ZombiePlagueg_Nemesisg_FirstZombieg_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(Clientpev_healthHealth float(NeededHealth));
        
remove_task(Client);

        return;
    }

    
set_pev(Clientpev_healthHealth 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_Statusg_Timeg_Amountg_ZombiePlagueg_Nemesisg_FirstZombieg_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(victiminflictorattackerFloat:damagedamagetype)
{
    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(victim0))
        
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(ClientHealth 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(ClientHealth 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(Clientpev_healthHealth float(NeededHealth));

// player dies after respawn when he was killed while regeneration was activ the round before
set_user_health(ClientHealth NeededHealth);

// same thing here
fm_set_user_health(ClientHealth 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
Freddy2304 is offline
Freddy2304
Junior Member
Join Date: Dec 2006
Old 06-07-2010 , 09:18   Re: [ZP] Regeneration: some bugs
Reply With Quote #2

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_Statusg_Timeg_Delayg_Amountg_ZombiePlagueg_Nemesis,  g_FirstZombieg_LastZombiebool: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(victiminflictorattacker,  Float:damagedamagetype)
{
    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(victim0))
        {
            
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(victimplayerhp[victim] + NeededHealth);
        
remove_task(victim);

        return;
    }
    
set_user_health(victimplayerhp[victim] + get_pcvar_num(g_Amount));

Freddy2304 is offline
Brreaker
Senior Member
Join Date: Oct 2009
Location: Constanta, Romania
Old 06-08-2010 , 00:58   Re: [ZP] Regeneration: some bugs
Reply With Quote #3

Why don't you just register ham spawn and set player's health to 100 everytime he spawns?
__________________
There are 10 kinds of people.Those who understand binary, and those who don't.
Also, for those who understand binary, there is a donation tab too!
No steam || PM support!
Brreaker is offline
Send a message via MSN to Brreaker Send a message via Yahoo to Brreaker
RedRobster
Veteran Member
Join Date: Apr 2010
Location: Your Closet
Old 06-08-2010 , 01:48   Re: [ZP] Regeneration: some bugs
Reply With Quote #4

Quote:
Originally Posted by Brreaker View Post
Why don't you just register ham spawn and set player's health to 100 everytime he spawns?
The way to do this is...
PHP Code:
public plugin_init()
{
      
RegisterHamHam_Spawn"player""Player_Spawn")
}

public 
Player_Spawn(id)
{    
      if(
cs_get_user_team == CS_TEAM_T && is_user_aliveid ) ) //Will only do it to Ts (Zombies if I remember correctly). Second thing is just an extra check, won't hurt to have it).
              
set_user_healthid100 //100 or w/e you want starting health to be


Last edited by RedRobster; 06-08-2010 at 01:54.
RedRobster is offline
Brreaker
Senior Member
Join Date: Oct 2009
Location: Constanta, Romania
Old 06-08-2010 , 05:54   Re: [ZP] Regeneration: some bugs
Reply With Quote #5

Quote:
Originally Posted by RedRobster View Post
The way to do this is...
PHP Code:
public plugin_init()
{
      
RegisterHamHam_Spawn"player""Player_Spawn")
}

public 
Player_Spawn(id)
{    
      if(
cs_get_user_team == CS_TEAM_T && is_user_aliveid ) ) //Will only do it to Ts (Zombies if I remember correctly). Second thing is just an extra check, won't hurt to have it).
              
set_user_healthid100 //100 or w/e you want starting health to be

is_user_alive is not needed, everytime you spawn the player, he is alive, also you need to return HAM_IGNORED
__________________
There are 10 kinds of people.Those who understand binary, and those who don't.
Also, for those who understand binary, there is a donation tab too!
No steam || PM support!

Last edited by Brreaker; 06-08-2010 at 05:58.
Brreaker is offline
Send a message via MSN to Brreaker Send a message via Yahoo to Brreaker
Freddy2304
Junior Member
Join Date: Dec 2006
Old 06-08-2010 , 11:57   Re: [ZP] Regeneration: some bugs
Reply With Quote #6

Quote:
Originally Posted by RedRobster View Post
The way to do this is...
PHP Code:
public plugin_init()
{
      
RegisterHamHam_Spawn"player""Player_Spawn")
}

public 
Player_Spawn(id)
{    
      if(
cs_get_user_team == CS_TEAM_T && is_user_aliveid ) ) //Will only do it to Ts (Zombies if I remember correctly). Second thing is just an extra check, won't hurt to have it).
              
set_user_healthid100 //100 or w/e you want starting health to be

Sorry, but i can't see why i should need this code.

i tested it but it changed nothing. The bugs still exist
__________________
Freddy2304 is offline
Brreaker
Senior Member
Join Date: Oct 2009
Location: Constanta, Romania
Old 06-09-2010 , 01:49   Re: [ZP] Regeneration: some bugs
Reply With Quote #7

PHP Code:
public plugin_init()
{
      
RegisterHamHam_Spawn"player""Player_Spawn")
}

public 
Player_Spawn(id)
{    
      if(
cs_get_user_team == CS_TEAM_T && is_user_aliveid ) )  {
              
ExecuteHamB(Ham_CS_RoundRespawnid//respawn again the player maybe?
              
set_user_healthid100 //100 or w/e you want starting health 
              
}


not sure...
__________________
There are 10 kinds of people.Those who understand binary, and those who don't.
Also, for those who understand binary, there is a donation tab too!
No steam || PM support!
Brreaker is offline
Send a message via MSN to Brreaker Send a message via Yahoo to Brreaker
Freddy2304
Junior Member
Join Date: Dec 2006
Old 06-09-2010 , 08:21   Re: [ZP] Regeneration: some bugs
Reply With Quote #8

now i get that error:
[IMG]http://img121.**************/img121/5189/errorbh.jpg[/IMG]
__________________
Freddy2304 is offline
Freddy2304
Junior Member
Join Date: Dec 2006
Old 06-16-2010 , 19:38   Re: [ZP] Regeneration: some bugs
Reply With Quote #9

Original version by hleV - ZP: Regeneration

----------

Here is my final version:

* all bugs fixed (i hope )
* delay added
* no regeneration after fall damage

new CVar

* zp_regen_delay <#> - time after regeneration starts (default: 2)



PHP Code:
#include <amxmodx>
#include <fakemeta>
#include <zombieplague>
#include <hamsandwich>
#include <cstrike>

new g_Statusg_Timeg_Delayg_Amountg_ZombiePlagueg_Nemesisg_FirstZombieg_LastZombiebool:gamestarted=false;
new 
playerhp[33], playerhpOld[33], gotdamage[33];

public 
plugin_init()
{
    
register_plugin("ZP: Regeneration""1.3""hleV (edited by Freddy)");
    
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(victiminflictorattackerFloat:damagedamagetype)
{
    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(victim0))
        {
            
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 || !(cs_get_user_team(victim)==CS_TEAM_T))
    {
        
remove_task(victim);
        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_pev(victimpev_healthplayerhp[victim] + float(NeededHealth)); //set_user_health(victim, playerhp[victim] + NeededHealth);
        
remove_task(victim);
        return;
    }
    
set_pev(victimpev_healthplayerhp[victim] + get_pcvar_float(g_Amount)); //set_user_health(victim, playerhp[victim] + get_pcvar_num(g_Amount));

Attached Files
File Type: sma Get Plugin or Get Source (zp_regeneration.sma - 393 views - 3.0 KB)
__________________

Last edited by Freddy2304; 06-16-2010 at 21:39.
Freddy2304 is offline
unnyquee
Senior Member
Join Date: Jun 2009
Location: Constanta, Romania
Old 06-08-2010 , 05:56   Re: [ZP] Regeneration: some bugs
Reply With Quote #10

@ Brreaker: wrong + wrong

is_user_alive is needed to return the actual spawn event, and he doesn't need to return anything since he didn't do that before the check / in check.
__________________
unnyquee is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 05:16.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode