[HowTo] Detect Holding Walk Button (CS 1.6)

For scripting examples for learning how to use AMXX.
User avatar
Archive-Poster
Posts: 1367
Gender:
United States of America

[HowTo] Detect Holding Walk Button (CS 1.6)

Post by Archive-Poster »

Since walking is done purely clientside, there was no easy way of finding out when player is holding the walk button. However the client sends certain information to the server regarding their forward and side buttons in a class called UserCmd. These are the speeds you move at.

Using FAKEMETA, we create the FM_CmdStart forward to capture the forwardmove and sidemove variables.

Then using the walkspeed which is MAXSPEED * 0.52, we check if forward/side moves are lower than that amount. 0.52 was retrieved from the client cvar "cl_movespeedkey" which is changeable, so this will break if the client changes it. It's their own fault for trying to cheat/mess around.

Heres the full code. Enjoy.

Code: Select all

plugin_init()
    register_forward( FM_CmdStart, "FMCmdStart" );

public FMCmdStart( id, uc_handle, randseed )
{
    new Float:fmove, Float:smove;
    get_uc(uc_handle, UC_ForwardMove, fmove);
    get_uc(uc_handle, UC_SideMove, smove );

    new Float:maxspeed;
    pev(id, pev_maxspeed, maxspeed);
    new Float:walkspeed = (maxspeed * 0.52); 
    fmove = floatabs( fmove );
    smove = floatabs( smove );
    
    if(fmove <= walkspeed && smove <= walkspeed && !(fmove == 0.0 && smove == 0.0))
    {
        client_print( id, print_center, "WALKING" );
    }
    else
    {
        client_print( id, print_center, "RUNNING" );    
    }
}
The reason I created this, was to make the walk button a sprint button instead of walking. By increasing the maxspeed when walking, and returning it to default when running.

Who is online

Users browsing this forum: No registered users and 1 guest