Basic tutorial 10
Key pressed down scripts (+vstr).
For scripts that require an action when a key is kept pressed down we use the +vstr command. Let me first show you how to use this command properly. Binding a key to a +vstr command should look like this:
bind key "+vstr var1 var2"
As you can see you need 2 variables, one for each situation: when the key is pressed down and when the key is not pressed down. Var1 should state what should happen when the key is pressed down and var2 should state what should happen when the key is not pressed down. So you will also have to state the actions set to these 2 variables, as talked about in the seventh tutorial. In total it should look like this:
bind key "+vstr var1 var2"
set var1 "command1, command2, ..."
set var2 "command1, command2, ..."
Let's clarify this with an example. One of the most requested scripts is the sprint while shooting script. This script automatically makes you sprint while you are shooting. A perfect example of a key pressed down script, cause you are firing your gun as long as you keep your mouse1 (left mouse button) pressed down.
You need to use 2 cvars to make this script work. The first is +attack and the second is +sprint. Of course these are the commands to enable firing your gun and sprinting. These again have 2 cvars to disable these actions: -attack and -sprint. When you keep mouse1 pressed down, you want to enable sprinting and firing your gun and of course when you let go of mouse1, you want to disable firing your gun and sprinting. This would result in the following script:
bind mouse1 "+vstr shootOn shootOff"
set shootOn "+attack; +sprint"
set shootOff "-attack; -sprint"
In theory this script should work, but in practice you will find out that it sometimes does not. It could keep on firing when you let go of mouse1. That's why you should always use the disable commands twice, like this:
bind mouse1 "+vstr shootOn shootOff"
set shootOn "+attack; +sprint"
set shootOff "-attack; -attack; -sprint; -sprint"
This way you make sure the disable commands always work.
Note: Again it does not matter what names you choose for the 2 variables. Just use specific names that make sense to you.
|