AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Snippets and Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=112)
-   -   [SNIPPET] Detecting button presses (and releases) (https://forums.alliedmods.net/showthread.php?t=151142)

shavit 04-09-2016 16:33

Re: [SNIPPET] Detecting button presses (and releases)
 
Quote:

Originally Posted by mottzi (Post 2408302)
@psychonic why are you creating the variable inside the loop?

nothing stops you from making it static globally and setting a value inside

mottzi 04-09-2016 17:38

Re: [SNIPPET] Detecting button presses (and releases)
 
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.

humbugtheman 04-10-2016 06:01

Re: [SNIPPET] Detecting button presses (and releases)
 
What makes you think that "defining a variable inside a loop" is a bad habit????

mottzi 04-10-2016 10:04

Re: [SNIPPET] Detecting button presses (and releases)
 
After some research on the internet I found that I'm wrong about the variables. Somehow I thought it would be inefficient. :)

Spirit_12 01-17-2018 19:40

Re: [SNIPPET] Detecting button presses (and releases)
 
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.

psychonic 01-17-2018 19:53

Re: [SNIPPET] Detecting button presses (and releases)
 
Quote:

Originally Posted by Spirit_12 (Post 2572626)
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).

hmmmmm 03-09-2018 17:55

Re: [SNIPPET] Detecting button presses (and releases)
 
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

Spirit_12 08-15-2018 16:26

Re: [SNIPPET] Detecting button presses (and releases)
 
Quote:

Originally Posted by hmmmmm (Post 2582164)
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?

hmmmmm 08-16-2018 02:49

Re: [SNIPPET] Detecting button presses (and releases)
 
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.


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

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