Difference between revisions of "Button constants (AMX Mod X)"

From AlliedModders Wiki
Jump to: navigation, search
 
(Constants)
 
(5 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 +
{{LanguageSwitch}}
 +
 +
 
==Usage==
 
==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).
 
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:
 
For example, this would work:
<pre>
+
<pawn>register_concmd("+explode","explode");</pawn>
register_concmd("+explode","explode");
 
</pre>
 
  
 
However this would not:
 
However this would not:
<pre>
+
<pawn>register_concmd("+attack","hook_attack");</pawn>
register_concmd("+attack","hook_attack");
 
</pre>
 
  
 
==Constants==
 
==Constants==
  
A full list of constants can be found here:
+
A full list of constants can be found [http://amxmodx.org/api/hlsdk_const#pev-entity-pev-button-or-pev-entity-pev-oldbuttons-values/ here].
http://amxmodx.org/funcwiki.php?go=module&id=3#const_buttons
 
  
 
==Implementation==
 
==Implementation==
 
If, for example, it is desired to check when a player is attacking, one would use the following:
 
If, for example, it is desired to check when a player is attacking, one would use the following:
<pre>
+
<pawn>#include <amxmodx>
#include <amxmodx>
 
 
#include <engine>
 
#include <engine>
  
Line 34: Line 31:
 
// do something
 
// do something
 
}
 
}
}
+
}</pawn>
</pre>
 
  
 
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.
 
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:
 
To set an entity's button, the same type of idea can be implemented:
<pre>
+
<pawn>#include <amxmodx>
#include <amxmodx>
 
 
#include <engine>
 
#include <engine>
  
Line 52: Line 47:
 
{
 
{
 
entity_set_int(id,EV_INT_button,IN_ATTACK);
 
entity_set_int(id,EV_INT_button,IN_ATTACK);
}
+
}</pawn>
</pre>
 
  
 
This sets the client's attack flag to ''on'' every time a frame is rendered.  
 
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:
 
To get an entity's buttons, and then ommit a certain button, one would use the following:
<pre>
+
<pawn>#include <amxmodx>
#include <amxmodx>
 
 
#include <engine>
 
#include <engine>
  
Line 70: Line 63:
 
{
 
{
 
entity_set_int(id,EV_INT_button,entity_get_int(id,EV_INT_button) & ~IN_ATTACK);
 
entity_set_int(id,EV_INT_button,entity_get_int(id,EV_INT_button) & ~IN_ATTACK);
}
+
}</pawn>
</pre>
 
  
 
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.
 
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.
 
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.
 +
 +
[[Category:Scripting (AMX Mod X)]]

Latest revision as of 14:56, 30 August 2017

Warning: This template (and by extension, language format) should not be used, any pages using it should be switched to Template:Languages

View this page in:  English  Russian  简体中文(Simplified Chinese)


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:

register_concmd("+explode","explode");

However this would not:

register_concmd("+attack","hook_attack");

Constants

A full list of constants can be found here.

Implementation

If, for example, it is desired to check when a player is attacking, one would use the following:

#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:

#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:

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