AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Code Snippets/Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=83)
-   -   [TUT] Using Button Constants (https://forums.alliedmods.net/showthread.php?t=40210)

Hawk552 06-24-2006 21:20

[TUT] Using Button Constants
 
This is a duplicate of the tutorial I made in the AMWiki in this URL: http://wiki.tcwonline.org/index.php/Button_constants

Usage

Button constants are generally used to determine when an entity is doing a certain action, such as jumping, attacking, or moving. This is used because +/- commands cannot be hooked by the HL engine (if they are made by the HL engine).
For example, this would work:
Code:
register_concmd("+explode","hook_explode")

However this would not:
Code:
register_concmd("+attack","hook_attack")
Why? Because the client does not literally send "+attack" over the reliable stream, since this would cause massive lag. Instead, an integer is sent, which is easier on bandwidth.


Constants

A full list of constants can be found here: http://amxmodx.org/funcwiki.php?go=m...#const_buttons


Implementation

If, for example, it is desired to check when a player is attacking, one would use the following:
Code:
#include <amxmodx> #include <engine> public plugin_init() {     register_plugin("Attack Test","1.0","Hawk552"); } public client_PreThink(id) {     if(entity_get_int(id,EV_INT_BUTTON) & IN_ATTACK)     {         // do something     } }
Notice how this uses the & operator, rather than the && operator. This is because a bit value is returned, and the & operator checks if a bit value is contained in another bit value.
To set an entity's button, the same type of idea can be implemented:
Code:
#include <amxmodx> #include <engine> public plugin_init() {     register_plugin("Attack Test","1.0","Hawk552"); } public client_PreThink(id) {     entity_set_int(id,EV_INT_button,IN_ATTACK); }
This sets the client's attack flag to on every time a frame is rendered.
To get an entity's buttons, and then ommit a certain button, one would use the following:
Code:
#include <amxmodx> #include <engine> public plugin_init() {     register_plugin("Attack Test","1.0","Hawk552"); } public client_PreThink(id) {     entity_set_int(id,EV_INT_button,entity_get_int(id,EV_INT_button) & ~IN_ATTACK); }
Say, for example, during a certain time, the client is jumping and attacking at the same time. In this case, the entity_get_int(id,EV_INT_button) function would return IN_ATTACK and IN_JUMP. Using the ~ operator removes the certain bit value, making it into merely IN_JUMP.
There are many more ways to use button constants, and not all must be used on players. They are simply more commonly implemented when dealing with players.

SweatyBanana 06-25-2006 03:04

Re: Using Button Constants
 
Cool man..

Did u ust make these up or are they from other places?

Hawk552 06-25-2006 08:37

Re: Using Button Constants
 
Quote:

Originally Posted by SweatyBanana
Cool man..

Did u ust make these up or are they from other places?

If you read the first sentence in the post you would know.

3xr 06-25-2006 09:10

Re: Using Button Constants
 
Is their any alternative to catching a client command thats a HL registered one... but not buttons like +attack and such. I want to do something for ESF, but since I can only do a +Powerup one time... I can't seem to think of a work around since I am new to AMXX scripting(the natives mainly).

Hawk552 06-25-2006 09:16

Re: Using Button Constants
 
Quote:

Originally Posted by 3xr
Is their any alternative to catching a client command thats a HL registered one... but not buttons like +attack and such. I want to do something for ESF, but since I can only do a +Powerup one time... I can't seem to think of a work around since I am new to AMXX scripting(the natives mainly).

This is being answered in AIM. (user talked to me there like a minute after he posted this)

drekes 06-25-2010 10:36

Re: [TUT] Using Button Constants
 
Do i have to check if he is alive to? Or doesn't this work with dead players?

ConnorMcLeod 06-25-2010 11:01

Re: [TUT] Using Button Constants
 
Quote:

Originally Posted by drekes (Post 1219455)
This works fine with dead players !


drekes 06-25-2010 11:59

Re: [TUT] Using Button Constants
 
So does that mean if a dead player uses +attack it will be executing the code to? I'm confused.

Alka 06-25-2010 12:03

Re: [TUT] Using Button Constants
 
Yes.

drekes 06-25-2010 12:03

Re: [TUT] Using Button Constants
 
Okay, thanks guys

EDIT: EV_INT_BUTTON gives undefined symbol here.

EDIT2: nevermind, it was EV_INT_button.


All times are GMT -4. The time now is 22:29.

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