Raised This Month: $170 Target: $400
 42% 

[SNIPPET] Detecting button presses (and releases)


Post New Thread Reply   
 
Thread Tools Display Modes
shavit
AlliedModders Donor
Join Date: Dec 2011
Location: Israel
Old 04-09-2016 , 16:33   Re: [SNIPPET] Detecting button presses (and releases)
Reply With Quote #11

Quote:
Originally Posted by mottzi View Post
@psychonic why are you creating the variable inside the loop?
nothing stops you from making it static globally and setting a value inside
__________________
My Plugins
Not taking private requests, too busy.
shavit is offline
mottzi
Veteran Member
Join Date: May 2010
Location: Switzerland
Old 04-09-2016 , 17:38   Re: [SNIPPET] Detecting button presses (and releases)
Reply With Quote #12

True, but since this is the Snippets and Tutorials section and many newcommers take code from here I suggest that such bad habits like defining variables inside loops would be avoided. No static needed, the best thing would be to declare the variable outside the loop.
__________________
Quote:
#define true ((rand() % 2)? true: false) //Happy debugging suckers
mottzi is offline
Send a message via MSN to mottzi
humbugtheman
Member
Join Date: Jan 2012
Old 04-10-2016 , 06:01   Re: [SNIPPET] Detecting button presses (and releases)
Reply With Quote #13

What makes you think that "defining a variable inside a loop" is a bad habit????
humbugtheman is offline
mottzi
Veteran Member
Join Date: May 2010
Location: Switzerland
Old 04-10-2016 , 10:04   Re: [SNIPPET] Detecting button presses (and releases)
Reply With Quote #14

After some research on the internet I found that I'm wrong about the variables. Somehow I thought it would be inefficient.
__________________
Quote:
#define true ((rand() % 2)? true: false) //Happy debugging suckers
mottzi is offline
Send a message via MSN to mottzi
Spirit_12
Veteran Member
Join Date: Dec 2012
Location: Toronto, CA
Old 01-17-2018 , 19:40   Re: [SNIPPET] Detecting button presses (and releases)
Reply With Quote #15

Is there a way to hook other buttons that are not on the list? To be specific, I'm trying to hook lastinv or slot1 key presses.
__________________
Spirit_12 is offline
psychonic

BAFFLED
Join Date: May 2008
Old 01-17-2018 , 19:53   Re: [SNIPPET] Detecting button presses (and releases)
Reply With Quote #16

Quote:
Originally Posted by Spirit_12 View Post
Is there a way to hook other buttons that are not on the list? To be specific, I'm trying to hook lastinv or slot1 key presses.
Those are client commands that do not get transmitted to the server (as commands nor buttons). You'd have to watch the weapon parameter in OnPlayerRunCommand for having a value (and then take as-is or infer the command from there).
psychonic is offline
hmmmmm
Senior Member
Join Date: Mar 2017
Location: ...
Old 03-09-2018 , 17:55   Re: [SNIPPET] Detecting button presses (and releases)
Reply With Quote #17

I've found a bit of a sexier way of doing this, just have to get m_afButtonReleased and m_afButtonPressed data props
These variables store the buttons released/pressed that frame, or 0 if nothing was released/pressed
hmmmmm is offline
Spirit_12
Veteran Member
Join Date: Dec 2012
Location: Toronto, CA
Old 08-15-2018 , 16:26   Re: [SNIPPET] Detecting button presses (and releases)
Reply With Quote #18

Quote:
Originally Posted by hmmmmm View Post
I've found a bit of a sexier way of doing this, just have to get m_afButtonReleased and m_afButtonPressed data props
These variables store the buttons released/pressed that frame, or 0 if nothing was released/pressed
Would you be able to post a snippet for that?
__________________
Spirit_12 is offline
hmmmmm
Senior Member
Join Date: Mar 2017
Location: ...
Old 08-16-2018 , 02:49   Re: [SNIPPET] Detecting button presses (and releases)
Reply With Quote #19

PHP Code:
if( GetEntPropclientProp_Data"m_afButtonPressed" ) & IN_USE 
PHP Code:
if( GetEntPropclientProp_Data"m_afButtonReleased" ) & IN_ATTACK 
This works on CS:GO, not sure about other games.
hmmmmm is offline
Reply


Thread Tools
Display Modes

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 08:29.


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