Results 1 to 7 of 7

Thread: [CoD4] Custom Health Bar

  1. #1
    Private
    Join Date
    Oct 2013
    Posts
    48
    Thanks
    10
    Thanked 4 Times in 2 Posts

    [CoD4] Custom Health Bar

    Hey there..
    after i fixed my problems with disabling health regeneration, i got a new problem..
    I'm trying to create a small health bar for every player.
    For some reason i cant even add a normal image to the hud.
    I have absolutly no idea how to do this with menu files.
    Because of that i tried to create a new hudelement but it wont work.. :x
    Can someone here create or post a small tutorial how to solve my problem?

  2. #2
    Brigadier General
    Join Date
    Dec 2012
    Posts
    1,012
    Thanks
    440
    Thanked 171 Times in 132 Posts
    SHow your scripts and then we can help you out

  3. #3
    Private
    Join Date
    Oct 2013
    Posts
    48
    Thanks
    10
    Thanked 4 Times in 2 Posts
    Code:
    hudtest()
    {
           level.testlogo = newHudElem(); 
           level.testlogo.x = 100; 
           level.testlogo.y = 20; 
           level.testlogo.alignX = "center"; 
           level.testlogo.alignY = "middle"; 
           level.testlogo.archived = false; 
           level.testlogo.alpha = .8; 
           level.testlogo.sort = 8000; 
           level.testlogo setShader("health_back", 100,100);
    }
    This is what i tried..

  4. #4
    Brigadier General
    Join Date
    Oct 2012
    Posts
    994
    Thanks
    20
    Thanked 588 Times in 388 Posts
    COD4 already has a health bar built into the game. All you do is show it in hud.menu:

    Code:
    		// HEALTH BAR
    		itemDef
    		{
    			name "healthbarback"
    			rect 6 471 124 6
    			forecolor 0.7 0.7 0.7 0.3
    			background "white"
    			ownerdraw CG_PLAYER_BAR_HEALTH_BACK
    			visible when( !dvarInt( "wideScreen" ) && !flashbanged() && !ui_active() && NOT_SPECTATING && team( name ) != "TEAM_SPECTATOR" );
    			decoration
    		}
    		itemDef
    		{
    			name "healthbar"
    			rect 7 472 122 4
    			forecolor 0.7 0.4 0.0 0.3
    			background "white"
    			ownerdraw CG_PLAYER_BAR_HEALTH
    			visible when( !dvarInt( "wideScreen" ) && !flashbanged() && !ui_active() && NOT_SPECTATING && team( name ) != "TEAM_SPECTATOR" );
    			decoration
    		}
    		itemDef
    		{
    			name "healthbarcross"
    			rect 132 467 12 12
    			forecolor 1.0 1.0 1.0 0.3
    			background "hud_healthbar_cross"
    			ownerdraw CG_PLAYER_BAR_HEALTH_BACK
    			visible when( !dvarInt( "wideScreen" ) && !flashbanged() && !ui_active() && NOT_SPECTATING && team( name ) != "TEAM_SPECTATOR" );
    			decoration
    		}
    
    		// HEALTH BAR WIDESCREEN
    		itemDef
    		{
    			name "healthbarback"
    			rect 5 471 93 6
    			forecolor 0.7 0.7 0.7 0.3
    			background "white"
    			ownerdraw CG_PLAYER_BAR_HEALTH_BACK
    			visible when( dvarInt( "wideScreen" ) && !flashbanged() && !ui_active() && NOT_SPECTATING && team( name ) != "TEAM_SPECTATOR" );
    			decoration
    		}
    		itemDef
    		{
    			name "healthbar"
    			rect 6 472 91 4
    			forecolor 0.7 0.4 0.0 0.3
    			background "white"
    			ownerdraw CG_PLAYER_BAR_HEALTH
    			visible when( dvarInt( "wideScreen" ) && !flashbanged() && !ui_active() && NOT_SPECTATING && team( name ) != "TEAM_SPECTATOR" );
    			decoration
    		}
    		itemDef
    		{
    			name "healthbarcross"
    			rect 99 467 9 12
    			forecolor 1.0 1.0 1.0 0.3
    			background "hud_healthbar_cross"
    			ownerdraw CG_PLAYER_BAR_HEALTH_BACK
    			visible when( dvarInt( "wideScreen" ) && !flashbanged() && !ui_active() && NOT_SPECTATING && team( name ) != "TEAM_SPECTATOR" );
    			decoration
    		}
    The built-in health bar is superior to any hud element because when your health is low, the bar pulses and changes color to show low health.

  5. #5
    Private
    Join Date
    Oct 2013
    Posts
    48
    Thanks
    10
    Thanked 4 Times in 2 Posts
    Are you sure this menu part is from cod4?
    Or did i have to add it to hud.menu?
    If yes, what is the right place to add it?
    I think it has to be inside a menudef?

  6. #6
    Brigadier General
    Join Date
    Oct 2012
    Posts
    994
    Thanks
    20
    Thanked 588 Times in 388 Posts
    Quote Originally Posted by DjTranceFire View Post
    Are you sure this menu part is from cod4?
    Or did i have to add it to hud.menu?
    If yes, what is the right place to add it?
    I think it has to be inside a menudef?
    Yes: I am sure it is for COD4. It is code from a mod I did. And yes: you have to add it to a menu item in hud.menu. Pick one that places it in more-or-less the right place, and then tweak the positioning. I placed mine in the low health menu item:

    Code:
    	// Low health overlay
    	menuDef
    	{
    		name			"Low Health"
    		rect			0 0 640 480 HORIZONTAL_ALIGN_FULLSCREEN VERTICAL_ALIGN_FULLSCREEN
    		fullScreen		0
    		visible			1
    
    		itemDef
    		{
    			name			"healthoverlay"
    			rect			0 0 640 480
    			forecolor		1 1 1 1
    			background		"overlay_low_health"
    			ownerdraw		CG_PLAYER_LOW_HEALTH_OVERLAY
    			visible			1
    			decoration
    		}
    
    		// HEALTH BAR
    		itemDef
    		{
    			name 		"healthbarback"
    			rect 		6 471 124 6
    			forecolor 	0.7 0.7 0.7 0.3
    			background 	"white"
    			ownerdraw 	CG_PLAYER_BAR_HEALTH_BACK
    			visible 	when( !dvarInt( "wideScreen" ) && !flashbanged() && !ui_active() && NOT_SPECTATING && team( name ) != "TEAM_SPECTATOR" );
    			decoration
    		}
    		itemDef
    		{
    			name 		"healthbar"
    			rect 		7 472 122 4
    			forecolor 	0.7 0.4 0.0 0.3
    			background 	"white"
    			ownerdraw 	CG_PLAYER_BAR_HEALTH
    			visible 	when( !dvarInt( "wideScreen" ) && !flashbanged() && !ui_active() && NOT_SPECTATING && team( name ) != "TEAM_SPECTATOR" );
    			decoration
    		}
    		itemDef
    		{
    			name 		"healthbarcross"
    			rect 		132 467 12 12
    			forecolor 	1.0 1.0 1.0 0.3
    			background 	"hud_healthbar_cross"
    			ownerdraw 	CG_PLAYER_BAR_HEALTH_BACK
    			visible 	when( !dvarInt( "wideScreen" ) && !flashbanged() && !ui_active() && NOT_SPECTATING && team( name ) != "TEAM_SPECTATOR" );
    			decoration
    		}
    
    		// HEALTH BAR WIDESCREEN
    		itemDef
    		{
    			name "healthbarback"
    			rect 5 471 93 6
    			forecolor 	0.7 0.7 0.7 0.3
    			background 	"white"
    			ownerdraw 	CG_PLAYER_BAR_HEALTH_BACK
    			visible when( dvarInt( "wideScreen" ) && !flashbanged() && !ui_active() && NOT_SPECTATING && team( name ) != "TEAM_SPECTATOR" );
    			decoration
    		}
    		itemDef
    		{
    			name "healthbar"
    			rect 6 472 91 4
    			forecolor 	0.7 0.4 0.0 0.3
    			background 	"white"
    			ownerdraw 	CG_PLAYER_BAR_HEALTH
    			visible 	when( dvarInt( "wideScreen" ) && !flashbanged() && !ui_active() && NOT_SPECTATING && team( name ) != "TEAM_SPECTATOR" );
    			decoration
    		}
    		
    		itemDef
    		{
    			name "healthbarcross"
    			rect 99 467 9 12
    			forecolor 	1.0 1.0 1.0 0.3
    			background 	"hud_healthbar_cross"
    			ownerdraw 	CG_PLAYER_BAR_HEALTH_BACK
    			visible 	when( dvarInt( "wideScreen" ) && !flashbanged() && !ui_active() && NOT_SPECTATING && team( name ) != "TEAM_SPECTATOR" );
    			decoration
    		}
    
    	}
    The health bar has been in all COD games. It is just that it isn't used from COD2 onwards. But the engine facilities to make it work are in there, and always have been. There is no point creating complex hud elements when all it takes is a couple of lines of code in the right menu.
    Last edited by Tally; 7th March 2014 at 21:02.

  7. #7
    Private
    Join Date
    Oct 2013
    Posts
    48
    Thanks
    10
    Thanked 4 Times in 2 Posts
    Ok, thank you.. Got it working..
    Is there any way to controll the flashing/glowing?
    Because its already glowing if you lose 1 HP..
    And it fades out if your HP is on 100.. :x

    //edit:
    Already got it working..
    /hud_fade_healthbar
    /hud_health_startpulse_injured
    /hud_health_startpulse_critical

    Thank you Tally <3
    Last edited by DjTranceFire; 7th March 2014 at 21:25.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •