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

Check if player sends +jump, -jump, +duck, -duck, etc.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
phayzee
New Member
Join Date: Sep 2021
Old 10-07-2022 , 14:04   Check if player sends +jump, -jump, +duck, -duck, etc.
Reply With Quote #1

Hi.

I'm trying to find out if there's any way to check if a player sends some specific commands (+jump, -jump, +moveleft, +moveright, etc.).

This is what I tried so far, but it doesn't seem to work as it print nothing to the console.

PHP Code:
#include <amxmodx>

public plugin_init() {
    
register_plugin("Log commands""0.1""tester");

    
register_clcmd("+jump""jumpExecuted");
    
register_clcmd("-jump""jumpTerminated");
}

public 
jumpExecuted(id) {
    
console_print(id"+jump executed");

    return 
PLUGIN_HANDLED;
}

public 
jumpTerminated(id) {
    
console_print(id"-jump executed");

    return 
PLUGIN_HANDLED;

phayzee is offline
jimaway
Heeeere's Jimmy!
Join Date: Jan 2009
Location: Estonia
Old 10-07-2022 , 15:50   Re: Check if player sends +jump, -jump, +duck, -duck, etc.
Reply With Quote #2

Code:
/**
     * Description:     Typically called every frame when a player has jump held.
     * Forward params:  function(this)
     * Return type:     None.
     * Execute params:  ExecuteHam(Ham_Player_Jump, this);
     */
    Ham_Player_Jump,

    /**
     * Description:     Typically called every frame when a player has duck held.
     *                  This function is not supported in Earth's Special Forces mod.
     * Forward params:  function(this)
     * Return type:     None.
     * Execute params:  ExecuteHam(Ham_Player_Duck, this);
     */
    Ham_Player_Duck

Last edited by jimaway; 10-07-2022 at 15:51.
jimaway is offline
phayzee
New Member
Join Date: Sep 2021
Old 10-07-2022 , 16:47   Re: Check if player sends +jump, -jump, +duck, -duck, etc.
Reply With Quote #3

That seems good, for now.
1. But what about the corresponding -command for each of them? How can I see when is that called (-jump, -duck, for example)

2. Is there anything similar for +moveright, +moveleft, +forward, +back etc. ? Or for any other commands that might exist (+speed, +use, etc.)
phayzee is offline
Mistrick
Senior Member
Join Date: Aug 2012
Location: Russia
Old 10-08-2022 , 07:19   Re: Check if player sends +jump, -jump, +duck, -duck, etc.
Reply With Quote #4

PHP Code:
#include <amxmodx>
#include <fakemeta>

public plugin_init()
{
    
register_forward(FM_PlayerPreThink"FM_PlayerPreThink_Pre"false);
}
public 
FM_PlayerPreThink_Pre(id)
{
    new 
buttonsold_buttons;
    
buttons pev(idpev_button);
    
old_buttons pev(idpev_oldbuttons);

    if(
buttons IN_BACK && ~old_buttons IN_BACK) {
        
client_print(idprint_chat"BACK Pressed");
    }
    
    if(
buttons IN_BACK) {
        
client_print(idprint_chat"BACK Active");
    }
    
    if(~
buttons IN_BACK && old_buttons IN_BACK) {
        
client_print(idprint_chat"BACK Released");
    }

Change IN_BACK to another constant to check another button. Don't work for +speed.
Mistrick is offline
MrPickles
Senior Member
Join Date: Aug 2022
Location: Colombia
Old 10-10-2022 , 01:08   Re: Check if player sends +jump, -jump, +duck, -duck, etc.
Reply With Quote #5

PHP Code:
if(entity_get_intClientEV_INT_button ) & // Holding Jump
if(!entity_get_intClientEV_INT_button ) & // Not Holding Jump

if(entity_get_intClientEV_INT_button ) & // Holding Duck

/*
    0 - IDLE
    1 - MOUSE1
    2048 - MOUSE2
    512 - MOVE LEFT
    1024 - MOVE RIGHT
    8 - MOVE FORWARD
    16 - MOVE BACKWARDS
    2 - JUMP
    4 - CTRL
    32768 - TAB
    8192 - RELOAD
    32 - USE       */ 

Last edited by MrPickles; 10-10-2022 at 01:09.
MrPickles is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 10-11-2022 , 00:08   Re: Check if player sends +jump, -jump, +duck, -duck, etc.
Reply With Quote #6

Quote:
Originally Posted by MrPickles View Post
PHP Code:
if(!entity_get_intClientEV_INT_button ) & // Not Holding Jump 
When negating a value being used to store bit-wise values, you should use a tilde (~) instead of an exclamation (!).

PHP Code:
if( ~entity_get_intClientEV_INT_button ) & // Not Holding Jump 
Alternatively, you can force the bitwise comparison to occur first and then you can use the exclamation:

PHP Code:
if( !(entity_get_intClientEV_INT_button ) & 2) ) // Not Holding Jump 
__________________

Last edited by fysiks; 10-11-2022 at 00:10.
fysiks is offline
MrPickles
Senior Member
Join Date: Aug 2022
Location: Colombia
Old 10-11-2022 , 18:31   Re: Check if player sends +jump, -jump, +duck, -duck, etc.
Reply With Quote #7

Quote:
Originally Posted by fysiks View Post
When negating a value being used to store bit-wise values, you should use a tilde (~) instead of an exclamation (!).

PHP Code:
if( ~entity_get_intClientEV_INT_button ) & // Not Holding Jump 

PHP Code:
if( ~entity_get_intClientEV_INT_button ) & // Not Holding Jump 

=>

PHP Code:
if( entity_get_intClientEV_INT_button ) & ~// Not Holding Jump 
============================================

PHP Code:
if( !(entity_get_intClientEV_INT_button ) & 2) ) // Not Holding Jump 
and yes, i forget the () before the exclamation

Last edited by MrPickles; 10-11-2022 at 18:34.
MrPickles is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 10-12-2022 , 00:10   Re: Check if player sends +jump, -jump, +duck, -duck, etc.
Reply With Quote #8

Quote:
Originally Posted by MrPickles View Post
PHP Code:
if( entity_get_intClientEV_INT_button ) & ~// Not Holding Jump 
No. Doing the bitwise NOT on the 2 will not work, you must do it how I wrote. This is what will happen:

Code:
   0b11010101 (buttons value with second bit not set)
 & 0b11111101 (~2)
 = 0b11010101 (evalutates as true)


   0b11010111 (buttons value with second bit set)
 & 0b11111101 (~2)
 = 0b11010101 (same exact result as above)
As you can see, it will return true for both pressed and not pressed except when no other buttons are pressed which cannot be guaranteed (which is why the buttons are stored in bitwise fashion).
__________________
fysiks 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 19:55.


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