PDA

View Full Version : [CoD4] Custom Health Bar



DjTranceFire
7th March 2014, 16:04
Hey there.. :)
after i fixed my problems with disabling health regeneration, i got a new problem.. :D
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?

Ni3ls
7th March 2014, 17:43
SHow your scripts and then we can help you out

DjTranceFire
7th March 2014, 17:49
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..

Tally
7th March 2014, 21:03
COD4 already has a health bar built into the game. All you do is show it in hud.menu:


// 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.

DjTranceFire
7th March 2014, 21:22
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?

Tally
7th March 2014, 22:00
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:


// 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.

DjTranceFire
7th March 2014, 22:13
Ok, thank you.. Got it working.. :)
Is there any way to controll the flashing/glowing?
Because its already glowing if you lose 1 HP.. :D
And it fades out if your HP is on 100.. :x

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

Thank you Tally <3