Binding More Than One Function to a Single Key

by Montag451


  This tutorial is designed to demonstrate how to bind more then one function to a single key. For those who have played many of the various team modifications available for Quake 2 they know that to be an effective team player communication is of a primary concern. Coordinating your activity with that of your team and allowing others to know your position and status are two very crucial components to mounting a successful defense or offense. Further, anybody who has been left in charge of the defense of your base knows how hard it can be to mount a successful stand against a well armed, and coordinated offense. Often times a well-stocked defender can mean the difference between a successful capture for your team or one for the opposing team.

  So know you may ask "how am I a supposed to fit all of these commands on my keyboard"? Well it can be quite difficult, especially if you play more then one position throughout the course of the game; however, there are a few options available and varied use of them can make for an effective keyboard layout.

  If you are new to scripting it is recommended that you read the other tutorials on this page.

Overlay scripts

  Overlay scripts are a fairly simple way to make semi-permanent changes to your keyboard layout. This type of script is useful for changing the messages on your keyboard depending on which position you are playing. Lets say for example you are currently patrolling the midfield in a CTF game, and get called back to help defend your base. Chances are you need to communicate different things to your teammates then you did when you are on patrol.

  First you will need to break your messages apart into different categories, for example offensive, defensive patrol, and permanent messages, then take a look at your current message bindings and assign one from each category to your existing message keys (except for the permanent ones). You may want to rearrange their layout, but it shouldn't matter all that much because it will take you a little time to get used to the new settings anyway =).

  So after you spent some time figuring out which keys you want to use and which messages go to which keys then you are ready to start writing the config files you will need. First thing you will need is to create one file for each set of messages you created, say offmsgs.cfg, defmsgs.cfg and patmsgs.cfg. You can store one set of each in the directory of every mod you plan on using them in. However, if you plan on using identical messages in each mod then you can simplify your upkeep. Check Cycho's bit on maintainability.

  Now that you have each of the files with the appropriate binds in each your almost done. The final step is to add three lines to your autoexec.cfg, or you can create another file called something like msgswitch.cfg and add a line executing that file from your autoexec.cfg (i.e. exec "msgswitch.cfg"). Whichever you choose, just make sure that you end up with three buttons bound to execute the files you created. Here is a sample using the names from above.

//Message switcher

bind INS "exec defmsgs.cfg"
bind END "exec offmsgs.cfg"
bind PGDN "exec patmsgs.cfg"

  Now whenever you hit the Delete key you will change all of your messages to those you have in your defmsgs.cfg file. The same is true for the END and PAGE DOWN keys. On a final note since all of your messages are now bound to different files you may want to execute a default message set when you start the game. Choose the position you play most often and execute that file from either the msgswitch.cfg file or your autoexec.cfg. That's it you can now change what messages you have bound with the switch of a key.

Toggle Switches

  The other way of binding more then one action to a key is by use of toggle keys. This method also requires making more then one .cfg file, however this one is dependent on which key you choose to use as a toggle key. We will be centering this example on the keypad. We will develop a set of .cfg files that will allow you to change several aspects of your game play on the fly. When we are finished with this section we will be able to drop weapons, ammo, and supplies for defensive teammates. In this example we will use the kp_ins (0 key on the keypad) to drop weapons and the kp_del (the . on the keypad) to drop ammo.

  A few files will be needed to pull this off; first you will need one .cfg for each set of actions you are creating, and one to control the toggle function. The first file we will create will be the ones for the weapons. Since there are nine droppable weapons and nine numeric keys on the keypad we shouldn't have any problems, however, if you are playing LMCTF then you may find yourself a key short since they have added the plasma rifle. In cases like that you can either double up on one key or you can use one of the keys from the top row. Create a new text file and call it drpweap.cfg

// Drop Weapon Script for toggle switch

bind kp_end "drop shotgun"
bind kp_downarrow "drop super shotgun"
bind kp_pgdn "drop machinegun"
bind kp_leftarrow "drop chaingun"
bind kp_5 "drop grenade launcher"
bind kp_rightarrow "drop rocket launcher"
bind kp_home "drop hyperblaster; wait; drop plasma rifle"  
bind kp_uparrow "drop railgun"
bind kp_pgup "drop bfg10k"    	//A lot of servers disable the BFG 
				//so you may not need this one.

  The next file we need is one that will drop the ammo and items. So create a new text file and name it drpitm.cfg

//Drop Items config for toggle switch

bind kp_end "drop shells"
bind kp_downarrow  "drop grenades"
bind kp_pgdn "drop bullets"
bind kp_leftarrow "drop rockets"
bind kp_5 "drop cells"
bind kp_rightarrow "drop slugs"
bind kp_home "drop quad damage"	//Only usable if Instant Items
				//is not enabled on the server
bind kp_uparrow "drop power shield; wait; drop power screen"
bind kp_pgup "drop flag"

  The toggle switch will execute the files we have just created for as long as the toggle key is held down. So we will need another file to return the keys to their default state when you release the toggle key. So create another text file and call it rtrn.cfg. In this file you will rebind all of the keys you have bound in the files above to their default value. Well those files will allow you to drop the weapons and items as well as define the keys default values. Now we need to add a final file that will allow you to toggle these functions on and off. To create the toggle switch create another text file and call it ts.cfg. This file will provide the actual functionality. This file will need to be executed from your autoexec.cfg. ts.cfg will be a relatively short file it will only the information need for the toggle switch itself.

  Each toggle switch should look like this.

alias +drpwpn "exec drpweap.cfg"	//the plus key means that
					//the alias is only active
					//while the key it is bound
					//to is held down
alias –drpwpn "exec rtrn.cfg"	// this is the action that will be
				// executed when you release the key
				// +drpweap is bound to
bind kp_ins "+drpwpn"

  Now when you hold down the kp_ins it will execute the file we created to drop weapons, and when you release it the rtrn.cfg will execute returning the key binds to their default values.

  So a complete ts.cfg for the files we made above would look like this.

// Toggle switch
alias +drpwpn "exec drpweap.cfg"
alias –drpwpn "exec rtrn.cfg"
alias +drpitem "exec drpitm.cfg"
alias –drpitem "exec rtrn.cfg"
bind kp_ins "+drpwpn"
bind kp_del "+drpitem"

  Well that will do it. After you add a line to execute the ts.cfg in your autoexec.cfg you will be ready to go. If all that toggle scripting seems like too much then you should check out Oster's Binder. He has released version 2.0 and you can bind up to 4 keys to a single action. It has lots of other good features you can check it out at http://www.planetquake.com/otser/