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

Solved Button Press Detection Issues


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Ravrob
Junior Member
Join Date: Oct 2019
Location: The Ice
Old 07-05-2020 , 06:45   Button Press Detection Issues
Reply With Quote #1

So as far as button detection goes, the only two ways I've really found of doing it is through OnPlayerRunCmd and GetEntProp, I'm using GetEntProp in this instance and I want it to do an action when the button is pressed however while testing this it always seems to trigger multiple times or not at all and I'd like to know if there's a different way to accomplish this or if anyone would know the cause.

Here's the bit I'm using
Code:
public void OnGameFrame() {

	for (int i = 1; i <= MaxClients; i++) {
		if (!IsClientInGame(i) || !IsPlayerAlive(i)) {
			continue;
		}
		
		if(GetEntProp(i, Prop_Data, "m_afButtonReleased") & IN_RELOAD){
			PrintToChat(i, "You pressed the reload key!");
		}
	}
}

Last edited by Ravrob; 07-05-2020 at 22:28.
Ravrob is offline
Silvers
SourceMod Plugin Approver
Join Date: Aug 2010
Location: SpaceX
Old 07-05-2020 , 13:24   Re: Button Press Detection Issues
Reply With Quote #2

You should be using "OnPlayerRunCmd" why are you using "OnGameFrame" for this?

See here:

https://forums.alliedmods.net/showthread.php?t=151142
__________________
Silvers is offline
PC Gamer
Veteran Member
Join Date: Mar 2014
Old 07-05-2020 , 16:56   Re: Button Press Detection Issues
Reply With Quote #3

Quote:
Originally Posted by Ravrob View Post
Here's the bit I'm using
Code:
public void OnGameFrame() {

	if(GetEntProp(i, Prop_Data, "m_afButtonReleased") & IN_RELOAD){
	PrintToChat(i, "You pressed the reload key!");
}
I think you should be using "m_afButtonPressed" to see if a button is pressed.

As Silvers stated you should be using OnPlayerRunCmd.

I too had problems with buttons being pressed. I learned that it was best to use OnPlayerRunCmd to check for button presses. I also learned that a single button press will register LOTS of button presses. To fix that I ended up adding a timer to the button press to ensure that the action couldn't occur again for the duration of the timer.

In this example the action occurs once and is prevented from occurring again for 3 seconds:
PHP Code:
new bool:g_wait[MAXPLAYERS 1]; 

public 
Action:OnPlayerRunCmd(client, &buttons, &impulseFloat:vel[3], Float:angles[3], &weapon

    if(
buttons IN_RELOAD && g_wait[client] == false)         
    { 
        
//insert your command(s) here...

        
g_wait[client] = true;
        
CreateTimer(3.0Waitingclient);
    }
}

public 
Action:Waiting(Handle:timerany:client
{
    
g_wait[client] = false

PC Gamer is offline
Ravrob
Junior Member
Join Date: Oct 2019
Location: The Ice
Old 07-05-2020 , 22:21   Re: Button Press Detection Issues
Reply With Quote #4

That worked just fine! Thanks for your help I was confused about using OnPlayerRunCmd and you really cleared it up for me. I totally understand why I shouldn't have been using OnGameFrame in that situation, I just didn't know any other way to make use of "m_afButtonPressed".
Ravrob 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 04:01.


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