AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Need help with the get_user_button(id) (https://forums.alliedmods.net/showthread.php?t=108409)

K.K.Lv 11-05-2009 00:53

Need help with the get_user_button(id)
 
Anyone can tell me how to use get_user_button(id) !
I want to hook drop key when the current weapon is knife !
or can some one give me a example !
Thx !!:up:

Arkshine 11-05-2009 04:09

Re: Need help with the get_user_button(id)
 
get_user_button() gives you the button that a player is pressing.

See hlsdk_const.inc :

Code:

#define IN_ATTACK                      (1<<0)
#define IN_JUMP                        (1<<1)
#define IN_DUCK                        (1<<2)
#define IN_FORWARD                      (1<<3)
#define IN_BACK                        (1<<4)
#define IN_USE                          (1<<5)
#define IN_CANCEL                      (1<<6)
#define IN_LEFT                        (1<<7)
#define IN_RIGHT                        (1<<8)
#define IN_MOVELEFT                    (1<<9)
#define IN_MOVERIGHT                    (1<<10)
#define IN_ATTACK2                      (1<<11)
#define IN_RUN                          (1<<12)
#define IN_RELOAD                      (1<<13)
#define IN_ALT1                        (1<<14)
#define IN_SCORE                        (1<<15)

To hook a drop, you can hook "drop" with register_clcmd(). But you can not drop a knife.

K.K.Lv 11-05-2009 04:53

Re: Need help with the get_user_button(id)
 
Thx, I know this !may be my en is so poor! I want to player press twice drop key to hook some, because I have seen a plugin can do it ! but the author did not show the code out !
so i try to write a code that like his plugin!

ConnorMcLeod 11-05-2009 06:23

Re: Need help with the get_user_button(id)
 
You don't need button for this.

PHP Code:

#include <amxmodx>

public plugin_init()
{

    
register_clcmd("drop""ClientCommand_Drop")
}

public 
ClientCommand_Dropid )
{
    if( 
is_user_alive(id) && get_user_weapon(id) == CSW_KNIFE )
    {
        
// execute your code here


        
return PLUGIN_HANDLED // this prevent the message "can't drop this weapon" from showing
    
}
    return 
PLUGIN_CONTINUE



K.K.Lv 11-05-2009 07:37

Re: Need help with the get_user_button(id)
 
Quote:

Originally Posted by ConnorMcLeod (Post 981376)
You don't need button for this.

I mean press twice drop key !
your code just once !

ConnorMcLeod 11-05-2009 07:49

Re: Need help with the get_user_button(id)
 
PHP Code:

#include <amxmodx>

#define MAX_INTERVAL    0.5

#define MAX_PLAYERS 32

new Float:g_fLastGameTimeDoprKeyPressed[MAX_PLAYERS+1]

public 
plugin_init()
{
    
register_clcmd("drop""ClientCommand_Drop")
}

public 
ClientCommand_Dropid )
{
    if( 
is_user_alive(id) && get_user_weapon(id) == CSW_KNIFE )
    {
        
// execute your code here
        
new Float:flGameTime get_gametime()
        if( 
flGameTime g_fLastGameTimeDoprKeyPressed[id] < MAX_INTERVAL )
        {
            
g_fLastGameTimeDoprKeyPressed[id] = 0.0
            
// execute code below
            
        
}
        else
        {
            
g_fLastGameTimeDoprKeyPressed[id] = flGameTime
        
}
        return 
PLUGIN_HANDLED // this prevent the message "can't drop this weapon" from showing
    
}
    return 
PLUGIN_CONTINUE



K.K.Lv 11-05-2009 08:23

Re: Need help with the get_user_button(id)
 
thx!!
+K


All times are GMT -4. The time now is 17:31.

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