Compatible/Suggested Zombie Health Bar

Gameplay Addons
johnnysins2000
Veteran Member
Veteran Member
Pakistan
Posts: 672
Joined: 2 Years Ago
Location: Lahore
Has thanked: 11 times
Been thanked: 10 times
Age: 22
Contact:

Zombie Health Bar

#1

Post by johnnysins2000 » 2 Years Ago

Zombie Health Bar

Description:
  • This Plugin shows Zombie's Health Bar! Enjoy!
Code:
    1. #include <zombie_escape>
    2.  
    3. #define PLUGIN "[ZE] Addon: Show Health Bar"
    4. #define VERSION "1.0"
    5. #define AUTHOR "ZE DEV TEAM"
    6.  
    7. new const healthbar_spr[] = "sprites/zb_healthbar.spr"
    8. new g_playerbar[33] , g_isAlive[33]
    9. new g_playerMaxHealth[33]
    10.  
    11. public plugin_init()
    12. {
    13.     register_plugin(PLUGIN, VERSION, AUTHOR)
    14.    
    15.     RegisterHam(Ham_Spawn, "player", "ham_spawn_post", 1)
    16.     register_forward(FM_AddToFullPack, "fm_addtofullpack_post", 1)
    17.    
    18.     register_event("ResetHUD", "event_resethud", "be")
    19.     register_event("DeathMsg", "event_death", "a")
    20.     register_event("Health", "event_health", "be")
    21.    
    22.     make_healthbar()
    23. }
    24.  
    25. public make_healthbar()
    26. {
    27.     static playerBar, allocString
    28.     allocString = engfunc(EngFunc_AllocString, "env_sprite")
    29.    
    30.     for( new id = 1; id <= get_maxplayers(); id ++ )
    31.     {
    32.         g_playerbar[id] = engfunc(EngFunc_CreateNamedEntity, allocString)
    33.         playerBar = g_playerbar[id]
    34.        
    35.         if(pev_valid(playerBar))
    36.         {
    37.             set_pev(playerBar, pev_scale, 0.25)
    38.             engfunc(EngFunc_SetModel, playerBar, healthbar_spr)
    39.             set_pev(playerBar, pev_effects, pev(playerBar, pev_effects ) | EF_NODRAW)
    40.         }
    41.     }  
    42. }
    43.  
    44. public plugin_precache() engfunc(EngFunc_PrecacheModel, healthbar_spr)
    45.  
    46. public ham_spawn_post(id)
    47. {
    48.     if(is_user_alive(id))
    49.     {
    50.         g_isAlive[id] = 1
    51.     }
    52. }
    53.  
    54. public  ze_user_infected(id)
    55. {
    56.     g_playerMaxHealth[id] = get_user_health(id)
    57. }
    58.  
    59. public ze_user_humanized(id)
    60. {
    61.     set_pev(g_playerbar[id], pev_effects, pev(g_playerbar[id], pev_effects) | EF_NODRAW)
    62. }
    63.  
    64. public client_disconnect(id)
    65. {
    66.     set_pev(g_playerbar[id], pev_effects, pev(g_playerbar[id], pev_effects) | EF_NODRAW)
    67. }
    68.  
    69. public event_resethud(id)
    70. {
    71.     set_pev(g_playerbar[id], pev_effects, pev(g_playerbar[id], pev_effects) | EF_NODRAW)
    72. }
    73.  
    74. public event_death()
    75. {
    76.     new id = read_data(2)
    77.    
    78.     g_isAlive[id] = 0
    79.     set_pev(g_playerbar[id], pev_effects, pev(g_playerbar[id], pev_effects) | EF_NODRAW)
    80. }
    81.  
    82. public event_health(id)
    83. {
    84.     new hp = get_user_health(id)
    85.    
    86.     if(g_playerMaxHealth[id] < hp)
    87.     {
    88.         g_playerMaxHealth[id] = hp
    89.         set_pev(g_playerbar[id], pev_frame, 99.0)
    90.     }
    91.     else
    92.     {
    93.         set_pev(g_playerbar[id], pev_frame, 0.0 + (((hp - 1) * 100) / g_playerMaxHealth[id]))
    94.     }
    95. }
    96.  
    97. public fm_addtofullpack_post(es, e, user, host, host_flags, player, p_set)
    98. {
    99.     if(!player)
    100.         return FMRES_IGNORED
    101.        
    102.     if(!is_user_alive(host) || !is_user_alive(user))
    103.         return FMRES_IGNORED
    104.        
    105.     if(!ze_is_user_zombie(user))
    106.         return FMRES_IGNORED
    107.        
    108.     if(host == user)
    109.         return FMRES_IGNORED
    110.    
    111.     new Float:PlayerOrigin[3]
    112.     pev(user, pev_origin, PlayerOrigin)
    113.                            
    114.     PlayerOrigin[2] += 60.0
    115.                        
    116.     engfunc(EngFunc_SetOrigin, g_playerbar[user], PlayerOrigin)
    117.     set_pev(g_playerbar[user], pev_effects, pev(g_playerbar[user], pev_effects) & ~EF_NODRAW)
    118.  
    119.     return FMRES_HANDLED
    120. }

Installation & Instructions:
  • Simply install it like any plugin and Don't forget to copy sprites in sprite folder

Screenshots:
  • hl 2017-06-21 14-05-13-78.png
Downloads:
Nobody Is That Busy If They Make Time :roll:

User avatar
Spir0x
Veteran Member
Veteran Member
Tunisia
Posts: 633
Joined: 2 Years Ago
Location: Tunisia
Has thanked: 14 times
Been thanked: 7 times
Age: 19
Contact:

#2

Post by Spir0x » 2 Years Ago

Nice Johnny SINS :) RAMADAN :)
I trynna make money, not friends.

johnnysins2000
Veteran Member
Veteran Member
Pakistan
Posts: 672
Joined: 2 Years Ago
Location: Lahore
Has thanked: 11 times
Been thanked: 10 times
Age: 22
Contact:

#3

Post by johnnysins2000 » 2 Years Ago

Spir0x wrote:
2 Years Ago
Nice Johnny SINS :) RAMADAN :)
Happy Ramadan to you too :)
Nobody Is That Busy If They Make Time :roll:

User avatar
Spir0x
Veteran Member
Veteran Member
Tunisia
Posts: 633
Joined: 2 Years Ago
Location: Tunisia
Has thanked: 14 times
Been thanked: 7 times
Age: 19
Contact:

#4

Post by Spir0x » 2 Years Ago

Ty :)
I trynna make money, not friends.

User avatar
Raheem
Mod Developer
Mod Developer
Egypt
Posts: 1972
Joined: 2 Years Ago
Location: Egypt
Has thanked: 32 times
Been thanked: 108 times
Age: 22
Contact:

#5

Post by Raheem » 2 Years Ago

The plugin can be optimized to use ReAPI can you do it?
You don't know? Learn and you will know.

johnnysins2000
Veteran Member
Veteran Member
Pakistan
Posts: 672
Joined: 2 Years Ago
Location: Lahore
Has thanked: 11 times
Been thanked: 10 times
Age: 22
Contact:

#6

Post by johnnysins2000 » 2 Years Ago

Raheem wrote:
2 Years Ago
The plugin can be optimized to use ReAPI can you do it?
IDK how to use ReAPI if I knew how to use reapi i would have done it myself

What things do I need to learn from ReAPI in order to make Code optimized
Nobody Is That Busy If They Make Time :roll:

User avatar
Mohamed Alaa
Mod Developer
Mod Developer
Egypt
Posts: 626
Joined: 2 Years Ago
Location: Egypt
Has thanked: 34 times
Been thanked: 49 times
Age: 19
Contact:

#7

Post by Mohamed Alaa » 2 Years Ago

Examples:

Code: Select all

RegisterHam(Ham_Spawn, "player", "ham_spawn_post", 1)
To --->

Code: Select all

RegisterHookChain(RG_CBasePlayer_Spawn, "ham_spawn_post", 1)
Also it's better to use Ham_Killed (For Ham)/RG_CBasePlayer_Killed (For ReAPI).

If you're going to use ham/reapi, change this

Code: Select all

public event_death()
{
    new id = read_data(2)
   
    g_isAlive[id] = 0
    set_pev(g_playerbar[id], pev_effects, pev(g_playerbar[id], pev_effects) | EF_NODRAW)
}
To --->

Code: Select all

public event_death(killer, .victim = id)
{
     g_isAlive[id] = 0
    set_pev(g_playerbar[id], pev_effects, EF_NODRAW)
}
Want your own mod edition? PM me.
Accepting web projects.
CS 1.6 hosting: powergamingtech.com

johnnysins2000
Veteran Member
Veteran Member
Pakistan
Posts: 672
Joined: 2 Years Ago
Location: Lahore
Has thanked: 11 times
Been thanked: 10 times
Age: 22
Contact:

#8

Post by johnnysins2000 » 2 Years Ago

Jack GamePlay wrote:
2 Years Ago
Examples:

Code: Select all

RegisterHam(Ham_Spawn, "player", "ham_spawn_post", 1)
To --->

Code: Select all

RegisterHookChain(RG_CBasePlayer_Spawn, "ham_spawn_post", 1)
Also it's better to use Ham_Killed (For Ham)/RG_CBasePlayer_Killed (For ReAPI).

If you're going to use ham/reapi, change this

Code: Select all

public event_death()
{
    new id = read_data(2)
   
    g_isAlive[id] = 0
    set_pev(g_playerbar[id], pev_effects, pev(g_playerbar[id], pev_effects) | EF_NODRAW)
}
To --->

Code: Select all

public event_death(killer, .victim = id)
{
     g_isAlive[id] = 0
    set_pev(g_playerbar[id], pev_effects, EF_NODRAW)
}
Thnx Jack for the tip

I will try tomorrow :)
Nobody Is That Busy If They Make Time :roll:

johnnysins2000
Veteran Member
Veteran Member
Pakistan
Posts: 672
Joined: 2 Years Ago
Location: Lahore
Has thanked: 11 times
Been thanked: 10 times
Age: 22
Contact:

#9

Post by johnnysins2000 » 2 Years Ago

Code: Select all

#include <zombie_escape>
 
#define PLUGIN "[ZE] Addon: Show Health Bar"
#define VERSION "1.0"
#define AUTHOR "ZE DEV TEAM"
 
new const healthbar_spr[] = "sprites/zb_healthbar.spr"
new g_playerbar[33] , g_isAlive[33]
new g_playerMaxHealth[33]
 
public plugin_init()
{
    register_plugin(PLUGIN, VERSION, AUTHOR)
   
    RegisterHookChain(RG_CBasePlayer_Spawn, "ham_spawn_post", 1)
    register_forward(FM_AddToFullPack, "fm_addtofullpack_post", 1)
   
    register_event("ResetHUD", "event_resethud", "be")
    register_event("DeathMsg", "event_death", "a")
    register_event("Health", "event_health", "be")
   
    make_healthbar()
}
 
public make_healthbar()
{
    static playerBar, allocString
    allocString = engfunc(EngFunc_AllocString, "env_sprite")
   
    for( new id = 1; id <= get_maxplayers(); id ++ )
    {
        g_playerbar[id] = engfunc(EngFunc_CreateNamedEntity, allocString)
        playerBar = g_playerbar[id]
       
        if(pev_valid(playerBar))
        {
            set_pev(playerBar, pev_scale, 0.25)
            engfunc(EngFunc_SetModel, playerBar, healthbar_spr)
            set_pev(playerBar, pev_effects, pev(playerBar, pev_effects ) | EF_NODRAW)
        }
    }  
}
 
public plugin_precache() engfunc(EngFunc_PrecacheModel, healthbar_spr)
 
public ham_spawn_post(id)
{
    if(is_user_alive(id))
    {
        g_isAlive[id] = 1
    }
}
 
public ze_user_infected(id)
{
    g_playerMaxHealth[id] = get_user_health(id)
}
 
public ze_user_humanized(id)
{
    set_pev(g_playerbar[id], pev_effects, pev(g_playerbar[id], pev_effects) | EF_NODRAW)
}
 
public client_disconnect(id)
{
    set_pev(g_playerbar[id], pev_effects, pev(g_playerbar[id], pev_effects) | EF_NODRAW)
}
 
public event_resethud(id)
{
    set_pev(g_playerbar[id], pev_effects, pev(g_playerbar[id], pev_effects) | EF_NODRAW)
}
 
public event_death(killer, id) 
{ 		
    g_isAlive[id] = 0
    set_pev(g_playerbar[id], pev_effects, EF_NODRAW) 
}
 
public event_health(id)
{
    new hp = get_user_health(id)
   
    if(g_playerMaxHealth[id] < hp)
    {
        g_playerMaxHealth[id] = hp
        set_pev(g_playerbar[id], pev_frame, 99.0)
    }
    else
    {
        set_pev(g_playerbar[id], pev_frame, 0.0 + (((hp - 1) * 100) / g_playerMaxHealth[id]))
    }
}
 
public fm_addtofullpack_post(es, e, user, host, host_flags, player, p_set)
{
    if(!player)
        return FMRES_IGNORED
       
    if(!is_user_alive(host) || !is_user_alive(user))
        return FMRES_IGNORED
       
    if(!ze_is_user_zombie(user))
        return FMRES_IGNORED
       
    if(host == user)
        return FMRES_IGNORED
   
    new Float:PlayerOrigin[3]
    pev(user, pev_origin, PlayerOrigin)
                           
    PlayerOrigin[2] += 60.0
                       
    engfunc(EngFunc_SetOrigin, g_playerbar[user], PlayerOrigin)
    set_pev(g_playerbar[user], pev_effects, pev(g_playerbar[user], pev_effects) & ~EF_NODRAW)
 
    return FMRES_HANDLED
}
raheem or jack check this ? is this optimized now ?
Nobody Is That Busy If They Make Time :roll:

User avatar
Raheem
Mod Developer
Mod Developer
Egypt
Posts: 1972
Joined: 2 Years Ago
Location: Egypt
Has thanked: 32 times
Been thanked: 108 times
Age: 22
Contact:

#10

Post by Raheem » 2 Years Ago

Can you update the plugin as we told you?

Also replace all set_pev with set_entvar
When you find something like: pev_frame just remove pev and make it var so it's: var_frame
When find something like: pev(g_playerbar[user], pev_effects) change to get_entvar(g_playerbar[user], var_effects)

And like that optimize the code and do what we said before and update to new version.
You don't know? Learn and you will know.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest