AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Detecting walk/run [SHIFT] (https://forums.alliedmods.net/showthread.php?t=334809)

Celena Luna 10-21-2021 04:27

Detecting walk/run [SHIFT]
 
It is something I want to discuss than actually a question.

1. Wrong way to detect walk
PHP Code:

buttons pev(idpev_buttons//or buttons = get_uc(cmd, UC_Buttons) if using at CmdStart

//Check running
if(buttons IN_RUN)
{
     
//Do stuff


This is most people thought at first if they try to check running/walking but it actually didn't work at all
Because IN_RUN exist but it never been called or set anywhere


2. The usual way to detect walk
Usually, when we want to detect walk/run, we have to check via Player Maxspeed
There was an old topic discussed about this (Link)

3. Detect via player sequence
This way, we try to detect walk/run via checking player sequence. More specifically - Gaitsequence

PHP Code:

stock IsPlayerWalking(id)
{
    static 
buttonssequence;
    
buttons pev(idpev_button);
    
sequence pev(idpev_gaitsequence);
 
    if((
buttons IN_FORWARD || buttons IN_BACK || buttons IN_LEFT || buttons IN_RIGHT))
    {
        if(
sequence == 3)
            return 
true;
        else 
            return 
false
    
}

    return 
false


sequence == 3 because Player Model's walk sequence is 3 and we know it is gaitsequence because the animation was on the lower part of the body.

https://i.imgur.com/1CkW98q.png

4. Detect via m_Activity (reHLDS/reGameDLL)
When I look up in reGameDLL, I saw player animation was set depend on Activity and from Activity, to LookUpSequence

In ReAPI we have a member called m_Activity so we can actually check it like this
PHP Code:

stock IsPlayerWalking(id)
{
    static 
Activity:Act//cssdk_const
    
Act get_member(idm_Activity//I am not sure what this return though, haven't try
    
if(Act == ACT_WALK)
        return 
true;
    
    return 
false


I don't want to post in TUT section because I am not sure how many % all of this is correct so I want to make it as a discussion first.

PS: Also, I saw this part which related to speed
PHP Code:

if (speed 135.0f)
    
pev->gaitsequence LookupActivity(ACT_RUN);
else
    
pev->gaitsequence LookupActivity(ACT_WALK); 

So it still lead to a problem when we try to detect walk to turn it into "Sprint" (Hold Shift to run faster) or the player speed modified (like Zombie Mod), it will automatically change to RUN when speed > 135.0f (I am lazy to convert for now).

This all might be non-sense so forgive me if all of this is wrong

Natsheh 10-21-2021 09:04

Re: Detecting walk/run [SHIFT]
 
You want to catch if the player is holding the shift walking or if the player is walking?

I know they sound similar but they're different because shift walking its the maxspeed times cl_movespeedkey client cvar value equal to player speed or greater than it.

And the other one is any speed equal or below 135/210 is said to trigger the walking animation.

Bugsy 10-21-2021 18:13

Re: Detecting walk/run [SHIFT]
 
This has been discussed a few times in the past. The below thread/code will tell you if a player is walking or running, but only when moving, which to me makes sense because who cares if a player is standing still?

https://forums.alliedmods.net/showpo...62&postcount=9

Celena Luna 10-21-2021 22:21

Re: Detecting walk/run [SHIFT]
 
Quote:

Originally Posted by Natsheh (Post 2761185)
You want to catch if the player is holding the shift walking or if the player is walking?

I know they sound similar but they're different because shift walking its the maxspeed times cl_movespeedkey client cvar value equal to player speed or greater than it.

And the other one is any speed equal or below 135/210 is said to trigger the walking animation.

I was confused "Detect" and "Hook" a bit.

I actually aimming for "Change holding Shift from walk to sprint" so holding Shift increased speed instead of slowdown.

So can we increase player speed by increase cl_movespeedkey? and isn't it would consider "Slowhacking" if we try to change it?

Natsheh 10-21-2021 22:50

Re: Detecting walk/run [SHIFT]
 
Quote:

Originally Posted by Celena Luna (Post 2761264)
I was confused "Detect" and "Hook" a bit.

I actually aimming for "Change holding Shift from walk to sprint" so holding Shift increased speed instead of slowdown.

So can we increase player speed by increase cl_movespeedkey? and isn't it would consider "Slowhacking" if we try to change it?

No we're not doing that, we will only retrieve the value to check if the player holding the shift walk, then you can change player maxspeed and set it back on release or setting velocity


All times are GMT -4. The time now is 11:44.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.