You are currently browsing the Musings from teh M^onk^K weblog archives for June, 2009.
7. June 2009 by Monkk.
While playing Team Fortress 2, I’ve found that some servers are set up for higher bandwidth usage allowing for a smoother game. To really take advantage of that, typically a few client side cvars need to be changed. However, many servers also run the default settings on their server and you’ll need to set the cvars back.
Conveniently, the source engine allows TF2 players the ability to create client side scripts / configs that will automate these changes. I have taken the liberty of creating a config that will let you bind a key to a “nextrate” command which will toggle the cvars between their High and Low rate settings.
First off, I am only changing the values for two CVARS, there may be more and they would be simple to add, but for the sake of this discussion I will be changing “rate” and “cl_updaterate” cvars.
The Low settings are:
rate: 30000
cl_updaterate: 20
The High settings are:
rate: 60000
cl_updaterate: 100
All that really needs to be done is, when connecting to a High rate server, in the console type:
rate 60000;cl_updaterate 100;
And when connecting to a Low rate server, in the console type:
rate 30000;cl_updaterate 20;
but who wants to type that everytime…. So, without further ado, enter the script:
alias ShowHighRateMsg echo rate set to 60000, cl_updaterate set to 100
alias ShowLowRateMsg echo rate set to 30000, cl_updaterate set to 20
alias SetHighrate "rate 60000; cl_updaterate 100;alias nextrate SetLowrate;ShowHighRateMsg;"
alias SetLowrate "rate 30000; cl_updaterate 20;alias nextrate SetHighrate;ShowLowRateMsg"
alias nextrate SetLowRate
nextrate
This uses the alias command which lets you set chains of console commands together and reference later by the name you give the alias.
Above five aliases are created:
1. ShowHighRateMsg – Simply echoes the text we want the user to see in the console after executing the nextrate command to set the High Rate settings
2. ShowLowRateMsg – Simply echoes the text we want the user to see in the console after executing the nextrate command to set the Low Rate settings
3. SetHighRate – Actually sets the cvars for High Rate server use. It also sets the alias for “nextrate” to SetLowRate. This is what implements the Toggle functionality. The user keeps calling “nextrate” and nextrate is pointed to different aliases every time it is called. It also displays the setting changes it is making in the console for the user to see if they bring up the console.
4. SetLowRate – Actually sets the cvars for Low Rate server use. It also sets the alias for “nextrate” to SetHighRate. This is what implements the Toggle functionality. The user keeps calling “nextrate” and nextrate is pointed to different aliases every time it is called. It also displays the setting changes it is making in the console for the user to see if they bring up the console.
5. nextrate – This declares the nextrate alias and by default points it to SetLowRate. This is the alias that you bind to a key. To bind it, it must exist first which is why it is by default pointed to SetHighRate (it assumes you play on more Low Rate servers then High Rate, besides it’s the default value from Valve so, hard to go wrong.)
The final line of the script is a call to nextrate, which as mentioned set to SetLowRate, so this actually execuste the nextrate alias and sets the cvars to Low Rate server use.
You could then bind a key to nextrate and execute it during the game. For example, in the console type:
bind m nextrate
Which will bind your M key to the nextrate alias. Pressing M at this point will execute the nextrate alias whenever it is pressed.
At this point, were you to paste the above script line by line into the console window of TF2, you could call nextrate over and over again and see it change. Well again, who’s going to paste all that in every time?
So you have 2 options at this point. Open up the AutoExec.cfg file in your TF2 cfg directory:
C:\program Files (x86)\steam\steamapps\<YOUR STEAM NAME>\team fortress 2\tf\cfg
and paste the entire script in there. You could also bind it to the key of your choice by adding the bind command from earlier here.
The other option, and I think the cleanest, is to create a new text file called “ServerRateToggle.cfg” in the \cfg\ directory (same place as the AutoExec.cfg) and paste the script into the new file. Then open the AutoExec.cfg and add the following line at the bottom:
exec ServerRateToggle.cfg
now, whenever the AutoExec.cfg file is parsed by TF2 (in this case, every time you start the game) it will execute the Rate toggle script which will reset the values to their defaults. You could also add the bind command in the autoexec.cfg after the call to exec ServerRateToggle and it will be bound forever more for your convenient use.
Here is a link to the ServerRateToggle.cfg to avoid copy and paste errors
Enjoy, and let me know if you come up with anything better or more commands that need to be added to the cvars I’m currently setting!
Posted in Gaming | Print | 1 Comment »
7. June 2009 by Monkk.
This little tutorial will cover making custom TF2 sprays. How to make a static spray, a transparent spray, and animated sprays.
First, to give credit where credit is due. I found the information on making sprays from a few blogs/sites. Unfortunately, there was no comprehensive information for dealing with transparency and animation so this article you are reading now attempts to bring it all together in one place. Here are the direct links to the articles I used as a base:
- “Create Animated Sprays in Team Fortress 2 and Counter-Strike” @ www.maximumpc.com
Resolution: Sprays resolution maximum is: 256 x 256 pixels
They can be smaller, but they can’t be larger! If they are larger the 256 in either width or height, the spray simply will not show.File Size: Currently the Source Engine (the Valve game platform that Team Fortress 2 is built on) has a file size limit for sprays of 120 KB do not exceed that or the spray will simply not work. This usually isn’t an issue with Non-Animated sprays, but Animated ones use 1 image per frame so you’re probably not going to get more than 4 or 5 frames with a resolution of 128 x 128 (note that is smaller then the largest supported spray resolution, we choose that to allow for more frames.)
In all cases, when we import images into VTFEdit, they are re-sampled to align to a resolution that is a power of 2, this is due to the rendering engine and an optimization for faster and easier rendering. Suffice it to say. the engine just needs them that way. VTFEdit gives you a drop-down box to give you further control. It defaults to “Nearest Power of 2” but there are options for “Smallest Power of 2” and “Largest Power of 2”.
During the import, VTFEdit looks at the dimensions of the image, for an example, let’s say our image is 220 x 220. If the image’s dimensions do not align to a power of 2 in both their X and Y dimensions, VTFEdit figures out the next largest and next smallest even power of 2 to align to and re-samples the image to these new dimensions. It uses the value in the drop-down list as a guide-line. In our case the next smallest is: 128 x 128 and the next largest is 256 x 256. If “Nearest Power of 2” is chosen, since 220 is closer to 256 then it is to 128, 256 x 256 is used. If our image size was 130 x 130, the next smallest is: 128 x 128 (again) and the next largest is: 256 x 256 (again), and 128 x 128 would be used. If you select “Next Smallest Power of 2” it will always pick the next smallest value, and likewise, should you choose “Next Largest Power of 2” it will always choose the next largest.
How do I know what the next powers of 2 are? Well I wrote a simple program to dump a bunch out for me and I just compared
Below is a convenient table for your use:
2 to the Power of Dec. Value Bin Value
——————————————————————
2 ^ 0 1 0000000001
2 ^ 1 2 0000000010
2 ^ 2 4 0000000100
2 ^ 3 8 0000001000
2 ^ 4 16 0000010000
2 ^ 5 32 0000100000
2 ^ 6 64 0001000000
2 ^ 7 128 0010000000
2 ^ 8 256 0100000000
2 ^ 9 512 1000000000Using square images (same X and Y dimensions) is easiest. But in the case of a rectangular image, the X and Y and handled separately, so an 65 x 130 image, using “Nearest Power of 2” ends up being 64 x 128, which may or may not stretch / compress your image inappropriately and you’ll want to either force the re-sampling or manually resample it with padding in the image to make the resolutions easier to work with. Square, as I mentioned is the easiest
![]()
Usually, leaving the default of “Nearest Power of 2” is sufficient, but I feel it’s better to resample the image yourself during the image preparation phase of the procedure because it is likely Gimp or Photoshop have a highly superior re-sampler then VTFEdit. I’m not saying it is, I’m just saying it’s likely, especially as the tool hasn’t been updated in 2+ years at this point. Plus it’s nice to know what’s really going on under the hood.
Sprays are stored in 2 places for Team Fortress 2. By default they are:
C:\Program Files\Steam\steamapps\<STEAM_ACCOUNT_NAME>\team fortress 2\tf\materials\VGUI\logos\
C:\Program Files\Steam\steamapps\<STEAM_ACCOUNT_NAME>\team fortress 2\tf\materials\VGUI\logos\UI\
where <STEAM_ACCOUNT_NAME> is the login name associated with your Steam account.
-If the C:\Program Files\Steam\steamapps\<STEAM_ACCOUNT_NAME>\team fortress 2\tf\materials\ directory does not have a sub-directory called “VGUI” create a new folder with that name there.
-If the VGUI folder does not have a logos directory, create a new folder with that name there. Once the .vtf is in here, you can import it from here using the TF2 Options –> Multi-Player, Import Spray option and browse to this directory. The importing process will create a file with the same name as the .vtf file but will have a .vmt extension (not sure what that is though, any thoughts?) This will also copy the .vtf and .vmt to the logos/UI directory.
-If the logos directory does not have a UI directory, create a new folder with that name there. One the .vtf and .vmt files are in this directory, they will appear in the Choose Spray drop-down list for choosing.
For most cases it does not matter what you name the image file that you import into VTFEdit. Whatever the file is named, will be used by VTFEdit as the default .vtf name for saving but you can always type a different name.
For Animated Sprays, it DOES matter however. Animated sprays are created by making a series of images, 1 per frame, and giving them a sequential file name so that VTFEdit recognizes them as multiple frames for the same spray. Basically, they just need to be alphabetized so when VTFEdit sorts the multi-selected images, it sorts the filenames alphabetically and frame 1 goes to the 1st file, frame 2 goes to the second, and so on. For ease of use you could use filenames like: “1-MySprayImage.tga”, “2-MySprayImage.tga”, “3-MySprayImage.tga”, etc.
The process is relatively simple, create or find an image you want to use as a spray. Make sure it is cropped or scaled down to a resolution of (at largest) 256 x 256. Open VTFEdit, on the File Menu, choose the Import item. Browse to the spray image and select it, verify the VTFEdit import options are correct (the tool remembers it’s last settings so typically you’ll only need to set it up the first time you make a spray) and hit OK.
A screenshot of pretty useable settings follows:
Non-Animated Spray:
Animated Spray:
Please note, the only difference in the above two screen-shots is the value of the “Texture Type” drop-down list item. Non-Animated sprays use “Volume Texture”, animated ones use “Animated Textures”. It would be fine to use an Animated Texture with a 1 frame animation, but I have found no information to say use one method or another. I’ve successfully created non-animated sprays with Volume Texture and animated sprays with Animated Texture.
At this point VTFEdit will display to you the imported image and you simply go to the File menu again, choose the "Save As” item, browse to your local logos directory and save the file with whatever name you’d like with a .vtf extension.
You’re ready to use it! Just start Team Fortress 2, go to Options, then the MultiPlayer Options tab, then press the import spray button and browse to your logos directory (as mentioned above) and choose the new spray. Click apply, connect to your favorite server and spray away!
VTFEdit makes the whole process of creating the .vtf file for use by TF2 a very easy process. The hard part is preparing the image before importing it into VTFEdit. Non-Animated, Non-Transparent images are the easiest, they only require the correct 256 x 256 or smaller size constraint. Transparency requires Alpha channels and TGA file format.
Some of the Articles I listed at the beginning have more detail on making transparent images and animation image preparation, I urge you to check them out if you are unsure.
Good luck!
Here is a link to a Quicktime movie of the actual spray in game showing the animation. Not very exciting but enjoy! Click here to view the movie!
Posted in Gaming | Print | 2 Comments »