Raised This Month: $51 Target: $400
 12% 

[HowTo] Detect Holding Walk Button (CS 1.6)


Post New Thread Reply   
 
Thread Tools Display Modes
MPNumB
Veteran Member
Join Date: Feb 2007
Location: Lithuania
Old 04-14-2012 , 14:16   Re: [HowTo] Detect Holding Walk Button (CS 1.6)
Reply With Quote #21

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.
__________________
Skill and no annoying bugs with fixed balance issues is my goal!
My approved plugins what don't show up in Approved List:
* Bomb/Death/CSS Radar
* HotVision
___
Need help? Please check this documentation first.

Last edited by MPNumB; 04-14-2012 at 14:21.
MPNumB is offline
Send a message via Skype™ to MPNumB
Infernuz
Member
Join Date: May 2011
Old 04-15-2012 , 10:53   Re: [HowTo] Detect Holding Walk Button (CS 1.6)
Reply With Quote #22

What if player is crouching?
Infernuz is offline
Send a message via ICQ to Infernuz
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 04-15-2012 , 13:46   Re: [HowTo] Detect Holding Walk Button (CS 1.6)
Reply With Quote #23

Check if player flags contain FL_DUCKING.

Fakemeta:
Code:
if(pev(id, pev_flags) & FL_DUCKING) {     // ducking }

Engine:
Code:
if(get_entity_flags(id) & FL_DUCKING) {     // ducking }
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 03-31-2013 , 14:32   Re: [HowTo] Detect Holding Walk Button (CS 1.6)
Reply With Quote #24

May be this method is more reliable :

PHP Code:
#include <amxmodx>
#include <fakemeta>

#define PLUGIN "Walk Detect"
#define VERSION "0.0.1"

new const g_szCvarsNames[][] = 
{
    
"cl_sidespeed",
    
"cl_forwardspeed",
    
"cl_backspeed",
    
// "cl_upspeed",
    
"cl_movespeedkey"
}

enum
{
    
SIDE_SPEED,
    
FORWARD_SPEED,
    
BACK_SPEED,
    
// UP_SPEED,
    
MOVE_SPEED_KEY
}

new 
Float:g_flUserCvarsValues[33][sizeof(g_szCvarsNames)]
new 
bool:g_bIsWalking[33]

public 
plugin_init()
{
    
register_pluginPLUGINVERSION"ConnorMcLeod" )
    
register_forward(FM_CmdStart"OnCmdStart")
}

public 
client_disconnectid )
{
    
remove_task(id)
}

public 
client_putinserverid )
{
    if( !
is_user_bot(id) )
    {
        
set_task(0.1"CheckCvars"id)
    }
}

public 
CheckCvarsid )
{
    if( 
is_user_connected(id) )
    {
        new 
cvar_index[1]
        for(new 
ii<sizeof(g_szCvarsNames); i++)
        {
            
cvar_index[0] = i
            query_client_cvar
(idg_szCvarsNames[i], "CvarResult"sizeof(cvar_index), cvar_index)
        }
    }
}

public 
CvarResult(idszCvar[], szValue[], mParms[])
{
    if( 
is_user_connected(id) )
    {
        
g_flUserCvarsValues[id][mParms[0]] = str_to_float(szValue)
        
query_client_cvar(idszCvar"CvarResult"1mParms)
    }
}

public 
OnCmdStart(idcmd)
{
    if( !
is_user_alive(id) )
    {
        return
    }

    static 
Float:movebuttonsFloat:normalmove
    buttons 
get_uc(cmdUC_Buttons)

    if( 
buttons & (IN_FORWARD|IN_BACK) != (IN_FORWARD|IN_BACK) )
    {
        
normalmove 0.0
        get_uc
(cmdUC_ForwardMovemove)
        
        if( 
buttons IN_FORWARD )
        {
            
normalmove += g_flUserCvarsValues[id][FORWARD_SPEED]
        }
        else
        {
            
normalmove += g_flUserCvarsValues[id][BACK_SPEED]
        }
        
        if( 
move == normalmove g_flUserCvarsValues[id][MOVE_SPEED_KEY] )
        {
            
g_bIsWalking[id] = true
            
return
        }
    }

    if( 
buttons & (IN_MOVELEFT|IN_MOVERIGHT) != (IN_MOVELEFT|IN_MOVERIGHT) )
    {
        
normalmove 0.0
        get_uc
(cmdUC_SideMovemove)
        
        if( 
buttons IN_MOVELEFT )
        {
            
normalmove -= g_flUserCvarsValues[id][SIDE_SPEED]
        }
        else
        {
            
normalmove += g_flUserCvarsValues[id][SIDE_SPEED]
        }
        
        if( 
move == normalmove g_flUserCvarsValues[id][MOVE_SPEED_KEY] )
        {
            
g_bIsWalking[id] = true
            
return
        }
    }
    
g_bIsWalking[id] = false


Client code :
Spoiler



I haven't implemented anything with upspeed because there is no IN_UP and IN_DOWN so any attempt wouldn't be reliable, also i think it is only used in water ?
__________________
- tired and retired -

- my plugins -

Last edited by ConnorMcLeod; 04-01-2013 at 13:55.
ConnorMcLeod is offline
Fr33m@n
Veteran Member
Join Date: May 2008
Location: France Marne
Old 04-01-2013 , 07:22   Re: [HowTo] Detect Holding Walk Button (CS 1.6)
Reply With Quote #25

I just tested this version, it doesn't work ConnorMcLeod. The return value is always 0 even if i move the non working get_uc(cmd, UC_Buttons, buttons) by the working buttons = get_uc(cmd, UC_Buttons)
Your previous one in previous pages is working well but sometimes false walk repport.

Last edited by Fr33m@n; 04-01-2013 at 09:57.
Fr33m@n is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 04-01-2013 , 13:55   Re: [HowTo] Detect Holding Walk Button (CS 1.6)
Reply With Quote #26

And with fixed buttons = get_uc(cmd, UC_Buttons) ?
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 01:52.


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