Answered Creating health bar in bo3

CabCon

Head Administrator
Staff member
Head Staff Team
Messages
4,998
Reaction score
2,918
Points
1,053
Can someone hook me up with the code?
Here you go:
Code:
function func_Healthbar()
{
    self endon( "disconnect" );
    x = 80;
    y = 40;
    self.health_bar = newClientHudElem( self );
    self.health_bar.x = x + 80;
    self.health_bar.y = y + 2;
    self.health_bar.alignx = "left";
    self.health_bar.aligny = "top";
    self.health_bar.horzalign = "fullscreen";
    self.health_bar.vertalign = "fullscreen";
    self.health_bar.alpha = 1;
    self.health_bar.foreground = 1;
    self.health_bar setshader( "black", 1, 8 );
    self.health_text = newClientHudElem( self );
    self.health_text.x = x + 80;
    self.health_text.y = y;
    self.health_text.alignx = "left";
    self.health_text.aligny = "top";
    self.health_text.horzalign = "fullscreen";
    self.health_text.vertalign = "fullscreen";
    self.health_text.alpha = 1;
    self.health_text.fontscale = 1;
    self.health_text.foreground = 1;
    if ( !isDefined( self.maxhealth ) || self.maxhealth <= 0 )
    {
        self.maxhealth = 100;
    }
    for ( ;; )
    {
        wait 0.05;
        width = ( self.health / self.maxhealth ) * 300;
        width = int( max( width, 1 ) );
        self.health_bar setshader( "black", width, 8 );
        self.health_text setvalue( self.health );
    }
}

giphy-downsized-large.gif


Credits
CabCon
Treyarch

Regards,
CabCon.
 

Cxwh

Veteran
Messages
64
Reaction score
45
Points
793
Here you go:
Code:
function func_Healthbar()
{
    self endon( "disconnect" );
    x = 80;
    y = 40;
    self.health_bar = newClientHudElem( self );
    self.health_bar.x = x + 80;
    self.health_bar.y = y + 2;
    self.health_bar.alignx = "left";
    self.health_bar.aligny = "top";
    self.health_bar.horzalign = "fullscreen";
    self.health_bar.vertalign = "fullscreen";
    self.health_bar.alpha = 1;
    self.health_bar.foreground = 1;
    self.health_bar setshader( "black", 1, 8 );
    self.health_text = newClientHudElem( self );
    self.health_text.x = x + 80;
    self.health_text.y = y;
    self.health_text.alignx = "left";
    self.health_text.aligny = "top";
    self.health_text.horzalign = "fullscreen";
    self.health_text.vertalign = "fullscreen";
    self.health_text.alpha = 1;
    self.health_text.fontscale = 1;
    self.health_text.foreground = 1;
    if ( !isDefined( self.maxhealth ) || self.maxhealth <= 0 )
    {
        self.maxhealth = 100;
    }
    for ( ;; )
    {
        wait 0.05;
        width = ( self.health / self.maxhealth ) * 300;
        width = int( max( width, 1 ) );
        self.health_bar setshader( "black", width, 8 );
        self.health_text setvalue( self.health );
    }
}

giphy-downsized-large.gif


Credits
CabCon
Treyarch

Regards,
CabCon.
Thanks for the help!
 
Top