logo Scripting for Enemy Territory

Menu


Home
Tutorials
Downloads
Forum
Contact

Friends





Advanced tutorial 3

Creating a proper name selector.

In our basic tutorials we talked about creating a toggle. This is what most people use when creating a name toggle too. This is not recommended though. You might have a toggle of 7 names. Now you want to choose the seventh name, so you start pressing your binded key to set the right name. When doing this you are changing your names 6 times, cause you want to go from name 1 to name 7. Some servers have a security setting preventing you from too many name changes in a certain amount of time(, to prevent you from lagging the server). So a script like this could get you kicked.

So in short a simple script like this will work, but is not smart:
bind x "vstr changeName"
set name1 "name Name_nr_1; set changeName vstr name2"
set name2 "name Name_nr_2; set changeName vstr name3"
set name3 "name Name_nr_3; set changeName vstr name4"
set name4 "name Name_nr_4; set changeName vstr name5"
set name5 "name Name_nr_5; set changeName vstr name1"
set changeName "vstr name1"

It would be better if you could scroll through your names until you found the one you want and then change you current name to the prefered name. So you would need 1 key to scroll through your names. Of course seeing the names in the echo section, so you know which name you have selected. And another key to actually set your new name.



Ok let's go through this step by step. First we start of by storing all the names in variables:
set N1 "name Name_nr_1"
set N2 "name Name_nr_2"
set N3 "name Name_nr_3"
set N4 "name Name_nr_4"
set N5 "name Name_nr_5"

When we execute one of these variables (i.e. vstr N1) you name will be changed to the name stored in that variable. Now we need to create a toggle to scroll through the names:
bind x "vstr changeName"
set name1 "echo Nick: Name_nr_1; set changeName vstr name2"
set name2 "echo Nick: Name_nr_2; set changeName vstr name3"
set name3 "echo Nick: Name_nr_3; set changeName vstr name4"
set name4 "echo Nick: Name_nr_4; set changeName vstr name5"
set name5 "echo Nick: Name_nr_5; set changeName vstr name1"
set changeName "vstr name1"

As you can see the only thing this toggle does at this moment is echo the names you scroll through while pressing x, nothing more! Now I want to add another key y, to actually set the name. So if I scroll through my names with x to for instance name 4 and I would press y, I want my script to set my name to Name_nr_4. In other words I want it to execute N4 when I press y. For this we need an extra variable, let's call it setName. This is the variable that will be binded to y:
bind y "vstr setName"



Now the question is how do we actually connect N1-N5 to setName. Well by adjusting the variables name1 to name5 like this:
set name1 "echo Nick: Name_nr_1; set changeName vstr name2; set setName vstr N1"
set name2 "echo Nick: Name_nr_2; set changeName vstr name3; set setName vstr N2"
set name3 "echo Nick: Name_nr_3; set changeName vstr name4; set setName vstr N3"
set name4 "echo Nick: Name_nr_4; set changeName vstr name5; set setName vstr N4"
set name5 "echo Nick: Name_nr_5; set changeName vstr name1; set setName vstr N5"

As you can see when x is pressed and name 1 is echoed, then the variable setName is connected to N1. So now when I press y (which connected to variable setName) N1 is executed. When I press x again, the second name is echoed. Now setName is connected to N2. So when I press y, N2 is executed. And so on...
So our script in total up till now is as followed:
bind x "vstr changeName"
bind y "vstr setName"

set N1 "name Name_nr_1"
set N2 "name Name_nr_2"
set N3 "name Name_nr_3"
set N4 "name Name_nr_4"
set N5 "name Name_nr_5"

set name1 "echo Nick: Name_nr_1; set changeName vstr name2; set setName vstr N1"
set name2 "echo Nick: Name_nr_2; set changeName vstr name3; set setName vstr N2"
set name3 "echo Nick: Name_nr_3; set changeName vstr name4; set setName vstr N3"
set name4 "echo Nick: Name_nr_4; set changeName vstr name5; set setName vstr N4"
set name5 "echo Nick: Name_nr_5; set changeName vstr name1; set setName vstr N5"

set changeName "vstr name1"

Now it's almost completed. It just needs one more thing. The last line of the script above is the initial value for variable changeName. As we have discussed in the toggle tutorial in our basic tutorial section, our script needs to know where to start the first time we press x. That's what this initial value is for.
If x is not pressed at least once, then the variable setName is not connected to any of the variables N1 to N5 yet. Pretty logical, cause you cannot actually set the name with y if you haven't chosen one yet with x. So we need to set the variable setName to an echo message stating, you have to choose a name first. So the initial value for setName will be:
set setName "echo Choose a name first using x!"



Now we have our total script. I also added some comment lines to make it clear which part does what. Here it is:
//Binded keys
bind x "vstr changeName"
bind y "vstr setName"


//Your names
set N1 "name Name_nr_1"
set N2 "name Name_nr_2"
set N3 "name Name_nr_3"
set N4 "name Name_nr_4"
set N5 "name Name_nr_5"


//Toggle
set name1 "echo Nick: Name_nr_1; set changeName vstr name2; set setName vstr N1"
set name2 "echo Nick: Name_nr_2; set changeName vstr name3; set setName vstr N2"
set name3 "echo Nick: Name_nr_3; set changeName vstr name4; set setName vstr N3"
set name4 "echo Nick: Name_nr_4; set changeName vstr name5; set setName vstr N4"
set name5 "echo Nick: Name_nr_5; set changeName vstr name1; set setName vstr N5"


//Initial values
set changeName "vstr name1"
set setName "echo Choose a name first using x!"

Back to the tutorial list