Toggling Aliases

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.

Step #1

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:


alias fpson "cl_showfps 1"
alias fpsoff "cl_showfps 0"

Step #2

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:


alias fpson "cl_showfps 1; alias fpsshow fpsoff"
alias fpsoff "cl_showfps 0; alias fpsshow fpson"
alias fpsshow "fpson"

Step #3

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:


alias fpson "cl_showfps 1; alias fpsshow fpsoff"
alias fpsoff " cl_showfps 0; alias fpsshow fpson"
alias fpsshow "fpson"

bind "?" " fpsshow"

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!

Step #4

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:


developer 1; echo FPS Is Currently ON; developer 0
developer 1; echo FPS Is Currently OFF; developer 0

Now we need to add this into the original alias:


alias fpson " developer 1; echo FPS Is Currently ON; developer 0; cl_showfps 1; alias fpsshow fpsoff"
alias fpsoff " developer 1; echo FPS Is Currently OFF; developer 0; cl_showfps 0; alias fpsshow fpson"

The Final Result

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.


alias fpson "developer 1; echo FPS Is Currently ON; developer 0; cl_showfps 1; alias fpsshow fpsoff"
alias fpsoff "developer 1; echo FPS Is Currently OFF; developer 0; cl_showfps 0; alias fpsshow fpson"
alias fpsshow "fpson"

bind "?" "fpsshow"

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"

Add comment

Menu

News
Features
Events
Site
Search UKT:

User



Register here

Shoutbox

Zechs_
*sniff*
04:40 3/9/2008

X
JESUS CHRIST ITS A LION
23:33 27/8/2008

`NWA
lol @ this shoutbox going stron 2 years after the last news item was posted.
02:22 27/8/2008

w1ckedz
I wrote that Culexus comment Myers hahahaha
21:32 25/8/2008

tiz
Stealing is terrible I know! Some ****er even had the cheek to put it on ebay... [ [ expand ]