View Single Post
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