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

Hooking player actions (+reload, +attack2, etc)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
epicoder
Junior Member
Join Date: Oct 2012
Old 04-07-2014 , 14:51   Hooking player actions (+reload, +attack2, etc)
Reply With Quote #1

I'm trying to write a plugin that involves giving a player noclip while attack2 is held. Here is the gist of what I have:

Code:
public OnPluginStart() {
    AddCommandListener(Lst_Noclip, "+attack2");
    AddCommandListener(Lst_Noclip, "-attack2");
}

public Action:Lst_Noclip(client, const String:command[], argc) {
    if (command[0] == '+') {
        SetEntityMoveType(client, MOVETYPE_NOCLIP);
    } else {
        SetEntityMoveType(client, MOVETYPE_WALK);
    }
    return Plugin_Continue;
}
(in the actual code, I have all the check that player is alive/in-game/etc. This is a simplified version)

As far as I can tell, the listener is not even getting called at all. I've tried putting PrintToChat debug lines in there, typing +attack2 in console rather than pressing the button, just about anything I could think of.

I came up with an alternate version that involves checking each usercmd for attack2 using OnPlayerRunCmd, but that seemed a bit expensive and I was hoping to avoid it. Is what I'm trying to do possible with the method I'm using?
__________________
Missile ponies aren't everything in life, you know. But I have three, so I still win.

Last edited by epicoder; 04-07-2014 at 14:55.
epicoder is offline
wyd3x
Senior Member
Join Date: Sep 2012
Old 04-07-2014 , 14:54   Re: Hooking player actions (+reload, +attack2, etc)
Reply With Quote #2

try that :

PHP Code:
public Action:OnPlayerRunCmd(client, &buttons)
{
    if (
buttons & +attack2)
    {
        
// do that
    
} else if (buttons & -attack2) {
       
// do that

__________________
my plugins:
deleter v2.1 || [Store] Chat Color (1.2) - csgo || [Store] Award winner team
need a private plugin?
contact with me: PM, EMAIL: [email protected], discord: wyd3x #2096
private plugins: Hunger Games, [Store] Lottery, [Store] Gamble, VIP

Last edited by wyd3x; 04-07-2014 at 14:54.
wyd3x is offline
captaindeterprimary
AlliedModders Donor
Join Date: Sep 2012
Old 04-07-2014 , 14:55   Re: Hooking player actions (+reload, +attack2, etc)
Reply With Quote #3

Quote:
Originally Posted by wyd3x View Post
try that :

PHP Code:
public Action:OnPlayerRunCmd(client, &buttons)
{
    if (
buttons & +attack2)
    {
        
// do that
    
} else if (buttons & -attack2) {
       
// do that

Why not do a case switch?
__________________
Last edited by ; Today at 08:20 AM. Reason: Get rid of s
captaindeterprimary is offline
wyd3x
Senior Member
Join Date: Sep 2012
Old 04-07-2014 , 14:57   Re: Hooking player actions (+reload, +attack2, etc)
Reply With Quote #4

My mistake. try that:
PHP Code:
public Action:OnPlayerRunCmd(client, &buttons)
{
    if (
buttons IN_ATTACK)
    {
        
// do that
    
} else if (buttons IN_ATTACK2) {
       
// do that


Quote:
Originally Posted by vman315 View Post
Why not do a case switch?
hmmm.. I don`t know XD
__________________
my plugins:
deleter v2.1 || [Store] Chat Color (1.2) - csgo || [Store] Award winner team
need a private plugin?
contact with me: PM, EMAIL: [email protected], discord: wyd3x #2096
private plugins: Hunger Games, [Store] Lottery, [Store] Gamble, VIP

Last edited by wyd3x; 04-07-2014 at 14:58.
wyd3x is offline
epicoder
Junior Member
Join Date: Oct 2012
Old 04-07-2014 , 15:00   Re: Hooking player actions (+reload, +attack2, etc)
Reply With Quote #5

While I appreciate your response, I already have that code... Like I said, I was hoping to avoid OnPlayerRunCmd. It seems a little expensive for what I want to do. What I want to know is whether I will have to use OnPlayerRunCmd or not.
__________________
Missile ponies aren't everything in life, you know. But I have three, so I still win.
epicoder is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 04-07-2014 , 15:13   Re: Hooking player actions (+reload, +attack2, etc)
Reply With Quote #6

Quote:
Originally Posted by vman315 View Post
Why not do a case switch?
Because buttons is a bitfield not an enum.

Incidentally, to track when a person presses or lets go of IN_ATTACK2, you're going to have to track what it was on the previous OnPlayerRunCmd as it fires continually as long as the player is doing things.
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 04-07-2014 at 15:14.
Powerlord is offline
Mathias.
Veteran Member
Join Date: Aug 2010
Location: Canada is my city
Old 04-07-2014 , 15:56   Re: Hooking player actions (+reload, +attack2, etc)
Reply With Quote #7

Quote:
Originally Posted by epicoder View Post
While I appreciate your response, I already have that code... Like I said, I was hoping to avoid OnPlayerRunCmd. It seems a little expensive for what I want to do. What I want to know is whether I will have to use OnPlayerRunCmd or not.
Well nvm you idea than. It the way to track players action, people are afraid of calling codes in gameframes. It only bad if you do something crazy like accessing a keyvalue/create temporary entity/etc.. If you plan to declare variables use static and your all set.

Last edited by Mathias.; 04-07-2014 at 15:57.
Mathias. is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 04-07-2014 , 16:38   Re: Hooking player actions (+reload, +attack2, etc)
Reply With Quote #8

I dont under stand how it's expensive to use OnPlayerRunCmd?
something like this to make a toggle command:
Code:
public Action:OnPlayerRunCmd(iClient, &buttons, &impulse, Float:vel[3], Float:angles[3], &weapon)
{
	if (!IsClientConnected(iClient) || !IsClientInGame(iClient) || !IsPlayerAlive(iClient)) return Plugin_Continue;
	static bool:bIsInAttack[MAXPLAYERS+1];
	if (!bIsInAttack[iClient] && buttons & IN_ATTACK)
	{
		bIsInAttack[iClient] = true;
		SomeOtherFunction(iClient);
	}
	else
	{
		bIsInAttack[iClient] = false;
	}
	return Plugin_Continue;
}
bit tired so it might be wrong

Last edited by Mitchell; 04-07-2014 at 16:49.
Mitchell is offline
captaindeterprimary
AlliedModders Donor
Join Date: Sep 2012
Old 04-07-2014 , 17:23   Re: Hooking player actions (+reload, +attack2, etc)
Reply With Quote #9

Quote:
Originally Posted by Powerlord View Post
Because buttons is a bitfield not an enum.

Incidentally, to track when a person presses or lets go of IN_ATTACK2, you're going to have to track what it was on the previous OnPlayerRunCmd as it fires continually as long as the player is doing things.
Huh, I didn't know this.
__________________
Last edited by ; Today at 08:20 AM. Reason: Get rid of s
captaindeterprimary is offline
epicoder
Junior Member
Join Date: Oct 2012
Old 04-07-2014 , 20:55   Re: Hooking player actions (+reload, +attack2, etc)
Reply With Quote #10

Quote:
Originally Posted by Black-Rabbit View Post
Well nvm you idea than. It the way to track players action, people are afraid of calling codes in gameframes. It only bad if you do something crazy like accessing a keyvalue/create temporary entity/etc.. If you plan to declare variables use static and your all set.
Ok, I will keep this in mind.

Quote:
Originally Posted by Mitchell View Post
I dont under stand how it's expensive to use OnPlayerRunCmd?
I run my server on budget hardware that has barely enough memory to run srcds + sm core along with the other software stacks I run on it, and the CPU is not exactly a beast either. As such, I try to consider the impact of everything I am doing... Checking each and every usercmd when only one client will be allowed to do this in the end just seemed a bit excessive to me. But if that's the only way to do it, that's the only way to do it. Thanks for the information.
__________________
Missile ponies aren't everything in life, you know. But I have three, so I still win.
epicoder 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 07:01.


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