AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [ZP] Regeneration: some bugs (https://forums.alliedmods.net/showthread.php?t=128796)

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_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 06-07-2010 09:18

Re: [ZP] Regeneration: some bugs
 
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));



Brreaker 06-08-2010 00:58

Re: [ZP] Regeneration: some bugs
 
Why don't you just register ham spawn and set player's health to 100 everytime he spawns?

RedRobster 06-08-2010 01:48

Re: [ZP] Regeneration: some bugs
 
Quote:

Originally Posted by Brreaker (Post 1202901)
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



Brreaker 06-08-2010 05:54

Re: [ZP] Regeneration: some bugs
 
Quote:

Originally Posted by RedRobster (Post 1202929)
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 :)

unnyquee 06-08-2010 05:56

Re: [ZP] Regeneration: some bugs
 
@ 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.

Freddy2304 06-08-2010 11:57

Re: [ZP] Regeneration: some bugs
 
Quote:

Originally Posted by RedRobster (Post 1202929)
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

RedRobster 06-08-2010 12:39

Re: [ZP] Regeneration: some bugs
 
So, you are saying that they respawn with 0 health? As soon as they respawn they are dead again?

Freddy2304 06-08-2010 13:59

Re: [ZP] Regeneration: some bugs
 
set_pev(Client, pev_health, Health + float(NeededHealth));
-> the next round, player spawn with 0hp, the camera is on the ground (like u just died) and you can't do anything even with our code

set_user_health(Client, Health + NeededHealth);
and
fm_set_user_health(Client, Health + NeededHealth);
-> player dies after respawn when he was killed (e.g. by slay/slap/napalm nade). But they respawn immediately and everything is normal

Both while regeneration was activ the round before and they were killed.

Brreaker 06-09-2010 01:49

Re: [ZP] Regeneration: some bugs
 
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...


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

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