- Status
- Offline
- Joined
- Dec 16, 2019
- Messages
- 3
- Reaction score
- 3
do it for xy0 if needed
Code:
Title says it, do it for xy0 if needed
template<class T, class U>
inline T clamp_value(T in, U low, U high)
{
if (in <= low)
return low;
else if (in >= high)
return high;
else
return in;
}
void c_misc::strafer(CUserCmd* cmd) {
if (!settings.msc_autostrafe)
return;
if (g::pLocalEntity->GetMoveType() == MoveType_t::MOVETYPE_NOCLIP || g::pLocalEntity->GetMoveType() == MoveType_t::MOVETYPE_LADDER)
return;
if (!GetAsyncKeyState(VK_SPACE) || g::pLocalEntity->GetVelocity().Length2D() < 0.5)
return;
if (!(g::pLocalEntity->GetFlags() & FL_ONGROUND)) {
static float cl_sidespeed = g_pCVar->FindVar("cl_sidespeed")->GetFloat();
if (fabsf(cmd->mousedx > 2)) {
cmd->sidemove = (cmd->mousedx < 0.f) ? -cl_sidespeed : cl_sidespeed;
return;
}
if (settings.msc_autostrafe_wasd_movement) {
if (GetAsyncKeyState('S')) {
cmd->viewangles.y -= 180;
}
else if (GetAsyncKeyState('D')) {
cmd->viewangles.y -= 90;
}
else if (GetAsyncKeyState('A')) {
cmd->viewangles.y += 90;
}
}
if (!g::pLocalEntity->GetVelocity().Length2D() > 0.5 || g::pLocalEntity->GetVelocity().Length2D() == NAN || g::pLocalEntity->GetVelocity().Length2D() == INFINITE)
{
cmd->forwardmove = 400;
return;
}
cmd->forwardmove = clamp_value(5850.f / g::pLocalEntity->GetVelocity().Length2D(), -400, 400);
if ((cmd->forwardmove < -400 || cmd->forwardmove > 400))
cmd->forwardmove = 0;
const auto vel = g::pLocalEntity->GetVelocity();
const float y_vel = RAD2DEG(atan2(vel.y, vel.x));
const float diff_ang = MATH::normalize_yaw(cmd->viewangles.y - y_vel);
cmd->sidemove = (diff_ang > 0.0) ? -cl_sidespeed : cl_sidespeed;
cmd->viewangles.y = MATH::normalize_yaw(cmd->viewangles.y - diff_ang);
}
}