Before CL_CreateMove:
Code:
#define SPIN_REVS_PER_SECOND cvar.spin_speed
void FixupAngleDifference(usercmd_t *cmd)
{
cl_entity_t *pLocal;
Vector viewforward, viewright, viewup, aimforward, aimright, aimup, vTemp;
float newforward, newright, newup, newmagnitude, fTime;
float forward = g_Originalcmd.forwardmove;
float right = g_Originalcmd.sidemove;
float up = g_Originalcmd.upmove;
pLocal = gEngfuncs.GetLocalPlayer();
if(!pLocal)
return;
if(pLocal->curstate.movetype == MOVETYPE_WALK)
{
gEngfuncs.pfnAngleVectors(Vector(0.0f, g_Originalcmd.viewangles.y, 0.0f), viewforward, viewright, viewup);
}
else
{
gEngfuncs.pfnAngleVectors(g_Originalcmd.viewangles, viewforward, viewright, viewup);
}
int iHasShiftHeld = GetAsyncKeyState(VK_LSHIFT);
if(pLocal->curstate.movetype == MOVETYPE_WALK && !iHasShiftHeld && !(cmd->buttons & IN_ATTACK) && !(cmd->buttons & IN_USE))
{
fTime = gEngfuncs.GetClientTime();
cmd->viewangles.y = fmod(fTime * SPIN_REVS_PER_SECOND * 360.0f, 360.0f);
}
if(pLocal->curstate.movetype == MOVETYPE_WALK)
{
gEngfuncs.pfnAngleVectors(Vector(0.0f, cmd->viewangles.y, 0.0f), aimforward, aimright, aimup);
}
else
{
gEngfuncs.pfnAngleVectors(cmd->viewangles, aimforward, aimright, aimup);
}
newforward = DotProduct(forward * viewforward.Normalize(), aimforward) + DotProduct(right * viewright.Normalize(), aimforward) + DotProduct(up * viewup.Normalize(), aimforward);
newright = DotProduct(forward * viewforward.Normalize(), aimright) + DotProduct(right * viewright.Normalize(), aimright) + DotProduct(up * viewup.Normalize(), aimright);
newup = DotProduct(forward * viewforward.Normalize(), aimup) + DotProduct(right * viewright.Normalize(), aimup) + DotProduct(up * viewup.Normalize(), aimup);
cmd->forwardmove = newforward;
cmd->sidemove = newright;
cmd->upmove = newup;
}
Inside CL_CreateMove:
Make sure you put this above cvar.spin inside CL_CreateMove
Code:
memcpy(&g_Originalcmd, cmd, sizeof(usercmd_t));
You can put this anywhere below the code above. Make sure it is inside CL_CreateMove though
Code:
if (cvar.spin) { FixupAngleDifference(cmd); }
Now register your spin & spin_speed cvars. Make sure you register spin_speed as a float. If you have any problems please let me know.