AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Finding User's Pressed Buttons (https://forums.alliedmods.net/showthread.php?t=56381)

Minimum 06-12-2007 19:29

Finding User's Pressed Buttons
 
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.

Drak 06-12-2007 19:33

Re: Finding User's Pressed Buttons
 
Code:
if(pev(id,pev_button) & IN_JUMP) // IN_USE, IN_ATTACK, IN_ATTACK2 , etc, etc else if(pev(id,pev_oldbuttons) & IN_JUMP)

Minimum 06-12-2007 20:18

Re: Finding User's Pressed Buttons
 
Quote:

Originally Posted by SixTwin (Post 488875)
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.

regalis 06-12-2007 20:31

Re: Finding User's Pressed Buttons
 
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

Minimum 06-12-2007 21:02

Re: Finding User's Pressed Buttons
 
Quote:

Originally Posted by regalis (Post 488892)
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.

kmal2t 06-13-2007 01:46

Re: Finding User's Pressed Buttons
 
Maybe you actually used parantheses correctly the first time?

regalis 06-13-2007 07:57

Re: Finding User's Pressed Buttons
 
Quote:

Originally Posted by Minimum (Post 488905)
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

_Master_ 06-13-2007 09:01

Re: Finding User's Pressed Buttons
 
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.

Minimum 06-13-2007 10:19

Re: Finding User's Pressed Buttons
 
Quote:

Originally Posted by regalis (Post 489074)
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_ (Post 489097)
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.


All times are GMT -4. The time now is 10:43.

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