GetButtons (script event)
Game class
This event operates on an instance of the game class type {{{gameclass}}}
Description
Returns the button state from the current user command.
Usage
float getButtons( )
Parameters
- tba
Examples
float userbuttons,
btn0,
btn1,
btn2,
btn3,
btn4,
btn5,
btn6,
btn7;
userbuttons = $player1.getButtons();
btn0 = 1 & userbuttons;
btn1 = 2 & userbuttons;
btn2 = 4 & userbuttons;
btn3 = 8 & userbuttons;
btn4 = 16 & userbuttons;
btn5 = 32 & userbuttons;
btn6 = 64 & userbuttons;
btn7 = 128 & userbuttons;
if (btn0) {
sys.println("Attack was pressed.");
}
if (btn1) {
sys.println("Run was pressed.");
}
if (btn2) {
sys.println("Zoom was pressed.");
}
if (btn3) {
sys.println("Scores was pressed.");
}
if (btn4) {
sys.println("Mouse look was pressed.");
}
if (btn5) {
sys.println("Button 5 was pressed.");
}
if (btn6) {
sys.println("Button 6 was pressed.");
}
if (btn7) {
sys.println("Button 7 was pressed.");
}
Notes
The value returned bares relation to the status of eight possible buttons as defined in the SDK under UsercmdGen.h…
// usercmd_t->button bits
const int BUTTON_ATTACK = BIT(0);
const int BUTTON_RUN = BIT(1);
const int BUTTON_ZOOM = BIT(2);
const int BUTTON_SCORES = BIT(3);
const int BUTTON_MLOOK = BIT(4);
const int BUTTON_5 = BIT(5);
const int BUTTON_6 = BIT(6);
const int BUTTON_7 = BIT(7);
Each button’s status is stored as a single bit in a eight bit binary number. Each button is represented by either a 1 or 0 which corresponds with either an on or off state. The resulting binary number therefore represents the status of each button.
The example above depicts a way to determine which buttons are being pressed via getButtons.