AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   How to get The Key Down And Up Event (https://forums.alliedmods.net/showthread.php?t=57008)

spider853 06-26-2007 08:29

How to get The Key Down And Up Event
 
Hi, I Need To Get The +USE and -USE Events... I tried to make something like this
register_clcmd("+use","cl_used",0);
register_clcmd("-use","cl_useu",0);

but it isn't work..

please Help Me

Alka 06-26-2007 08:31

Re: How to get The Key Down And Up Event
 
Fakemeta way:

Code:

static button
button = pev(id,pev_button)
 
if(button & IN_USE)
{
    //do something
}

EDIT:Oh...sorry dunno!

spider853 06-26-2007 08:35

Re: How to get The Key Down And Up Event
 
I know how to check if is a Key but I need to react when a User Press Key "E" and When He Release it

:(

Arkshine 06-26-2007 08:52

Re: How to get The Key Down And Up Event
 
It may helps a little : http://forums.alliedmods.net/showthread.php?t=56872

and with :

Quote:

// Attack buttons
UC_Buttons, // unsigned short

regalis 06-26-2007 08:56

Re: How to get The Key Down And Up Event
 
To check if button is pressed:
Code:

public plugin_init()
{
    register_forward(FM_CmdStart, "fwd_CmdStart");
}

public fwd_CmdStart(id, uc_handle, seed)
{
    new buttons = get_uc(uc_handle, UC_Buttons);
    if(buttons & IN_USE)
    {
        //do something...
    }
}

But i dunno how to check when the key is released.
*edit* Greenberet have the better version..0o *edit*

greetz regalis

Greenberet 06-26-2007 08:58

Re: How to get The Key Down And Up Event
 
alka isnt far away.
fakemeta:
Code:
public plugin_init() {     register_forward(FM_PlayerPreThink, "prethink") } public prethink( id ) {      static button,oldbuttons;      button = pev( id, pev_button );      oldbuttons = pev( id, pev_oldbuttons );      if(button & IN_USE && !(oldbuttons & IN_USE))      {            // +use      } else if( oldbuttons & IN_USE && !(button & IN_USE))      {           // -use      } }

@regalis
your version has the problem that +use will allways be executed as long as it got pressed

Alka 06-26-2007 08:59

Re: How to get The Key Down And Up Event
 
0o...huh :P...you'r right Greenberet! :wink:

spider853 06-26-2007 09:07

Re: How to get The Key Down And Up Event
 
BIG THX TO ALL FOR HELP... thx Greenberet

but i how to get rid of that warning message

Warning: Loose indentation on line 15

public plugin_init() {
register_plugin(PLUGIN, VERSION, AUTHOR)
// Add your code here...
register_forward(FM_PlayerPreThink, "prethink",0) //LINE 15 (WARNING)
}
public prethink( id )
{
static button,oldbuttons;
button = pev( id, pev_button );
oldbuttons = pev( id, pev_oldbuttons );
if(button & IN_USE && !(oldbuttons & IN_USE))
{
console_print(id,"USE DOWN");
} else if( oldbuttons & IN_USE && !(button & IN_USE))
{
console_print(id,"USE UP");
}
}

Arkshine 06-26-2007 09:11

Re: How to get The Key Down And Up Event
 
You have to indent your code properly.

Code:
public plugin_init() {     register_plugin( PLUGIN, VERSION, AUTHOR );     register_forward( FM_PlayerPreThink, "prethink",0 ); } public prethink( id ) {     static button,oldbuttons;     button = pev( id, pev_button );         oldbuttons = pev( id, pev_oldbuttons );         if( button & IN_USE && !(oldbuttons & IN_USE) )     {         console_print( id,"USE DOWN");     }     else if( oldbuttons & IN_USE && !( button & IN_USE ) )     {         console_print( id, "USE UP" );     } }

spider853 06-26-2007 09:19

Re: How to get The Key Down And Up Event
 
Ouch.. Works )) thx


All times are GMT -4. The time now is 21:30.

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