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

From AlliedModders Wiki
Jump to: navigation, search
 
m (added category)
Line 76: Line 76:
  
 
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)]]

Revision as of 21:50, 19 January 2006

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: http://amxmodx.org/funcwiki.php?go=module&id=3#const_buttons

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.