Raised This Month: $ Target: $400
 0% 

Knowing if player is moving


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Greyscale
SourceMod Plugin Approver
Join Date: Dec 2007
Location: strYoMommasHouse[you];
Old 12-27-2007 , 23:56   Knowing if player is moving
Reply With Quote #1

Is there any method of checking if a player is currently holding down the "+forward" key? I don't just want to know if they are moving, I need to make sure they are moving forward, is there any consistent way of checking for this?

Thanks,
Greyscale
Greyscale is offline
pRED*
Join Date: Dec 2006
Old 12-28-2007 , 01:52   Re: Knowing if player is moving
Reply With Quote #2

Code:
new buttons = GetEntData(client, Prop_Data, "m_nButtons")

Code:
#define IN_ATTACK		(1 << 0)
#define IN_JUMP			(1 << 1)
#define IN_DUCK			(1 << 2)
#define IN_FORWARD		(1 << 3)
#define IN_BACK			(1 << 4)
#define IN_USE			(1 << 5)
#define IN_CANCEL		(1 << 6)
#define IN_LEFT			(1 << 7)
#define IN_RIGHT		(1 << 8)
#define IN_MOVELEFT		(1 << 9)
#define IN_MOVERIGHT	(1 << 10)
#define IN_ATTACK2		(1 << 11)
#define IN_RUN			(1 << 12)
#define IN_RELOAD		(1 << 13)
#define IN_ALT1			(1 << 14)
#define IN_ALT2			(1 << 15)
#define IN_SCORE		(1 << 16)   // Used by client.dll for when scoreboard is held down
#define IN_SPEED		(1 << 17)	// Player is holding the speed key
#define IN_WALK			(1 << 18)	// Player holding walk key
#define IN_ZOOM			(1 << 19)	// Zoom key for HUD zoom
#define IN_WEAPON1		(1 << 20)	// weapon defines these bits
#define IN_WEAPON2		(1 << 21)	// weapon defines these bits
#define IN_BULLRUSH		(1 << 22)
#define IN_GRENADE1		(1 << 23)	// grenade 1
#define IN_GRENADE2		(1 << 24)	// grenade 2
Add any defines you are going to use at the top of your plugin.

Then you can do

Code:
if (buttons & IN_FORWARD) { //stuff }
I think you can also use 'm_nImpulse' to check impulse commands. Theres a list of what they do (in HL2) in player.cpp in the sdk

Last edited by pRED*; 12-28-2007 at 01:56.
pRED* is offline
pRED*
Join Date: Dec 2006
Old 12-28-2007 , 02:12   Re: Knowing if player is moving
Reply With Quote #3

To make this easier, I've added the defines and a stock function for this. Update to sourcemod revision 1832 (should be available in about an hour)

Code:
new buttons = GetClientButtons(client);

if (buttons & IN_FORWARD)
{
	//stuff
}
The full list of defines is in entity_prop_stocks.inc
pRED* is offline
Greyscale
SourceMod Plugin Approver
Join Date: Dec 2007
Location: strYoMommasHouse[you];
Old 12-28-2007 , 14:10   Re: Knowing if player is moving
Reply With Quote #4

Thanks a lot, appreciate that a lot
Greyscale is offline
Greyscale
SourceMod Plugin Approver
Join Date: Dec 2007
Location: strYoMommasHouse[you];
Old 12-28-2007 , 14:58   Re: Knowing if player is moving
Reply With Quote #5

Hm, now if I could know when the player releases their forward key (-forward) then that would be awesome, but I can work around it if it's too much trouble or not even possible.
Greyscale is offline
kirewv
Senior Member
Join Date: Oct 2007
Old 03-25-2008 , 16:38   Re: Knowing if player is moving
Reply With Quote #6

Quote:
Originally Posted by Greyscale View Post
Hm, now if I could know when the player releases their forward key (-forward) then that would be awesome, but I can work around it if it's too much trouble or not even possible.
if(buttons == 0) would mean nothing is pressed and therefore the client is not moving

Last edited by kirewv; 03-25-2008 at 19:22.
kirewv is offline
Nican
Veteran Member
Join Date: Jan 2006
Location: NY
Old 03-25-2008 , 19:10   Re: Knowing if player is moving
Reply With Quote #7

Quote:
Originally Posted by kirewv View Post
if(buttons = 0) would mean nothing is press ie not moving
No, buttons can also represent, firing, ducking...

The whole list is on the first page >.<
__________________
http://www.nican132.com
I require reputation!
Nican is offline
Send a message via ICQ to Nican Send a message via MSN to Nican
Greyscale
SourceMod Plugin Approver
Join Date: Dec 2007
Location: strYoMommasHouse[you];
Old 12-28-2007 , 21:12   Re: Knowing if player is moving
Reply With Quote #8

I just tried your example and it didn't work, but it's not the stock itself, it's the check you suggested using. It seems to always pass no matter what buttons are held down. When the player is moving forward it is printed as an "8" so I'll just check if it's equal to 8.
Greyscale is offline
pRED*
Join Date: Dec 2006
Old 12-28-2007 , 22:24   Re: Knowing if player is moving
Reply With Quote #9

You sure you did
Code:
if (buttons & IN_FORWARD)
not
Code:
if (buttons && IN_FORWARD)
?

Quite a difference.
pRED* is offline
Greyscale
SourceMod Plugin Approver
Join Date: Dec 2007
Location: strYoMommasHouse[you];
Old 12-28-2007 , 22:33   Re: Knowing if player is moving
Reply With Quote #10

Yeah I'm sure.

It passed every time, did you try it?
Greyscale 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 07:06.


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