+- +-

+-User

Welcome, Guest.
Please login or register.
 
 
 

Login with your social network

Forgot your password?

+-Stats ezBlock

Members
Total Members: 4
Latest: Bob
New This Month: 0
New This Week: 0
New Today: 0
Stats
Total Posts: 15
Total Topics: 15
Most Online Today: 9
Most Online Ever: 152
(November 07, 2022, 01:49:47 pm)
Users Online
Members: 0
Guests: 7
Total: 7

Author Topic: [source code] Horizontal HealthBar  (Read 451 times)

0 Members and 1 Guest are viewing this topic.

  • Administrator
  • Hero Member
  • *
  • Posts: 1010
  • Karma: +20/-0

  • Badges: (View All)
    Signature Karma Admin
[source code] Horizontal HealthBar
« on: July 19, 2013, 02:07:31 am »
Code: [Select]
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: [Select]
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: [Select]
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: [Select]
DrawEnemyHealth(
(int)(ScreenX - (drawx/2)),
(int)(ScreenY - (drawy*2)),
drawx, drawy/4, enemiesVec[i].health);

Credits gflames12

Share on Bluesky Share on Facebook


 

Forum Rules ! by Brandon
July 20, 2013, 12:10:50 pm

Announcement by Brandon
July 19, 2013, 07:04:32 pm

Forum clean up! by Brandon
July 19, 2013, 07:01:23 pm

Crossfire Memory hack/wallhack by Dustin
July 19, 2013, 11:49:37 am

Assault Cube Ultimate Trainer v1.0 by Brandon
July 19, 2013, 03:31:34 am

[source code] Horizontal HealthBar by Brandon
July 19, 2013, 02:07:31 am

[Source Code] USSR's Address Logger - Combat Arms NA 19/7/2013 by Brandon
July 19, 2013, 01:59:57 am

Vip hack! by Brandon
July 19, 2013, 01:55:42 am

Winject .DLL Injector by Dustin
July 19, 2013, 01:51:13 am

Free full fraps! by Brandon
July 19, 2013, 01:33:00 am

Recent Posts ezBlock

Forum Rules ! by Brandon
July 20, 2013, 12:10:50 pm

Announcement by Brandon
July 19, 2013, 07:04:32 pm

Forum clean up! by Brandon
July 19, 2013, 07:01:23 pm

Crossfire Memory hack/wallhack by Dustin
July 19, 2013, 11:49:37 am

Assault Cube Ultimate Trainer v1.0 by Brandon
July 19, 2013, 03:31:34 am

[source code] Horizontal HealthBar by Brandon
July 19, 2013, 02:07:31 am

[Source Code] USSR's Address Logger - Combat Arms NA 19/7/2013 by Brandon
July 19, 2013, 01:59:57 am

Vip hack! by Brandon
July 19, 2013, 01:55:42 am

Winject .DLL Injector by Dustin
July 19, 2013, 01:51:13 am

Free full fraps! by Brandon
July 19, 2013, 01:33:00 am