AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Solved Button Press Detection Issues (https://forums.alliedmods.net/showthread.php?t=325754)

Ravrob 07-05-2020 06:45

Button Press Detection Issues
 
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!");
                }
        }
}


Silvers 07-05-2020 13:24

Re: Button Press Detection Issues
 
You should be using "OnPlayerRunCmd" why are you using "OnGameFrame" for this?

See here:

https://forums.alliedmods.net/showthread.php?t=151142

PC Gamer 07-05-2020 16:56

Re: Button Press Detection Issues
 
Quote:

Originally Posted by Ravrob (Post 2708713)
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



Ravrob 07-05-2020 22:21

Re: Button Press Detection Issues
 
That worked just fine! Thanks for your help :D 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".


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

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