Raised This Month: $32 Target: $400
 8% 

Does AddCommandListener(OnUse, "+use"); work?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Kailo
Senior Member
Join Date: Sep 2014
Location: Moscow, Russia
Old 06-07-2015 , 17:50   Does AddCommandListener(OnUse, "+use"); work?
Reply With Quote #1

How i can hook when player pressed in use button?
i tried
PHP Code:
AddCommandListener(OnUse"+use"); 
but it don't work.

Last edited by Kailo; 06-07-2015 at 17:50.
Kailo is offline
DarkDeviL
SourceMod Moderator
Join Date: Apr 2012
Old 06-07-2015 , 18:03   Re: Does AddCommandListener(OnUse, "+use"); work?
Reply With Quote #2

Quote:
Originally Posted by Kailo View Post
How i can hook when player pressed in use button?
i tried
PHP Code:
AddCommandListener(OnUse"+use"); 
but it don't work.
Your title asks if it works, however, you just said it doesn't work, ... so I guess you have your answer on that part...

Anyway, there's something about the buttons here:

https://sm.alliedmods.net/api/index....d=show&id=820&
https://sm.alliedmods.net/api/index....ad=file&id=47&

And this one seem to have something useful too, including some examples.


BTW, have you tried without the "+" in your AddCommandListener?
__________________
Mostly known as "DarkDeviL".

Dropbox FastDL: Public folder will no longer work after March 15, 2017!
For more info, see the [SRCDS Thread], or the [HLDS Thread].
DarkDeviL is offline
Dr. Api
BANNED
Join Date: Mar 2015
Location: France
Old 06-08-2015 , 03:29   Re: Does AddCommandListener(OnUse, "+use"); work?
Reply With Quote #3

PHP Code:
/***********************************************************/
/************************* JUMP ****************************/
/***********************************************************/
bool Jump(int client)
{
    if((
GetClientButtons(client) & IN_JUMP) && InTheAir(client) && C_State[client] != 512)
    {
        
PrintToDev(B_cvar_active_animations_dev"Jump");
        
C_State[client] = 512;
        return 
true;
    }
    return 
false;
}

/***********************************************************/
/********************** IN THE AIR *************************/
/***********************************************************/
bool InTheAir(int client)
{
    if(!(
GetEntityFlags(client) & FL_ONGROUND))
    {
        return 
true;
    }
    return 
false;

for use: IN_USE
Dr. Api is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 06-08-2015 , 11:33   Re: Does AddCommandListener(OnUse, "+use"); work?
Reply With Quote #4

If you really want to replicate +use using OnPlayerRunCmd, you should store the player's old buttons so know when they first press use.

i.e.

PHP Code:
#include <sdktools>

new oldButtons[MAXPLAYERS];

public 
OnPlayerRunCmd(client, &buttons, &impulseFloat:vel[3], Float:angles[3], &weapon, &subtype, &cmdnum, &tickcount, &seedmouse[2])
{
    if (
buttons IN_USE == IN_USE && oldButtons[client] & IN_USE != IN_USE)
    {
        
// Client just started pressing the use key AKA +use
    
}
    else
    if (
buttons IN_USE != IN_USE && oldButtons[client] & IN_USE == IN_USE)
    {
        
// client just stopped pressing the use key AKA -use
    
}

    
oldButtons[client] = buttons// store the old buttons for later
}

public 
OnClientDisconnect_Post(client)
{
    
oldButtons[client] = 0;

__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
Kailo
Senior Member
Join Date: Sep 2014
Location: Moscow, Russia
Old 06-08-2015 , 12:51   Re: Does AddCommandListener(OnUse, "+use"); work?
Reply With Quote #5

I tried OnPlayerRunCmd, but when u press in use and at once next press out. It will be fired OnPlayerRunCmd 7-8 times. And always fire if you hold use. But I need only once then you press in.

Last edited by Kailo; 06-08-2015 at 12:52.
Kailo is offline
Darkness_
Veteran Member
Join Date: Nov 2014
Old 06-08-2015 , 13:09   Re: Does AddCommandListener(OnUse, "+use"); work?
Reply With Quote #6

Quote:
Originally Posted by Kailo View Post
I tried OnPlayerRunCmd, but when u press in use and at once next press out. It will be fired OnPlayerRunCmd 7-8 times. And always fire if you hold use. But I need only once then you press in.
Then just add a cooldown.

PHP Code:
//Globals
g_bOnCoolDown[MAXPLAYERS+1] = {false, ...};

//Within OnPlayerRunCmd
if (!g_bOnCoolDown[client]) { 
    
//Your function
    
g_bOnCoolDown[client] = true;
   
CreateTimer(5.0RemoveCooldownGetClientUserId(client), TIMER_FLAG_NO_MAPCHANGE);
}

//Remove the cooldown
public Action RemoveCooldown(Handle timerany userId) {
    
//get the client from userid
    
g_bOnCoolDown[client] = false;
    return 
Plugin_Stop;


Last edited by Darkness_; 06-08-2015 at 13:11.
Darkness_ is offline
DarkDeviL
SourceMod Moderator
Join Date: Apr 2012
Old 06-08-2015 , 13:11   Re: Does AddCommandListener(OnUse, "+use"); work?
Reply With Quote #7

Quote:
Originally Posted by Kailo View Post
I tried OnPlayerRunCmd, but when u press in use and at once next press out. It will be fired OnPlayerRunCmd 7-8 times. And always fire if you hold use. But I need only once then you press in.
Powerlord's example above with checking for the old ("previous") buttons should fix that.
__________________
Mostly known as "DarkDeviL".

Dropbox FastDL: Public folder will no longer work after March 15, 2017!
For more info, see the [SRCDS Thread], or the [HLDS Thread].
DarkDeviL is offline
Kailo
Senior Member
Join Date: Sep 2014
Location: Moscow, Russia
Old 06-08-2015 , 13:28   Re: Does AddCommandListener(OnUse, "+use"); work?
Reply With Quote #8

Quote:
Originally Posted by arne1288 View Post
Powerlord's example above with checking for the old ("previous") buttons should fix that.
No, it is not option. I told thet it fires 7-8 times. Resulting in i will got 4-th +use fired.
Cooldown is not option too. I don't want limit players.
And any one know why AddCommandListener(OnUse, "+use"); doesn't work?
Kailo is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 06-08-2015 , 13:34   Re: Does AddCommandListener(OnUse, "+use"); work?
Reply With Quote #9

Quote:
Originally Posted by Kailo View Post
No, it is not option. I told thet it fires 7-8 times. Resulting in i will got 4-th +use fired.
Cooldown is not option too. I don't want limit players.
And any one know why AddCommandListener(OnUse, "+use"); doesn't work?
It has always worked for me, you must be writing the logic wrong.
You cannot listen to a command that is not sent to the server. (i.e. player use is sent as a user command or something another.)

Last edited by Mitchell; 06-08-2015 at 13:35.
Mitchell is offline
DarkDeviL
SourceMod Moderator
Join Date: Apr 2012
Old 06-08-2015 , 13:35   Re: Does AddCommandListener(OnUse, "+use"); work?
Reply With Quote #10

Quote:
Originally Posted by Kailo View Post
No, it is not option. I told thet it fires 7-8 times. Resulting in i will got 4-th +use fired.
Cooldown is not option too. I don't want limit players.
And any one know why AddCommandListener(OnUse, "+use"); doesn't work?
From above:

Quote:
Originally Posted by arne1288 View Post
BTW, have you tried without the "+" in your AddCommandListener?
__________________
Mostly known as "DarkDeviL".

Dropbox FastDL: Public folder will no longer work after March 15, 2017!
For more info, see the [SRCDS Thread], or the [HLDS Thread].
DarkDeviL is offline
Reply


Thread Tools
Display Modes

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 21:24.


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