I made an esp that is supposed to draw the name of the player above their head. It does this the majority of the time, however sometimes it will draw the name in the center of their body (where there head would be if they were crouched). I position the text using eyepos and raising it by 10.
Not working: https://imgur.com/a/LwNRFow
Working: https://imgur.com/a/uBOTJhl
Code:
#include "Hooks.h"
#include <codecvt>
PaintTraverseFn oPaintTraverse;
vgui::HFont hFont;
void __stdcall Hooks::PaintTraverse(unsigned int panel, bool forceRepaint, bool allowForce)
{
oPaintTraverse(Interfaces->Panel, panel, forceRepaint, allowForce);
{
static int drawPanel = 0;
if (!drawPanel)
if (!strcmp(Interfaces->Panel->GetName(panel), "MatSystemTopPanel"))
drawPanel = panel;
else
return;
if (drawPanel != panel)
return;
}
if (Config.esp)
{
CBaseEntity* local = (CBaseEntity*)Interfaces->ClientEntityList->GetClientEntity(Interfaces->EngineClient->GetLocalPlayer());
for (size_t i = 1; i <= 64; i++)
{
CBaseEntity* entity = (CBaseEntity*)Interfaces->ClientEntityList->GetClientEntity(i);
if (entity && entity->IsPlayer() && entity->GetHealth() && !entity->IsDormant() && i != Interfaces->EngineClient->GetLocalPlayer() && entity->GetTeam() != local->GetTeam())
{
player_info_t pInfo;
if (!Interfaces->EngineClient->GetPlayerInfo(entity->EntIndex(), &pInfo))
return;
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t> convert;
std::wstring name = convert.from_bytes(pInfo.name);
const wchar_t* szName = name.c_str();
Vector feetpos, eyepos;
if (Math.WorldToScreen(entity->GetEyePos() + Vector(0, 0, 10), eyepos) && Math.WorldToScreen(entity->GetOrigin(), feetpos))
{
int width = (feetpos.y - eyepos.y) / 2;
int hight = (feetpos.y - eyepos.y);
if(!hFont)
{
hFont = Interfaces->Surface->CreateFont_();
Interfaces->Surface->SetFontGlyphSet(hFont, "Tahoma", 12, 200, 0, 0, FONTFLAG_ANTIALIAS | FONTFLAG_OUTLINE);
}
int w, h;
Interfaces->Surface->DrawSetTextColor(255, 255, 255, 255);
Interfaces->Surface->DrawSetTextFont(hFont);
Interfaces->Surface->GetTextSize(hFont, szName, w, h);
Interfaces->Surface->DrawSetTextPos(eyepos.x - (w / 2), eyepos.y);
Interfaces->Surface->DrawPrintText(szName, (int)wcslen(szName), FONT_DRAW_DEFAULT);
}
}
}
}
}