Writing CFG Mods Tutorial 4 - Introduction to vstr

Using vstr


Vstr is an extremely important command and it will greatly benefit you and your mods to learn how to use it properly. You should check out the tutorials preceeding this one if you haven't already.


Despite it's countless uses and applications, the function of vstr is actually incredibally simple. Lets look at some simple code:

bind button_rshldr "toggle player_sustainammo"


Remember that with certain dvars and booleans, you don't need to specify the values with toggle. That bind will make RB toggle player_sustainammo. What if we want to change what RB does though? What if we want it to instead toggle g_speed between a few values? Well, we would have to do:


bind button_rshldr "toggle g_speed 300 400 700"


Luckily, there's an easier way; with vstr. Before I explain it, look at the following code and see if you can figure it out on your own:


bind button_rshldr "vstr motd"
set motd "toggle player_sustainammo"


Remember that motd is a dvar that can hold any text. Under normal circumstances - without mods - motd, or message of the day, would be something like "Visit Callofduty.com for information on upcoming releases...". Remember when I talked about multiple commands separated by semicolons, I called them command strings. String, in this vernacular, means, according to the online dictionary, " a group of characters that can be treated as a unit by a computer program ". We call the value of a dvar like motd a text string. Vstr stands for variable string. The command vstr will execute the value of a dvar as a command string. If you tried

vstr motd


...when it has one of the game's values, "Visit Callofduty.com...", the game will try to execute "Visit Callofduty.com....". "visit" isn't a command recognized by the game, so it will say "unknown command visit". If, however, we change the value of motd to something we want, like "toggle player_sustainammo", then when we do vstr motd, it will execute the value as a command string and will toggle player_sustainammo.


Maybe you're a bit confused right now. That's OK. Look at the following two codes:


bind button_rshldr "toggle player_sustainammo"


bind button_rshldr "vstr motd"
set motd "toggle player_sustainammo"


They will both have the same result. Using vstr <dvar> will have the same effect as just putting the value of that dvar. You might wonder what the point is if all we want RB to do is toggle player_sustainammo, but vstr is needed for other things.


Click here to move to on to the next tutorial, More Advanced Uses of Vstr.


You now have the necessary knowledge to start modding and you can head back here to start learning how to use what you've learned for different types of mods.