AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Double button press check (https://forums.alliedmods.net/showthread.php?t=330776)

musti132 02-20-2021 14:50

Double button press check
 
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.

SaBBa 02-20-2021 15:10

Re: Double button press check
 
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



musti132 02-20-2021 15:47

Re: Double button press check
 
Quote:

Originally Posted by SaBBa (Post 2737630)
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();
    } 



All times are GMT -4. The time now is 11:01.

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