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

[TUT] Using Button Constants


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 06-24-2006 , 21:20   [TUT] Using Button Constants
Reply With Quote #1

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.
__________________

Last edited by Hawk552; 06-24-2006 at 21:25. Reason: removed spaces and added line ends to make more readable
Hawk552 is offline
Send a message via AIM to Hawk552
SweatyBanana
BANNED
Join Date: Sep 2005
Location: LOL
Old 06-25-2006 , 03:04   Re: Using Button Constants
Reply With Quote #2

Cool man..

Did u ust make these up or are they from other places?
SweatyBanana is offline
Send a message via AIM to SweatyBanana Send a message via Yahoo to SweatyBanana
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 06-25-2006 , 08:37   Re: Using Button Constants
Reply With Quote #3

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.
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
3xr
Junior Member
Join Date: Mar 2005
Old 06-25-2006 , 09:10   Re: Using Button Constants
Reply With Quote #4

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).
3xr is offline
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 06-25-2006 , 09:16   Re: Using Button Constants
Reply With Quote #5

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)
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
drekes
Veteran Member
Join Date: Jul 2009
Location: Vault 11
Old 06-25-2010 , 10:36   Re: [TUT] Using Button Constants
Reply With Quote #6

Do i have to check if he is alive to? Or doesn't this work with dead players?
__________________

Quote:
Originally Posted by nikhilgupta345 View Post
You're retarded.
drekes is offline
Send a message via MSN to drekes
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 06-25-2010 , 11:01   Re: [TUT] Using Button Constants
Reply With Quote #7

Quote:
Originally Posted by drekes View Post
This works fine with dead players !
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
drekes
Veteran Member
Join Date: Jul 2009
Location: Vault 11
Old 06-25-2010 , 11:59   Re: [TUT] Using Button Constants
Reply With Quote #8

So does that mean if a dead player uses +attack it will be executing the code to? I'm confused.
__________________

Quote:
Originally Posted by nikhilgupta345 View Post
You're retarded.
drekes is offline
Send a message via MSN to drekes
Alka
AMX Mod X Plugin Approver
Join Date: Dec 2006
Location: malloc(null)
Old 06-25-2010 , 12:03   Re: [TUT] Using Button Constants
Reply With Quote #9

Yes.
__________________
Still...lovin' . Connor noob! Hello
Alka is offline
drekes
Veteran Member
Join Date: Jul 2009
Location: Vault 11
Old 06-25-2010 , 12:03   Re: [TUT] Using Button Constants
Reply With Quote #10

Okay, thanks guys

EDIT: EV_INT_BUTTON gives undefined symbol here.

EDIT2: nevermind, it was EV_INT_button.
__________________

Quote:
Originally Posted by nikhilgupta345 View Post
You're retarded.

Last edited by drekes; 06-25-2010 at 13:12.
drekes is offline
Send a message via MSN to drekes
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 12:06.


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