Another crappy TF2 blog.

Wednesday, April 14, 2010

Scrpiting: Aliases

What I'm going to show here isn't very complicated. I like using my "q" key to switch to my melee weapon and then to press it again to get back to my previous weapon. I'm going to show you how I did it initially, which worked, but not how I really wanted it to, and my revised version. The revised version is also the "proper" way to handle things for when your scripts start getting more complex. To do this, we need to understand aliases.

Aliases all have the same structure:
If there are multiple commands, they are separated by semi-colons(;). Easy enough to understand, I hope.

Version 1 (not recommended, but it gets the job done):

This script does what I want, but not very well. You'll notice that "MELEE" uses the "lastinv" command. It does switch back to the weapon I was using, but it ignores any setting I have in place for either "PRIMARY" or "SECONDARY" (the r_drawviewmodel command, in this case). Plus, if I change my mind about what button I use for melee, I have to change the binding in other places too.

Version 2 (the right way):

This is a much better version that addresses all of the problems that the first script has. I have two different MELEE aliases that differ only in which weapon it will switch back to. Which one is used is determined by PRIMARY and SECONDARY. It happens in the last command of each alias.

I hope that helps. Also, feel free to steal this script if you want.

No comments:

Post a Comment