void OverrideYaw() {
if (ctx::input_system->IsButtonDown((ButtonCode_t)Vars::options.override_key)) {
int w, h, x, y;
ctx::engine->GetScreenSize(w, h);
x = w / 2;
y = h / 2;
Vector crosshair = Vector(x, y, 0);
int bestent = -1;
float best_fov = 0;
Vector besthead2d;
for (int i = 0; i <= ctx::globals->maxclients; i++) {
sdk::CBaseEntity* player = ctx::client_ent_list->GetClientEntity(i);
if (!player->GetHealth() > 0)
continue;
if (player->GetIsDormant())
continue;
if (!player)
continue;
Vector headpos3d = player->GetBonePosition(8), headpos2d;
if (!RENDER::WorldToScreen(headpos3d, headpos2d))
continue;
float fov2d = crosshair.DistTo(headpos2d);
if (bestent == -1 || fov2d < best_fov) {
bestent = 1;
best_fov = fov2d;
besthead2d = headpos2d;
}
}
if (bestent > -1) {
sdk::CBaseEntity* player = ctx::client_ent_list->GetClientEntity(bestent);
int minx = x - (w / 10), maxx = x + (w / 10);
if (besthead2d.x < x || besthead2d.x > x)
return;
int totalwidth = maxx - minx;
int playerx = besthead2d.x - minx;
int additiveyaw = -(((playerx * 360) / totalwidth) - 100);
Vector* hr = player->GetHeadRotation();
hr->y += additiveyaw;
}
}
}