Raised This Month: $32 Target: $400
 8% 

How long a button has been held?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Drak
Veteran Member
Join Date: Jul 2005
Old 06-26-2008 , 16:33   How long a button has been held?
Reply With Quote #1

I'm trying to fire an event when the Attack button is held down for 4 seconds.
How can I do this?
Code:
client_PreThink(id) {     if(!is_user_alive(id))         return PLUGIN_HANDLED         if(pev(id,pev_button) & IN_ATTACK))     {               RunEvent(); // I want this called 4 seconds after holding the attack button.     } }
__________________
Oh yeah
Drak is offline
Send a message via MSN to Drak
Lee
AlliedModders Donor
Join Date: Feb 2006
Old 06-26-2008 , 16:50   Re: How long a button has been held?
Reply With Quote #2

Code:
public client_PreThink(id) {     if(!is_user_alive(id))         return;         static Float:pressTime[33];         if(~pev(id, pev_button) & IN_ATTACK)     {         pressTime[id] = 0.0;     }     else if(!pressTime[id])     {         pressTime[id] = get_gametime();     }     else if(get_gametime() < pressTime[id] + 4.0)     {         RunEvent();     } }
__________________
No support via PM.

Last edited by Lee; 06-26-2008 at 16:55.
Lee is offline
stupok
Veteran Member
Join Date: Feb 2006
Old 06-26-2008 , 20:47   Re: How long a button has been held?
Reply With Quote #3

How about this, so you can avoid client_prethink()?

Code:
register_forward(FM_CmdStart, "fwdCmdStart");   public fwdCmdStart(id, uc_handle, uc_seed) {     if(!is_user_alive(id))         return FMRES_IGNORED;       static iButton;     iButton = get_uc(uc_handle, UC_Buttons);         static Float:pressTime[33];         if(~iButton & IN_ATTACK)     {         pressTime[id] = 0.0;     }     else if(!pressTime[id])     {         pressTime[id] = get_gametime();     }     else if(get_gametime() < pressTime[id] + 4.0)     {         RunEvent();     }     return FMRES_IGNORED; }
__________________
stupok is offline
Emp`
AMX Mod X Plugin Approver
Join Date: Aug 2005
Location: Decapod 10
Old 06-27-2008 , 01:38   Re: How long a button has been held?
Reply With Quote #4

Quote:
Originally Posted by stupok69 View Post
How about this, so you can avoid client_prethink()?

Code:
register_forward(FM_CmdStart, "fwdCmdStart");   public fwdCmdStart(id, uc_handle, uc_seed) {     if(!is_user_alive(id))         return FMRES_IGNORED;       static iButton;     iButton = get_uc(uc_handle, UC_Buttons);         static Float:pressTime[33];         if(~iButton & IN_ATTACK)     {         pressTime[id] = 0.0;     }     else if(!pressTime[id])     {         pressTime[id] = get_gametime();     }     else if(get_gametime() < pressTime[id] + 4.0)     {         RunEvent();     }     return FMRES_IGNORED; }
because that wouldn't work?
Emp` is offline
Send a message via AIM to Emp` Send a message via MSN to Emp` Send a message via Yahoo to Emp` Send a message via Skype™ to Emp`
Greenberet
AMX Mod X Beta Tester
Join Date: Apr 2004
Location: Vienna
Old 06-27-2008 , 03:44   Re: How long a button has been held?
Reply With Quote #5

and how about:
Code:
    else if(!pressTime[id])
    {
        pressTime[id] = get_gametime() + 4.0;
    }
    else if(get_gametime() < pressTime[id])
    {
        RunEvent();
    }
__________________
Greenberet is offline
Send a message via ICQ to Greenberet Send a message via MSN to Greenberet
Reply



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 20:52.


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