Guest User

Untitled

a guest
Jan 2nd, 2014
361
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.55 KB | None | 0 0
  1. #include braxi\_dvar;
  2.  
  3. init( modVers )
  4. {
  5. addDvar( "pi_hb", "plugin_healthbar_enable", 1, 0, 1, "int" );
  6. if( !level.dvar["pi_hb"] )
  7. return;
  8.  
  9. addDvar( "pi_hb_show", "plugin_healthbar_show", 2, 0, 2, "int" ); //0 = Jumpers only | 1 = Activator Only | 2 = Everybody
  10. addDvar( "pi_hb_counter", "plugin_healthbar_counter", 1, 0, 1, "int" ); //Health: 100
  11. addDvar( "pi_hb_col", "plugin_healthbar_color", 1, 0, 1, "int" ); //change color: full = green; low = red
  12.  
  13. precacheShader( "white" );
  14.  
  15. while(1)
  16. {
  17. level waittill( "player_spawn", player );
  18. if( level.dvar["pi_hb_show"] == 0 && player.pers["team"] != "allies" )
  19. continue;
  20. if( level.dvar["pi_hb_show"] == 1 && player.pers["team"] != "axis" )
  21. continue;
  22.  
  23. player thread CreateHealthBar();
  24. player thread RemoveHealthbarOn( "death" );
  25. player thread RemoveHealthbarOn( "disconnect" );
  26. }
  27. }
  28.  
  29. CreateHealthBar()
  30. {
  31. wait 0.5;
  32. self RemoveHealthBar();
  33.  
  34. self.hb_bg = NewClientHudElem( self );
  35. self.hb_bg.alignX = "center";
  36. self.hb_bg.alignY = "bottom";
  37. self.hb_bg.horzalign = "center";
  38. self.hb_bg.vertalign = "bottom";
  39. self.hb_bg.x = 0;
  40. self.hb_bg.y = -35;
  41. self.hb_bg.alpha = 1;
  42. self.hb_bg.color = (0,0,0);
  43. self.hb_bg.foreground = false;
  44. self.hb_bg.hideWhenInMenu = true;
  45. self.hb_bg setShader( "white", 250, 16 );
  46.  
  47. self.hb_fg = NewClientHudElem( self );
  48. self.hb_fg.alignX = "center";
  49. self.hb_fg.alignY = "bottom";
  50. self.hb_fg.horzalign = "center";
  51. self.hb_fg.vertalign = "bottom";
  52. self.hb_fg.x = 0;
  53. self.hb_fg.y = -36;
  54. self.hb_fg.alpha = 1;
  55. self.hb_fg.color = (0,1,0);
  56. self.hb_fg.foreground = true;
  57. self.hb_fg.hideWhenInMenu = true;
  58. self.hb_fg setShader( "white", 250, 14 );
  59.  
  60. if( level.dvar["pi_hb_counter"] )
  61. {
  62. self.hb_value = NewClientHudElem( self );
  63. self.hb_value.alignX = "center";
  64. self.hb_value.alignY = "bottom";
  65. self.hb_value.horzalign = "center";
  66. self.hb_value.vertalign = "bottom";
  67. self.hb_value.x = 0;
  68. self.hb_value.y = -36;
  69. self.hb_value.font = "default";
  70. self.hb_value.fontscale = 1.4;
  71. self.hb_value.alpha = 1;
  72. self.hb_value.foreground = true;
  73. self.hb_value.color = (1,1,1);
  74. self.hb_value.glowalpha = 1;
  75. self.hb_value.glowcolor = (1,0,0);
  76. self.hb_value.hideWhenInMenu = true;
  77. self.hb_value.label = &"Health: &&1";
  78. self.hb_value setValue( self.health );
  79. }
  80.  
  81. while(1)
  82. {
  83. wait 0.2;
  84. if( !isDefined( self.hb_fg ) )
  85. return;
  86.  
  87. if( isDefined( self.hb_value ) )
  88. self.hb_value setValue( self.health );
  89.  
  90. self.hb_fg ScaleOverTime( 0.2, int(self.health/self.maxhealth*250), 14 );
  91. if( level.dvar["pi_hb_col"] )
  92. self.hb_fg.color = (1-(self.health/self.maxhealth),self.health/self.maxhealth,0);
  93. }
  94. }
  95.  
  96. RemoveHealthbarOn( until )
  97. {
  98. if( !isDefined( until ) || until == "" || until == " " || !isDefined( self ) || !isPlayer( self ) )
  99. return;
  100.  
  101. self waittill( until );
  102. self thread RemoveHealthbar();
  103. }
  104.  
  105. RemoveHealthBar()
  106. {
  107. if( !isDefined( self ) || !isPlayer( self ) )
  108. return;
  109.  
  110. if( isDefined( self.hb_bg ) )
  111. self.hb_bg destroy();
  112.  
  113. if( isDefined( self.hb_fg ) )
  114. self.hb_fg destroy();
  115.  
  116. if( isDefined( self.hb_value ) )
  117. self.hb_value destroy();
  118. }
Advertisement
Add Comment
Please, Sign In to add comment