
A toggle alias is where you can press one key to execute different commands each time you press it. This is useful for things that can be turned "on" and "off". With this script you can turn those things "on" by pressing the selected key, and "off" by pressing that key again.
First of all, we need something to toggle on and off. For this example we will use the "cl_showfps" command. If you haven't used this before, it shows your current Frames Per Second (fps) in the top left corner. First we need to create the separate aliases for turning the command on and off:
At the moment this script would work fine, but you would have to bind a key to "fpson" and another key to "fpsoff". So now we need to create the toggling alias. This is done by changing what the alias does after it has been pressed:
So, when you press the key bound to "fpsshow" it will switch the "cl_showfps" command on, and when you press the button again, it will switch it off. All we need to do know is to bind a key to the "fpsshow" command:
There we have it, you have a toggle script. To edit it, you will need to change the command to whatever you want, and make sure you change the "?" to a key!
This is not absolutely essential! This is just to make it a bit more user-friendly by using the "echo" command to tell you if you've turned the command chosen "on" or "off" . We do this by adding this into the alias:
Now we need to add this into the original alias:
If you would like to use this code, just copy and paste this into the correct files, see the Introductory tutorial to find out which.
This concludes my tutorial. I hope you enjoyed it, if you want to use my example, just copy and paste the above aliases into your "autoexec.cfg" and put the bind into your "config.cfg"