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.