Writing CFG Mods Tutorial 5 - Advanced vstr

Advanced Vstr


Up to this point in the tutorials, any mods you made probably would have been pretty bland. They would have consisted of single button binds and some dvars. Now that we're talking about vstr, however, we can get into the good stuff, like control sets and using vstr as a toggle.


Before we get started, let me explain one more thing about set. As you know, set will set the value of a dvar. What you don't know (or maybe you do if you aren't completely new to this) is that set can be used to make a NEW dvar. In the previous tutorial I said we could do:


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


This works because vstr motd will execute the text string in motd as a command string. It's as if instead of vstr motd we had put toggle player_sustainammo. Now, we used motd because it can hold text (unlike player_sustainammo or g_speed, which both hold numerical values), but we also could have done:


bind button_rshldr "vstr newdvar"
set newdvar "toggle player_sustainammo"


"Newdvar" could be anything you want it be. You could make it "rb" so that you can remember it better, or you could name it "right_shoulder_bind", or "asdflkasdfasdf", etc. Remember, though, if a dvar already exists with the name, that you won't be making a new dvar, but rather setting an old one. In the following examples, I will set new dvars with names that will tell us what we made them for so that it's easier to understand. When making dvars for SVGs or GPDs you might want to use as few characters in a dvar as possible to save space. When you use set to make a new dvar, its domain will be any text.


That being said, let's go over how to do different control sets. Or, how you would use one button to change what the other buttons do. So first off, let's establish what we want the controls to be. Let's say:

Controls 1:

RB: noclip
LB: godmode
back: toggle controls

Controls 2:

RB: notarget
LB: toggle timescale 1 2 .2
back: toggle controls

Timescale is the scale of time per frame... It just means how fast the game will go. Timscale has a default value of 1. A value of 2 means the game goes twice as fast. A value of .2 means the game goes 0.2 times as fast, or 80% slower. In the first controls, we want the right shoulder to toggle noclip, the left shoulder to toggle godmode, and the back button to switch to controls 2. In controls 2, we want the right shoulder to toggle notarget, the left shoulder to toggle the timescale, and the back button to switch back the controls 1. Let's get started:


bind button_rshldr "vstr rb"
bind button_lshldr "vstr lb"
bind button_back "toggle_controls"


This means that whatever value is in the dvar "rb" will be executed as a command string when we press the right shoulder. Same for the left shoulder and back, with their respective dvars. The problem is that the dvars "rb", "lb", and "back" don't exist yet. When we first start the game, we're going to be on controls 1, so we'll set the controls that way.


bind button_rshldr "vstr rb"
bind button_lshldr "vstr lb"
bind button_back "vstr toggle_controls"
set rb "noclip"
set lb "god"


Now when we press the right shoulder, it will toggle noclip, and the left shoulder will toggle godmode. Now that the right and left shoulder are bound to vstr dvars, we can change what they do by changing the dvars instead of binding them to something else. I'm going to add the toggle_controls dvar and the dvars it needs to work. It might seem a bit confusing, but just try to state it down until you can make sense out of it.


bind button_rshldr "vstr rb"
bind button_lshldr "vstr lb"
bind button_back "vstr toggle_controls"
set rb "noclip"
set lb "god"
set toggle_controls "vstr controls_2"
set controls_2 "set rb notarget;set lb toggle timescale 1 2 .2;set toggle_controls vstr controls_1"
set controls_1 "set rb noclip;set lb god;set toggle_controls vstr controls_2"


Like I said, stare that down until it makes sense. You will learn better that way, than if I just read the explanation. If you can't figure it out, then that's OK too, these tutorials are here for a reason.

Let's trace what happens when we press the back button the first time. It's at the start of the game, so the right shoulder is bound to vstr rb, the left shoulder to vstr lb, and the back button to vstr toggle_controls. Rb is set to noclip and lb to god. When we press rb we will toggle noclip, and when we press lb, we toggle godmode. Let's see what back does though. It's bound to vstr toggle_controls. That means that it's going to execute the value of toggle_controls as a command string. So, let's see what toggle_controls is. Uh oh, this is going to get confusing. Toggle_controls is set to vstr controls_2, which means that it's going to execute the value of controls_2 as a command string. Finally, we've reached the end; controls_2 is set to set rb notarget;set lb toggle timescale 1 2 .2;set toggle_controls vstr controls_1. When we press the back button, it first it rb to notarget, then it sets lb to toggle timescale 1 2 .2, then it sets toggle_controls to vstr controls_1. Now when we press the right shoulder, it's going to toggle notarget. Remember that the right shoulder is bound to vstr rb, and we've just set rb to notarget. The left shoulder will now toggle the timescale. Toggle_controls is now set to vstr controls_2. So the next time we press back, it's going to end up executing vstr controls_1 instead of vstr controls_2. Each time we press back, it will change the controls and change what the back button does the next time.


I'm sure you're sufficiently confused at this point, so you might want to take some time to test this on the PC version if you have it or just try to wrap your mind around it. Next I'm going to talk about another type of toggling effect with vstr.


Let's say you want right on the dpad to give you guns, and then make it so the next time you press it, you get different guns. For example, we want it to give us the thompson and the m1 carbine, and then the second time we press it, it will give us a raygun and a mp40. After that, we get the m1 and thompson again, and so on. Similar to what we did with the back button, we would do:


bind dpad_right "vstr guns"
set guns "vstr guns1"
set guns1 "give zombie_thompson;give zombie_m1carbine;set guns vstr guns2"
set guns2 "give raygun;give zombie_mp40;set guns vstr gun1"


If you understood the toggling control sets, you'll problaby set this. If you didn't understand the control sets, maybe this will help you understand. Remember that executing vstr <dvar> is the same as executing the value of the dvar, so right now vstr guns is the same as vstr guns1. Vstr guns1 is the same as give zombie_thompson;give zombie_m1carbine;set guns vstr guns2, so when we press back it will end up giving us the thompson, the carbine, and setting guns to vstr guns2. If you're still not getting the whole idea of vstr, let me give you a ridiculous example of how we could make the right shoulder toggle noclip:


bind button_rshldr "vstr 1"
set 1 "vstr 2"
set 2 "vstr 3"
set 3 "vstr 4"
set 4 "vstr 5"
set 5 "vstr 6"
set 6 "vstr 7"
set 7 "noclip"


When we press the right shoulder, it's going to go through each of those dvars. First it will execute the value of 1, which will make it execute the value of 2, which will make it execute the value of 3, and so on until it gets to executing the value of 7, which will toggle noclip. Despite how much longer this may seem to us, the computer will execute it as fast as if we had just bound right shoulder to noclip.


In Call of Duty Black Ops, the give all command will only give you a few of the guns, presumably because there is a limit on how many guns you can hold at one time. On World at War, there is no limit, so after executing give all, you will have all the guns and can go through them by pressing "y". Black Ops modding no longer works with the latest title updates, so chances are you're here for WaW modding, which means that you'll have little use for a bind that gives a certain amount of guns at a time instead of all of them. There is, however, a more useful toggle effect of vstr that I used in the mod menu for WaW.


bind dpad_right "vstr sun_color"
set sun_color "setfromdvar r_lighttweaksuncolor colors;vstr change_colors"
set colors "0 0 1 1"
set change_colors "vstr red"
set red "set colors 1 0 0 1;set change_colors vstr green"
set green "set colors 0 1 0 1;set change_colors vstr blue"
set blue "set colors 0 0 1 1;set change_colors vstr red"


Don't flip out if you don't get it at first, just, like with everything else, try to stare it down until you can make sense out of it. I talked about setfromdvar in the tutorial on other commands, so that shouldn't seem too new to you. R_lighttweaksuncolor is pretty self-explanatory; it's the dvar for the color of sunlight with a domain of any color in RGBa percents. Let's try to follow what the game will do when we press right on the dpad. Dpad_right is bound to vstr sun_color, so we're executing the value of sun_color as a command string. Sun_color is
setfromdvar r_lightweaksuncolor colors;vstr change_colors. The first command in that string is setfromdvar r_lighttweaksuncolor colors. That is going to set the value of r_lighttweaksuncolor to the value of the dvar colors. Just below it, you can see that we set colors to 0 0 1 1. Remember it's in RGBa percents, so 0% red, 0% green, 100% blue, and 100% visibility. The color of the sunlight would become blue and then the game would move on to the second part of the sun_color command string, which is vstr change_colors. Change_colors is set to vstr red, so now we're executing the command string in red, which is set colors 1 0 0 1;set change_colors vstr green. That's the end of what happens the first time we press right. Now when we press right, the color of sunlight will change to red, and the next time we press right, it will change the color to green, and so on. There is a more efficient way of donig this, which will be discussed in another tutorial.



Congratulations again!! Yet another tutorial completed!


Click here to move onto the next tutorial, Escaping With the Backslash.


You do however have the ability to make a kick-ass SVG or GPD at this point so you can also head back to the tutorials page if you want.