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

Double button press check


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
musti132
New Member
Join Date: Feb 2021
Old 02-20-2021 , 14:50   Double button press check
Reply With Quote #1

Hello, I have been trying to make a check to see if the "W" button has been pressed twice. I have tried multiple methods from the forums and my own, but none of them seemed to work.

What I have atm
PHP Code:
    static buttonsoldbuttons;

    
leap_time get_gametime()

    
buttons get_uc(handleUC_Buttons);
    
oldbuttons pev(idpev_oldbuttons); 

    if (!
g_isbot[id] && IN_FORWARD)
        
last_button_press get_gametime();


    
// Not doing a longjump (don't perform check for bots, they leap automatically)
    
if (!g_isbot[id] && !IN_FORWARD && buttons != oldbuttons && (leap_time last_button_press) < 0.5)
        return; 
The original code is from zombie plague 4.3 mod, I have tried to modify it to perform a long jump/leap when a user presses the "W" or forward button twice.
musti132 is offline
SaBBa
Member
Join Date: Dec 2012
Old 02-20-2021 , 15:10   Re: Double button press check
Reply With Quote #2

I might be wrong, but if forward button is pressed twice within 0.5 sec (not required to press them in a row), make_leap func will be executed

PHP Code:
new Float:buttonPressed[33] = 0

public plugin_init()
{
     
register_clcmd("forward""hook_command")
}

public 
hook_command(id)
{
     new 
Float:currentTime get_gametime()
     if(
is_user_bot(id))
          return 
PLUGIN_CONTINUE
     
if((currentTime buttonPressed[id]) < 0.5) {
          
// make_leap(id) or whatever you want
     
} else {
          
buttonPressed[id] = currentTime
     
}
     return 
PLUGIN_CONTINUE

__________________

Last edited by SaBBa; 02-21-2021 at 19:54.
SaBBa is offline
musti132
New Member
Join Date: Feb 2021
Old 02-20-2021 , 15:47   Re: Double button press check
Reply With Quote #3

Quote:
Originally Posted by SaBBa View Post
I might be wrong, but if forward button is pressed twice within 0.5 sec (not required to press them in a row), make_leap func will be executed

PHP Code:
new Float:buttonPressed 0

public plugin_init()
{
     
register_clcmd("forward""hook_command")
}

public 
hook_command(id)
{
     new 
Float:currentTime get_gametime()
     if(
is_user_bot(id))
          return 
PLUGIN_CONTINUE
     
if((currentTime buttonPressed) < 0.5) {
          
// make_leap(id) or whatever you want
     
} else {
          
buttonPressed currentTime
     
}
     return 
PLUGIN_CONTINUE

Thank you for trying to help, I got it working by looking at this plugin https://forums.alliedmods.net/showthread.php?t=229005 from akcaliberg

I used his method and with a bit of work I got it work.
PHP Code:
    static buttonoldbuttons;

    
button pev(idpev_button);
    
oldbuttons pev(idpev_oldbuttons); 

    if(
button IN_FORWARD && !(oldbuttons IN_FORWARD)) {
        if( (
get_gametime() - LastKeyPressed[id]) < 0.3 ) {
            if (
fm_get_speed(id) < 80)
                return;
            static 
Float:velocity[3]
            
            
// Make velocity vector
            
velocity_by_aim(idg_survivor[id] ? get_pcvar_num(cvar_leapsurvivorforce) : g_nemesis[id] ? get_pcvar_num(cvar_leapnemesisforce) : !g_zombie[id] ? get_pcvar_num(cvar_leaphumanforce) : get_pcvar_num(cvar_leapzombiesforce), velocity)
            
// Set custom height
            
velocity[2] = g_survivor[id] ? get_pcvar_float(cvar_leapsurvivorheight) : g_nemesis[id] ? get_pcvar_float(cvar_leapnemesisheight) : !g_zombie[id] ? get_pcvar_float(cvar_leaphumanheight) : get_pcvar_float(cvar_leapzombiesheight)
            
// Apply the new velocity
            
set_pev(idpev_velocityvelocity)
            
            
// Update last leap time
            
g_lastleaptime[id] = current_time
        
}
        
LastKeyPressed[id] = get_gametime();
    } 
musti132 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 14:35.


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