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

From AlliedModders Wiki
Jump to: navigation, search
(redirect)
 
(18 intermediate revisions by 4 users not shown)
Line 1: Line 1:
* [[index.php?title=Button_constants_%28AMX_Mod_X%29&action=edit|Оригинал]]
+
#REDIRECT [[Ru:Button_constants_(AMX_Mod_X)]]
 
 
==Использование==
 
Кнопочные константы обычно используются для того, чтобы "поймать" момент, когда entity совершает какое либо действие, такое как прыжки, передвижение или атака. Метод используется из-за того, что жвижок ХЛ не может "поймать" +/- команды
 
 
 
Например, Это будет работать:
 
<pre>
 
register_concmd("+explode","explode");
 
</pre>
 
 
 
А это - нет:
 
<pre>
 
register_concmd("+attack","hook_attack");
 
</pre>
 
 
 
==Константы==
 
 
 
Полный список всех констант вы можете найти здесь:
 
http://amxmodx.org/funcwiki.php?go=module&id=3#const_buttons
 
 
 
==Как все это замутить?==
 
Вот, например, один из вариантов, как "поймать" момент, когда игрок атакует:
 
<pre>
 
#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
 
}
 
}
 
</pre>
 
 
 
Обратите внимание, что используется оператор & , в отличии от оператора &&. Оператор & проверяет, содержится ли бит после оператора в бите до него, т.е. в данном случае проверяется, есть ли среди нажатых кнопок игрока кнопка IN_ATTACK
 
 
 
Чтобы заставить энтити эмулировать нажатие кнопки можно поступить следующим образом:
 
<pre>
 
#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);
 
}
 
</pre>
 
 
 
Этот пример будет ставить флаг кнопки атаки в положение "ВКЛ" каждый раз, когда рендерится кадр.
 
 
 
To get an entity's buttons, and then ommit a certain button, one would use the following:
 
<pre>
 
#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);
 
}
 
</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.
 
 
 
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 05:25, 6 November 2008