AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Button only pressed once (https://forums.alliedmods.net/showthread.php?t=222732)

Randomize 08-06-2013 02:28

Button only pressed once
 
How to detect if user press a button only once? I don't want fakemeta's way because when I pressed it, it detect many times. I use this with fakemeta:
PHP Code:

public pforward(id)
{
    static 
ButtonOldButton;
    
    
Button pevidpev_button )
    
OldButton pevidpev_oldbuttons )
    
    if (!(
Button IN_RELOAD) || !(Button IN_USE) || !(Button IN_ATTACK) || !(Button IN_ATTACK2))
    {
        if (
Button IN_FORWARD)
        {
            if (
g_running == 0)
            {
                
client_cmd(id"+fastrun")
                
client_printidprint_center"RUN" )
            }
            
g_running 1
        
}
        else if ((
OldButton IN_FORWARD) && !(Button IN_FORWARD))
        {
            if (
g_running == 1)
            {
                
client_cmd(id"-fastrun")
                
client_printidprint_center"STOP")
            }
            
g_running 0
        
}
    }



Randomize 08-06-2013 04:40

Re: Button only pressed once
 
No, I mean, if I use client_PreThink it looks like this in console:

+fastrun
+fastrun
+fastrun
+fastrun
+fastrun
+fastrun
+fastrun
+fastrun
+fastrun
+fastrun
+fastrun
+fastrun
+fastrun
+fastrun

It's kind of flood, right? I don't want it, I just want to detect if I press forward button only once. I use that for playing animation, so the animation won't play if I use fakemeta because the animation starts from begining.

Bos93 08-06-2013 09:08

Re: Button only pressed once
 
#define m_afButtonPressed 246
#define m_afButtonReleased 247

vamppa 08-06-2013 10:38

Re: Button only pressed once
 
how about fire?
would it be possible to check when an person pressed the fire button?

Bos93 08-06-2013 10:45

Re: Button only pressed once
 
Ham_Weapon_PrimaryAttack

Randomize 08-06-2013 11:23

Re: Button only pressed once
 
Bos93, thanks :D work very nice

Randomize 08-06-2013 21:11

Re: Button only pressed once
 
Hey, need help with this! When I'm reloading and press the IN_FORWARD button, the reload animation stops. How could I prevent IN_FORWARD button when I was reloading?

PHP Code:

public client_PostThink(id)
{    
    if(
is_user_alive(id) && get_pdata_int(idm_afButtonPressedXO_PLAYER) & IN_FORWARD)
    {
        
g_reload 1
    
}
    if (
g_reload == 0)
    {
        if(
is_user_alive(id) && get_pdata_int(idm_afButtonPressedXO_PLAYER) & IN_FORWARD)
        {
            
client_cmd(id"+fastrun")
            
client_printidprint_center"STAY" )
        }
        else if(
is_user_alive(id) && get_pdata_int(idm_afButtonReleasedXO_PLAYER) & IN_FORWARD)
        {
            
client_cmd(id"-fastrun")
            
client_printidprint_center"RUN")
        }
    }




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

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