Advertisement
CheezPuff

New Heal Bar by Dias v1.0

Jun 25th, 2019
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 2.68 KB | None | 0 0
  1. #include <amxmodx>
  2. #include <fakemeta>
  3. #include <hamsandwich>
  4. #include <zombieplague>
  5.  
  6. #define PLUGIN "[ZP] Addon: Show Zombie Health"
  7. #define VERSION "1.0"
  8. #define AUTHOR "Dias"
  9.  
  10. new const healthbar_spr[] = "sprites/zb_healthbar.spr"
  11. new g_playerbar[33], g_isAlive[33]
  12. new g_playerMaxHealth[33]
  13.  
  14. public plugin_init()
  15. {
  16.     register_plugin(PLUGIN, VERSION, AUTHOR)
  17.    
  18.     RegisterHam(Ham_Spawn, "player", "ham_spawn_post", 1)
  19.     register_forward(FM_AddToFullPack, "fm_addtofullpack_post", 1)
  20.    
  21.     register_event("ResetHUD", "event_resethud", "be")
  22.     register_event("DeathMsg", "event_death", "a")
  23.     register_event("Health", "event_health", "be")
  24.    
  25.     make_healthbar()
  26. }
  27.  
  28. public make_healthbar()
  29. {
  30.     static playerBar, allocString
  31.     allocString = engfunc(EngFunc_AllocString, "env_sprite")
  32.    
  33.     for( new id = 1; id <= get_maxplayers(); id ++ )
  34.     {
  35.         g_playerbar[id] = engfunc(EngFunc_CreateNamedEntity, allocString)
  36.         playerBar = g_playerbar[id]
  37.        
  38.         if(pev_valid(playerBar))
  39.         {
  40.             set_pev(playerBar, pev_scale, 0.25)
  41.             engfunc(EngFunc_SetModel, playerBar, healthbar_spr)
  42.             set_pev(playerBar, pev_effects, pev(playerBar, pev_effects ) | EF_NODRAW)
  43.         }
  44.     }  
  45. }
  46.  
  47. public plugin_precache()
  48. {
  49.     engfunc(EngFunc_PrecacheModel, healthbar_spr)
  50. }
  51.  
  52. public ham_spawn_post(id)
  53. {
  54.     if(is_user_alive(id))
  55.     {
  56.         g_isAlive[id] = 1
  57.     }
  58. }
  59.  
  60. public zp_user_infected_post(id)
  61. {
  62.     g_playerMaxHealth[id] = get_user_health(id)
  63. }
  64.  
  65. public zp_user_humanized_post(id)
  66. {
  67.     set_pev(g_playerbar[id], pev_effects, pev(g_playerbar[id], pev_effects) | EF_NODRAW)
  68. }
  69.  
  70. public event_resethud(id)
  71. {
  72.     set_pev(g_playerbar[id], pev_effects, pev(g_playerbar[id], pev_effects) | EF_NODRAW)
  73. }
  74.  
  75. public event_death()
  76. {
  77.     new id = read_data(2)
  78.    
  79.     g_isAlive[id] = 0
  80.     set_pev(g_playerbar[id], pev_effects, pev(g_playerbar[id], pev_effects) | EF_NODRAW)
  81. }
  82.  
  83. public event_health(id)
  84. {
  85.     new hp = get_user_health(id)
  86.    
  87.     if(g_playerMaxHealth[id] < hp)
  88.     {
  89.         g_playerMaxHealth[id] = hp
  90.         set_pev(g_playerbar[id], pev_frame, 99.0)
  91.     }
  92.     else
  93.     {
  94.         set_pev(g_playerbar[id], pev_frame, 0.0 + (((hp - 1) * 100) / g_playerMaxHealth[id]))
  95.     }
  96. }
  97.  
  98. public fm_addtofullpack_post(es, e, user, host, host_flags, player, p_set)
  99. {
  100.     if(!player)
  101.         return FMRES_IGNORED
  102.        
  103.     if(!is_user_alive(host) || !is_user_alive(user))
  104.         return FMRES_IGNORED
  105.        
  106.     if(!zp_get_user_zombie(user))
  107.         return FMRES_IGNORED
  108.        
  109.     if(host == user)
  110.         return FMRES_IGNORED
  111.    
  112.     new Float:PlayerOrigin[3]
  113.     pev(user, pev_origin, PlayerOrigin)
  114.                            
  115.     PlayerOrigin[2] += 60.0
  116.                        
  117.     engfunc(EngFunc_SetOrigin, g_playerbar[user], PlayerOrigin)
  118.     set_pev(g_playerbar[user], pev_effects, pev(g_playerbar[user], pev_effects) & ~EF_NODRAW)
  119.  
  120.     return FMRES_HANDLED
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement