diff options
| author | salmonik <salmonik@tuta.io> | 2026-10-26 15:38:39 +0100 |
|---|---|---|
| committer | salmonik <salmonik@tuta.io> | 2026-10-26 15:38:39 +0100 |
| commit | e2e6da47efc68ff37c680ae991d0756fd464fbeb (patch) | |
| tree | ba266c0b2153d283a053a6442a604f1fc17a1f83 | |
| parent | ESP working: NPC detection + authoritative server-side health (diff) | |
| download | hl2h-e2e6da47efc68ff37c680ae991d0756fd464fbeb.tar.gz hl2h-e2e6da47efc68ff37c680ae991d0756fd464fbeb.zip | |
ESP: vertical health bar right of the box, HP number beside it
| -rw-r--r-- | src/esp.cpp | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/src/esp.cpp b/src/esp.cpp index d12c718..3914342 100644 --- a/src/esp.cpp +++ b/src/esp.cpp | |||
| @@ -284,23 +284,30 @@ void esp_draw() { | |||
| 284 | else if (t.neutral) surf_color(220, 220, 220, 255); | 284 | else if (t.neutral) surf_color(220, 220, 220, 255); |
| 285 | else surf_color(255, 60, 60, 255); | 285 | else surf_color(255, 60, 60, 255); |
| 286 | float w = t.h * 0.45f; // ponytail: constant aspect, no OBB width | 286 | float w = t.h * 0.45f; // ponytail: constant aspect, no OBB width |
| 287 | surf_rect(0, (int)(t.sx - w / 2), (int)(t.sy - t.h), (int)(t.sx + w / 2), (int)t.sy); | 287 | int left = (int)(t.sx - w / 2); |
| 288 | int right = (int)(t.sx + w / 2); | ||
| 289 | int top = (int)(t.sy - t.h); | ||
| 290 | int bot = (int)t.sy; | ||
| 291 | surf_rect(0, left, top, right, bot); | ||
| 288 | if (t.show_health) { | 292 | if (t.show_health) { |
| 289 | float frac = t.health / (t.maxhealth > 1.0f ? t.maxhealth : 100.0f); | 293 | float frac = t.health / (t.maxhealth > 1.0f ? t.maxhealth : 100.0f); |
| 290 | if (frac > 1) frac = 1; | 294 | if (frac > 1) frac = 1; |
| 295 | if (frac < 0) frac = 0; | ||
| 296 | // vertical bar just right of the box, HP number beside it | ||
| 297 | int bx0 = right + 2, bx1 = right + 5; | ||
| 291 | surf_color(0, 0, 0, 200); | 298 | surf_color(0, 0, 0, 200); |
| 292 | surf_rect(1, (int)(t.sx - w / 2), (int)t.sy + 1, (int)(t.sx + w / 2), (int)t.sy + 4); | 299 | surf_rect(1, bx0, top, bx1, bot); |
| 300 | int fill_top = bot - (int)((float)(bot - top) * frac); | ||
| 301 | if (fill_top < top) fill_top = top; | ||
| 293 | if (frac > 0.5f) surf_color(40, 255, 40, 255); | 302 | if (frac > 0.5f) surf_color(40, 255, 40, 255); |
| 294 | else if (frac > 0.25f) surf_color(255, 255, 0, 255); | 303 | else if (frac > 0.25f) surf_color(255, 255, 0, 255); |
| 295 | else surf_color(255, 40, 40, 255); | 304 | else surf_color(255, 40, 40, 255); |
| 296 | surf_rect(1, (int)(t.sx - w / 2), (int)t.sy + 2, | 305 | if (fill_top < bot) |
| 297 | (int)(t.sx - w / 2 + w * frac), (int)t.sy + 3); | 306 | surf_rect(1, bx0, fill_top, bx1, bot); |
| 307 | char hptext[16]; | ||
| 308 | snprintf(hptext, sizeof(hptext), "%d", (int)t.health); | ||
| 309 | draw_text_col(bx1 + 3, top, hptext, 255, 255, 255); | ||
| 298 | } | 310 | } |
| 299 | char label[64]; | 311 | draw_text_col(left, top - 14, t.name, 255, 255, 255); |
| 300 | if (t.show_health) | ||
| 301 | snprintf(label, sizeof(label), "%s %d", t.name, (int)t.health); | ||
| 302 | else | ||
| 303 | snprintf(label, sizeof(label), "%s", t.name); | ||
| 304 | draw_text_col((int)(t.sx - w / 2), (int)(t.sy - t.h) - 14, label, 255, 255, 255); | ||
| 305 | } | 312 | } |
| 306 | } | 313 | } |
