Thought id release this since i have seen many people complaining of health bars on other forums, draws horizontal health bars about enemys head on screen. I have been using this same health bar since i made my first cod 4 d3d hack, using fleeps tutorials.
Credits: Mainly to fleep for code
drawing functions
Code:
void Drawing::DrawBorderBox( int x, int y, int w, int h, int thickness, D3DCOLOR Colour, IDirect3DDevice9 *pDevice)
{
//t
DrawFilledRect( x, y, w, thickness, Colour, pDevice );
//l
DrawFilledRect( x, y, thickness, h, Colour, pDevice );
//r
DrawFilledRect( (x + w), y, thickness, h, Colour, pDevice );
//b
DrawFilledRect( x, y + h, w+thickness, thickness, Colour, pDevice );
}
void Drawing::DrawFilledRect(int x, int y, int w, int h, D3DCOLOR color, IDirect3DDevice9* dev)
{
D3DRECT BarRect = { x, y, x + w, y + h };
dev->Clear(1, &BarRect, D3DCLEAR_TARGET | D3DCLEAR_TARGET, color, 0, 0);
}
next we have our actual function
Code:
void ESP::DrawEnemyHealth(int x, int y, int w, int h, int health)
{
Drawing::DrawBorderBox(x, y, w/*w*/, h/*h*/, 4, D3DCOLOR_ARGB(255, 0, 0, 255), D3dDevice );
float healthPercentage = ((float)health/(float)MAXHEALTH) * 100.0f;
float barPercentage = ((float)w*(float)(healthPercentage/100));
RECT healthRect =
{
x, //L
y-20,//T
x + w,//R
y + h//B
};
M_font->DrawText(NULL, I_O::IntToString(health).c_str() , -1, &healthRect, DT_NOCLIP, D3DCOLOR_ARGB(255, 255, 0, 0));
Drawing::DrawFilledRect( x, y, (int)barPercentage, h, GetHealthColor(health), D3dDevice );
}
to change colour of bar as health is lowered
Code:
D3DCOLOR ESP::GetHealthColor(int currentHealth)
{
if(currentHealth > 89 && currentHealth <= 100)
return D3DCOLOR_ARGB(255, 0, 255, 0);
else if(currentHealth > 79 && currentHealth < 90)
return D3DCOLOR_ARGB(255, 0, 255, 155);
else if(currentHealth > 69 && currentHealth < 80)
return D3DCOLOR_ARGB(255, 255, 255, 0);
else if(currentHealth > 59 && currentHealth < 70)
return D3DCOLOR_ARGB(255, 255, 205, 0);
else if(currentHealth > 49 && currentHealth < 60)
return D3DCOLOR_ARGB(255, 255, 170, 0);
else if(currentHealth > 39 && currentHealth < 50)
return D3DCOLOR_ARGB(255, 255, 128, 0);
else if(currentHealth > 29 && currentHealth < 40)
return D3DCOLOR_ARGB(255, 255, 97, 0);
else if(currentHealth > 19 && currentHealth < 30)
return D3DCOLOR_ARGB(255, 255, 58, 0);
else if(currentHealth > 9 && currentHealth < 20)
return D3DCOLOR_ARGB(255, 255, 0, 66);
else if(currentHealth > 1 && currentHealth < 9)
return D3DCOLOR_ARGB(255, 255, 0, 0);
}
to draw health bar (example call):
Code:
DrawEnemyHealth(
(int)(ScreenX - (drawx/2)),
(int)(ScreenY - (drawy*2)),
drawx, drawy/4, enemiesVec[i].health);