Raised This Month: $51 Target: $400
 12% 

Can you fix this plugin, so it doesn't kill players at the beginning of the round?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
GlobalPlague
Senior Member
Join Date: Feb 2016
Location: Pluto
Old 03-14-2022 , 11:07   Can you fix this plugin, so it doesn't kill players at the beginning of the round?
Reply With Quote #1

Hello. This plugin is about health regeneration regarding all players on the server. It's about constant health regeneration, until the amount of the player's health reaches the maximum according to the settings of the ZP mod itself:

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

new g_Statusg_Timeg_Amountg_ZombiePlagueg_Nemesisg_FirstZombieg_LastZombieg_heal

new const health_sound[] = "zb/zombi_heal.wav"

public plugin_init()
{
    
register_plugin("ZP: Regeneration""1.3 Fix bug""hleV")

    
g_Status register_cvar("zp_regeneration""1")                //on/off
    
g_Time register_cvar("zp_regen_time""1")                //vpema perena
    
g_Amount register_cvar("zp_regen_amount""10")            //ckolko hp gavat npu perene
    
g_Nemesis register_cvar("zp_regen_nemesis""1")         //perenutca lu nemesis
    
g_FirstZombie register_cvar("zp_regen_firstzombie""1")     //perenutca lu 1 zombu
    
g_LastZombie register_cvar("zp_regen_lastzombie""1")     //perenutca lu last zombu

    
register_event("Damage""SetRegeneration""be""2>0")

    
g_ZombiePlague get_cvar_pointer("zp_on")
}

public 
plugin_precache() 

    
engfunc(EngFunc_PrecacheSoundhealth_sound)
        
g_heal precache_model("sprites/cso_heal.spr"


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))
        
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 pev(Clientpev_health)

    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))

        
engfunc(EngFunc_EmitSoundClientCHAN_BODYhealth_sound1.0ATTN_NORM0PITCH_NORM)

        new 
origin[3
        
get_user_origin(Client,origin

        
message_begin(MSG_BROADCAST,SVC_TEMPENTITY
        
write_byte(TE_SPRITE
        
write_coord(origin[0]) 
        
write_coord(origin[1]) 
        
write_coord(origin[2]+=30
        
write_short(g_heal
        
write_byte(8
        
write_byte(255
        
message_end() 

When players join the server, the plugin works perfectly during the first round. However, once the first round is finished, at the beginning of the next round, everyone will be dead, no one will be able to move, and when you press TAB no one is shown as "DEAD".

When this problem happens after the first round, in the beginning of the second round, everyone is spawned already dead, and has -1 health.

This option "g_Amount = register_cvar("zp_regen_amount", "10")" suggests the amount of HP per second is 10. However, it's 1000-2000, because the plugin works ultra-fast, and the 10hp are coming multiple times per second, not only one time per second.

This sound: "new const health_sound[] = "zb/zombi_heal.wav"" is never finished. You hear only the first fraction of the first second, after which it repeats only the first fraction of the second, but never finishes the whole sound. This explains that the plugin works ultra-fast, and there is no time for the sound of giving 10hp to be finished, because the next 10hp is given even before the sound finishes.

The sound has to be played once per received 10hp. Since you don't receive 10hp per second, but around 1000-2000hp per second, the sound is repeated 1000-2000 times per second.

The same goes for the .spr file that comes out of you when you receive 10hp. Instead of your model releasing one sprite per second, it releases thousands of sprites per second.

I think this 'ultra-fast' bug is causing the problem.

Do you understand what I'm trying to explain? If you have a zombie mod, i recommend you to test the plugin, so you can understand what I'm talking about.

If you don't know how to fix the problem, just tell me. I already know how to have regeneration for all zombies, however, i have to add separated codes to each .sma file of each zombie, which means that if i want to disable the regeneration, i will have to edit all zombie classes, instead of just putting ";" before the name of the regeneration plugin i presented in this thread. I prefer to have one plugin controlling the HP of all zombies, instead of having to individually interfere in every single .sma file each time i want to change the regeneration.

I know my English is not good. If you don't understand me, just say it, and i will try to explain it in better way.
GlobalPlague is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 03-15-2022 , 15:26   Re: Can you fix this plugin, so it doesn't kill players at the beginning of the round
Reply With Quote #2

I straight up ignored all the text you wrote because is longer than the code itself and decided to read the entire code instead.

All I can say is that the plugin is terrible.

Ignoring all useless checks and poor coding, the main problem lies here:

Code:
if(get_user_health(Client) < zp_get_zombie_maxhealth(Client))         set_task(get_pcvar_float(g_Time), "Regenerate", Client, _, _, "b") }

This piece of code will initiate a repeating function that regenerates the player's health every time he takes damage.

So, if someone shoots 30 bullets at you, this wonderful plugin will initiate 30x times the regeneration function that will be called each second => 30 times per second => 30x times the amount of healing set in the cvar.

A simple solution would be to just do "remove_task(Client)" before activating the task, but the smart thing to do is using "set_task" just once when the player joins the server and simply check if he's alive and the health is less than needed.

Is there a reason to activate the task every time the player takes damage?
__________________

Last edited by OciXCrom; 03-15-2022 at 15:26.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
GlobalPlague
Senior Member
Join Date: Feb 2016
Location: Pluto
Old 03-15-2022 , 16:39   Re: Can you fix this plugin, so it doesn't kill players at the beginning of the round
Reply With Quote #3

Quote:
Originally Posted by OciXCrom View Post
I straight up ignored all the text you wrote because is longer than the code itself and decided to read the entire code instead.

All I can say is that the plugin is terrible.

Ignoring all useless checks and poor coding, the main problem lies here:

Code:
if(get_user_health(Client) < zp_get_zombie_maxhealth(Client))         set_task(get_pcvar_float(g_Time), "Regenerate", Client, _, _, "b") }

This piece of code will initiate a repeating function that regenerates the player's health every time he takes damage.

So, if someone shoots 30 bullets at you, this wonderful plugin will initiate 30x times the regeneration function that will be called each second => 30 times per second => 30x times the amount of healing set in the cvar.

A simple solution would be to just do "remove_task(Client)" before activating the task, but the smart thing to do is using "set_task" just once when the player joins the server and simply check if he's alive and the health is less than needed.

Is there a reason to activate the task every time the player takes damage?
Hello, OciXCrom. Thanks for trying to help me. Yes, the plugin is terrible.

I found a better and simpler alternative. I will just use the health regeneration codes used in the code of the Regeneration zombie, and i will transfer them to the codes of all other zombie classes i have in my ZM server.

I no longer need help to fix the problems this plugin causes, because i will use other methods.

"Is there a reason to activate the task every time the player takes damage?"

No.
GlobalPlague is offline
Supremache
Veteran Member
Join Date: Sep 2019
Location: Egypt
Old 03-18-2022 , 11:31   Re: Can you fix this plugin, so it doesn't kill players at the beginning of the round
Reply With Quote #4

I created regeneration class for my server, check it:

PHP Code:
public bb_zombie_class_setidiClass )
{
    if( 
iClass == g_szZombie][ ] && !task_existsid TASK_REGENERATION ) )
    {
        
set_task10.0"@Regenerate"id TASK_REGENERATION, .flags "b" )
    }
}

@
Regenerateid )
{
    
id -= TASK_REGENERATION;
    
    new 
iOrigin], iHealth pevidpev_health );
    
    if( !
is_user_aliveid ) || !zp_get_user_zombieid ) || bb_get_user_zombie_classid ) != g_szZombie][ ] || iHealth <= g_iCvarRegHealth ] )
    {
        
remove_taskid TASK_REGENERATION )
        return;
    }
    
    if( 
iHealth g_iCvarRegMaxHealth ] )
    {
        
set_pevidpev_healthfloatminiHealth g_iCvarRegHealth ], g_iCvarRegMaxHealth ] ) )
        
client_cmd(id"spk %s"szHealthSound );
        
        
set_hudmessage2120177, -1.00.110.05.01.01.0, -)
        
show_hudmessageid"== REGENERATOR ==^n!!!Regeneration: +%i HP Gained!!!"floatroundg_iCvarRegHealth ] ) );
        
        
get_user_originid iOrigin );
        
        
message_beginMSG_BROADCAST,SVC_TEMPENTITY );
        
write_byteTE_SPRITE );
        
write_coordiOrigin] );
        
write_coordiOrigin] );
        
write_coordiOrigin] += 40 );
        
write_shortg_iHealthSprite );
        
write_byte);
        
write_byte255 );
        
message_end( );
        
        
SetScreenFadeid0255075 )
    }

__________________
Youtube.com/Supremache

Bank System [Nvault - SQL Support]
VIP System
  • If you think it's that simple, then do it yourself.

Last edited by Supremache; 03-18-2022 at 16:10.
Supremache is offline
GlobalPlague
Senior Member
Join Date: Feb 2016
Location: Pluto
Old 03-21-2022 , 10:49   Re: Can you fix this plugin, so it doesn't kill players at the beginning of the round
Reply With Quote #5

Quote:
Originally Posted by Supremache View Post
I created regeneration class for my server, check it:

PHP Code:
public bb_zombie_class_setidiClass )
{
    if( 
iClass == g_szZombie][ ] && !task_existsid TASK_REGENERATION ) )
    {
        
set_task10.0"@Regenerate"id TASK_REGENERATION, .flags "b" )
    }
}

@
Regenerateid )
{
    
id -= TASK_REGENERATION;
    
    new 
iOrigin], iHealth pevidpev_health );
    
    if( !
is_user_aliveid ) || !zp_get_user_zombieid ) || bb_get_user_zombie_classid ) != g_szZombie][ ] || iHealth <= g_iCvarRegHealth ] )
    {
        
remove_taskid TASK_REGENERATION )
        return;
    }
    
    if( 
iHealth g_iCvarRegMaxHealth ] )
    {
        
set_pevidpev_healthfloatminiHealth g_iCvarRegHealth ], g_iCvarRegMaxHealth ] ) )
        
client_cmd(id"spk %s"szHealthSound );
        
        
set_hudmessage2120177, -1.00.110.05.01.01.0, -)
        
show_hudmessageid"== REGENERATOR ==^n!!!Regeneration: +%i HP Gained!!!"floatroundg_iCvarRegHealth ] ) );
        
        
get_user_originid iOrigin );
        
        
message_beginMSG_BROADCAST,SVC_TEMPENTITY );
        
write_byteTE_SPRITE );
        
write_coordiOrigin] );
        
write_coordiOrigin] );
        
write_coordiOrigin] += 40 );
        
write_shortg_iHealthSprite );
        
write_byte);
        
write_byte255 );
        
message_end( );
        
        
SetScreenFadeid0255075 )
    }

Is this code for a specific zombie class plugin, or will it work for any zombie class plugin, if i put in the in .sma file of the zombie classes i want to be able to regeneratet heir health?
GlobalPlague is offline
Supremache
Veteran Member
Join Date: Sep 2019
Location: Egypt
Old 03-21-2022 , 17:47   Re: Can you fix this plugin, so it doesn't kill players at the beginning of the round
Reply With Quote #6

I gave you an example of creating a regeneration zombie class but if you did copy/paste will get error messages
__________________
Youtube.com/Supremache

Bank System [Nvault - SQL Support]
VIP System
  • If you think it's that simple, then do it yourself.

Last edited by Supremache; 03-21-2022 at 20:52.
Supremache is offline
Reply



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 04:36.


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