Raised This Month: $12 Target: $400
 3% 

Detect user key.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Shiina.Mashiro
Senior Member
Join Date: Sep 2014
Location: Vietnam
Old 04-13-2015 , 11:32   Detect user key.
Reply With Quote #1

Hi, I'm trying to detect user using use and attack2 key.
This is what I've tried so far:
PHP Code:
public client_PreThink(id)
{
     if(!
is_user_connected(id))
          return 
PLUGIN_HANDLED
     
new wpn get_user_weapon(id)
     new 
button pev(idpev_button)
     if((
wpn == CSW_KNIFE) && (button IN_USE) && (button IN_ATTACK2))
          
my_function(id)
     return 
PLUGIN_CONTINUE

And this didn't work. Can anyone help me with this?
Thank you.
__________________
Shiina.Mashiro is offline
zmd94
Veteran Member
Join Date: Nov 2013
Location: Malaysia (9w2zow).
Old 04-13-2015 , 11:46   Re: Detect user key.
Reply With Quote #2

Example:
Code:
#include <amxmodx>
#include <fakemeta>
 
public plugin_init()
{
    register_forward(FM_CmdStart, "FwdCmdStart");
}
 
public FwdCmdStart(id, uc_handle)
{
    static Button, OldButtons;
    Button = get_uc(uc_handle, UC_Buttons);
    OldButtons = pev(id, pev_oldbuttons);
 
    if((Button & IN_RELOAD) && !(OldButtons & IN_RELOAD))
    {
        // Player presses reload
    }
   
    if((Button & IN_RELOAD) && (OldButtons & IN_RELOAD))
    {
        // Player is holding down reload
    }
    
    if(!(Button & IN_RELOAD) && (OldButtons & IN_RELOAD))
    {
        // Player releases reload  
    }
}

Last edited by zmd94; 04-13-2015 at 12:02.
zmd94 is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 04-13-2015 , 11:56   Re: Detect user key.
Reply With Quote #3

Something like this works:
PHP Code:
new UserButtonspev(idpev_button)
if(
UserButtons IN_USE && UserButtons IN_ATTACK2)
{
    
//do stuff

In a forward that is called 20 times per second per player you should use static, or even better, search for another way. Start by telling us what you want to do, because in most of cases, you have better options.
__________________
HamletEagle is offline
Shiina.Mashiro
Senior Member
Join Date: Sep 2014
Location: Vietnam
Old 04-13-2015 , 23:00   Re: Detect user key.
Reply With Quote #4

@zmd94
@HamletEagle
Thank to you both, I made it work ^^ Thanks again.
__________________
Shiina.Mashiro is offline
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:48.


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