RUST: Making New Buttons for Your MOD Last edited 1 year ago2022-09-29 07:53:55 UTC

Introduction

Allows you to add custom buttons to your MOD

Step 1: open file input.cpp

you need to first create a variable, typically global to the file which is a "kbutton_t"

you'll find a lot of these declared at once in input.cpp, so add something like:
kbutton_t in_my_new_button;
Or whatever you want to call it :P

Step 2: Specify the Command you want to use

Each button has a command, e.g. attack has +attack as a console command

You need to create a command in console from it as well, you can do this by using pfnAddCommand()

Although first you need to make a function which just makes the key down or up (pressed or released)

So you need to make TWO functions and TWO pfnAddCommand statements. Have a look...
// pressed button
void IN_My_New_Button_Down(void)
{
      KeyDown( &in_my_new_button );
}

// released button
void IN_My_New_Button_Up(void)
{
      KeyUp( &in_my_new_button );
}
There is also a place in input.cpp where a lot of pfnAddCommand()'s are made. Add your commands there.

you need to specify the command you want it to be and the name of the function which deals with it that you just made above. For example:
gEngfuncs.pfnAddCommand ("+my_button", IN_My_New_Button_Down);
gEngfuncs.pfnAddCommand ("-my_button", IN_My_New_Button_Up);
remember your button whatever you want.

Step 3: Giving the button an ID

Each button has a cont=stant identification to know what buttons are pressed. e.g. Attack has the constant IN_ATTACK, we want to make our own.

Now you should make a new bit for your button that will work with 'pev->button' in entvars.

Define it in input.h, as follows:
#define IN_MY_NEW_BUTTON (1<<16)

Step 4: Check if button is pressed

That's your new button's bit mask set that you can check in game if it is pressed.

Now you've done that you can go down into the CL_ButtonBits() function. Like this:
int CL_ButtonBits( int bResetState )
Add some new code to add your new bitmask to the bits pressed when your button in_my_new_button's state is 3 (i Think!)

Here is an example:
if ( in_my_new_button.state & 3 )
{
      bits |= IN_MY_NEW_BUTTON;
}

Step 5: Resetting the button State

You also have to add the button when your resetting the state at the bottom of the function.. where it has all of this stuff..
if ( bResetState )
{
      in_attack.state &= ~2;
      in_duck.state &= ~2;
         ...
         ...
  }
so now just add..
in_my_new_button.state &= ~2;

Finished

That's it. You have just codified your first button in Half-life. Congratulation!!!
This article was originally published on Gamedesign.net RUST.
The original URL of the article was http://www.gamedesign.net/node/539.
The archived page is available here.
TWHL only publishes archived articles from defunct websites, or with permission. For more information on TWHL's archiving efforts, please visit the TWHL Archiving Project page.

Comments

You must log in to post a comment. You can login or register a new account.