Raised This Month: $ Target: $400
 0% 

Finding User's Pressed Buttons


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Minimum
Senior Member
Join Date: Jun 2006
Old 06-12-2007 , 19:29   Finding User's Pressed Buttons
Reply With Quote #1

I already know how to do this via Engine but not via Fakemeta. I have tried posted methods and they have not worked for me. So I am posting this to ask how would you find buttons a user has pressed at the moment using Fakemeta?

For those who will ask the ultimate question: "Why just not use Engine?" - Fakemeta is less harsh on the CPU and the faster the plugin runs, the better.
Minimum is offline
Send a message via AIM to Minimum Send a message via MSN to Minimum
Drak
Veteran Member
Join Date: Jul 2005
Old 06-12-2007 , 19:33   Re: Finding User's Pressed Buttons
Reply With Quote #2

Code:
if(pev(id,pev_button) & IN_JUMP) // IN_USE, IN_ATTACK, IN_ATTACK2 , etc, etc else if(pev(id,pev_oldbuttons) & IN_JUMP)
__________________
Oh yeah
Drak is offline
Send a message via MSN to Drak
Minimum
Senior Member
Join Date: Jun 2006
Old 06-12-2007 , 20:18   Re: Finding User's Pressed Buttons
Reply With Quote #3

Quote:
Originally Posted by SixTwin View Post
Code:
if(pev(id,pev_button) & IN_JUMP) // IN_USE, IN_ATTACK, IN_ATTACK2 , etc, etc else if(pev(id,pev_oldbuttons) & IN_JUMP)
Not working. I put a server_print inside the if statement to see if it would work, no luck.
Minimum is offline
Send a message via AIM to Minimum Send a message via MSN to Minimum
regalis
Veteran Member
Join Date: Jan 2007
Location: F*cking Germany
Old 06-12-2007 , 20:31   Re: Finding User's Pressed Buttons
Reply With Quote #4

This code will hook ALL available buttons...
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 & (1<<0) || buttons & (1<<1) || buttons & (1<<2) || buttons & (1<<3)
    || buttons & (1<<4) || buttons & (1<<5) || buttons & (1<<6) || buttons & (1<<7) 
    || buttons & (1<<8) || buttons & (1<<9) || buttons & (1<<10) || buttons & (1<<11)
    || buttons & (1<<12) || buttons & (1<<13) || buttons & (1<<14) || buttons & (1<<15))
    {
         // do something
    }
    return FMRES_HANDLED;
}
Here are the button constants: http://www.amxmodx.org/funcwiki.php?...#const_buttons

greetz regalis
__________________
regalis is offline
Minimum
Senior Member
Join Date: Jun 2006
Old 06-12-2007 , 21:02   Re: Finding User's Pressed Buttons
Reply With Quote #5

Quote:
Originally Posted by regalis View Post
This code will hook ALL available buttons...
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 & (1<<0) || buttons & (1<<1) || buttons & (1<<2) || buttons & (1<<3)
    || buttons & (1<<4) || buttons & (1<<5) || buttons & (1<<6) || buttons & (1<<7) 
    || buttons & (1<<8) || buttons & (1<<9) || buttons & (1<<10) || buttons & (1<<11)
    || buttons & (1<<12) || buttons & (1<<13) || buttons & (1<<14) || buttons & (1<<15))
    {
         // do something
    }
    return FMRES_HANDLED;
}
Here are the button constants: http://www.amxmodx.org/funcwiki.php?...#const_buttons

greetz regalis
This was the method I tried before, didn't work before, didn't work now.

Code (plugin_init) -
Code:
    register_forward(FM_CmdStart,"client_WeaponCheck")

Code (plugin_precache) -
Code:
    tazermdl = precache_model("models/Tazer/p_tazer.mdl")     precache_model("models/Tazer/v_tazer.mdl")

Code (Function) -
Code:
public client_WeaponCheck(id,uc_handle,dummy) {     new entid, entbody, origin1[3], origin2[3], weaponmodel     pev(id,pev_weaponmodel,weaponmodel)     new buttons = get_uc(uc_handle, UC_Buttons)     if(buttons & IN_ATTACK && cl_tazercool[id] == 0 && weaponmodel == tazermdl) {

NOTE: This worked perfectly fine using get_user_buttons.

Last edited by Minimum; 06-12-2007 at 21:06.
Minimum is offline
Send a message via AIM to Minimum Send a message via MSN to Minimum
kmal2t
BANNED
Join Date: Apr 2006
Old 06-13-2007 , 01:46   Re: Finding User's Pressed Buttons
Reply With Quote #6

Maybe you actually used parantheses correctly the first time?

Last edited by kmal2t; 06-13-2007 at 01:52.
kmal2t is offline
regalis
Veteran Member
Join Date: Jan 2007
Location: F*cking Germany
Old 06-13-2007 , 07:57   Re: Finding User's Pressed Buttons
Reply With Quote #7

Quote:
Originally Posted by Minimum View Post
This was the method I tried before, didn't work before, didn't work now.
What i have postet works very fine for one of my plugins..
Don't know where exactly your problem is!?
Maybe post more code and describe WHAT is not working! kthx
__________________
regalis is offline
_Master_
Senior Member
Join Date: Dec 2006
Old 06-13-2007 , 09:01   Re: Finding User's Pressed Buttons
Reply With Quote #8

If you used get_user_buttons() then you had a hook to client prethink.
FM_CmdStart is NOT the same as FM_PlayerPreThink (CmdStart is NOT called on every player frame).

Fix: Hook FM_CmdStart (<-check buttons) and FM_PlayerPreThink(<- set model). You could just hook only FM_PlayerPreThink and deal with buttons and models there, but with CmdStart you have a more "instant" action on pressed buttons.
_Master_ is offline
Minimum
Senior Member
Join Date: Jun 2006
Old 06-13-2007 , 10:19   Re: Finding User's Pressed Buttons
Reply With Quote #9

Quote:
Originally Posted by regalis View Post
What i have postet works very fine for one of my plugins..
Don't know where exactly your problem is!?
Maybe post more code and describe WHAT is not working! kthx
I did post what isn't working...

Quote:
Originally Posted by _Master_ View Post
If you used get_user_buttons() then you had a hook to client prethink.
FM_CmdStart is NOT the same as FM_PlayerPreThink (CmdStart is NOT called on every player frame).

Fix: Hook FM_CmdStart (<-check buttons) and FM_PlayerPreThink(<- set model). You could just hook only FM_PlayerPreThink and deal with buttons and models there, but with CmdStart you have a more "instant" action on pressed buttons.
I'll try this.
Minimum is offline
Send a message via AIM to Minimum Send a message via MSN to Minimum
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 10:43.


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