Code:
plugin_init()
register_forward( FM_CmdStart, "FMCmdStart" );
public FMCmdStart( id, uc_handle, randseed )
{
new Float:fmove, Float:smove, Float:umove;
get_uc(uc_handle, UC_ForwardMove, fmove);
get_uc(uc_handle, UC_SideMove, smove);
get_uc(uc_handle, UC_UpMove, umove);
new Float:maxspeed;
pev(id, pev_maxspeed, maxspeed);
fmove = floatabs( fmove );
smove = floatabs( smove );
if( ((fmove*fmove)+(smove*smove)+(umove*umove))<=floatpower((maxspeed*0.52), 2.0) && (fmove || smove || umove) )
{
client_print( id, print_center, "WALKING" );
}
else
{
client_print( id, print_center, "RUNNING" );
}
}
I think this would be more accurate. Supports +moveup and +movedown.
However still this method works only if player is holding any movement key (meaning, that when player is sliding down after movement [even if holding shift], this method wont detect it), and can think that +strafe and mouse movement is when user is walking. Plus people can use scripts, and so on, what can trick this method. I'd suggest to use:
Code:
plugin_init()
register_forward( FM_CmdStart, "FMCmdStart" );
public FMCmdStart( id, uc_handle, randseed )
{
new Float:fmove, Float:smove, Float:umove;
get_uc(uc_handle, UC_ForwardMove, fmove);
get_uc(uc_handle, UC_SideMove, smove);
get_uc(uc_handle, UC_UpMove, umove);
new Float:maxspeed, maxwalkspeed;
pev(id, pev_maxspeed, maxspeed);
fmove = floatabs( fmove );
smove = floatabs( smove );
maxwalkspeed = what_is_higher((maxspeed*0.52), 22500.0);
if( ((fmove*fmove)+(smove*smove)+(umove*umove))<=maxwalkspeed && (fmove || smove || umove) )
{
client_print( id, print_center, "WALKING" );
}
else
{
client_print( id, print_center, "RUNNING" );
}
}
Float:what_is_higher(Float:val1, Float:val2)
{
if( val1>val2 )
return val1;
return val2;
}
Here we are being sure, that player is attempting to move at speed below stepsound speed. However it still doesn't solve the problem of player sliding a bit when releasing movement key. In this case, I've done next:
Code:
new bool:g_walking[33];
plugin_init()
register_forward( FM_CmdStart, "FMCmdStart" );
public client_connect(id)
g_walking[id] = false;
public client_putinserver(id)
g_walking[id] = false;
public client_disconnect(id)
g_walking[id] = false;
public FMCmdStart( id, uc_handle, randseed )
{
new Float:fmove, Float:smove, Float:umove;
get_uc(uc_handle, UC_ForwardMove, fmove);
get_uc(uc_handle, UC_SideMove, smove);
get_uc(uc_handle, UC_UpMove, umove);
new Float:maxspeed, maxwalkspeed;
pev(id, pev_maxspeed, maxspeed);
fmove = floatabs( fmove );
smove = floatabs( smove );
maxwalkspeed = what_is_higher((maxspeed*0.52), 22500.0);
static Float:oldspeed[33];
if( ((fmove*fmove)+(smove*smove)+(umove*umove))>maxwalkspeed ) // attempting to move above walking speed (150*150). It's faster to multiply, than to use sqrt - saving CPU
{
g_walking[id] = false;
//client_print( id, print_center, "RUNNING" );
}
else if( fmove || smove || umove ) // attempting to move below running speed
{
new Float:velocity[3];
pev(id, pev_velocity, velocity);
oldspeed[id] = ((velocity[0]*velocity[0])+(velocity[1]*velocity[1])+(velocity[2]*velocity[2])+1.0); // save old speed and an extra 1ups, since sliding down wont start from this frame
g_walking[id] = true;
//client_print( id, print_center, "WALKING" );
}
else if( g_walking[id] ) // no movement attempt, but may be sliding down after walking
{
new Float:velocity[3], Float:speed;
pev(id, pev_velocity, velocity);
speed = ((velocity[0]*velocity[0])+(velocity[1]*velocity[1])+(velocity[2]*velocity[2]));
if( speed>maxwalkspeed ) // pushed up to beyond walking speed
{
g_walking[id] = false;
client_print( id, print_center, "PUSHED TO RUN" );
}
else if( !speed ) // stopped
{
g_walking[id] = false;
client_print( id, print_center, "STANDING" );
}
else if( speed>=oldspeed[id] ) // is player not decelerating?
{
g_walking[id] = false;
client_print( id, print_center, "PUSHED" );
}
oldspeed[id] = speed;
}
}
Float:what_is_higher(Float:val1, Float:val2)
{
if( val1>val2 )
return val1;
return val2;
}
So, I think last example is the best. And use "g_walking[id]" to check is player walking or no.
__________________