|
![MeanGoof wrote this scripting tutorial to help the MiGHTY [TiC]Clan and others.](http://www.ticclan.com/tutorials/meangoofs-script-lessons/images/meangoof.gif)
MeanGoof's Scripting Tutorials:
(17 July, 2002)
(By: "Meangoof")
(Former [TiC]Clan Guest)
Lesson #3:
Toggle scripts:
What are Toggle Scripts?:
What is a toggle script you might ask? Did you ever wish
that you had a way to make your move keys toggle between
running and walking, without always having to hold down the
shift key when you want to walk? Did you ever wish you had a
particular key that could turn the radar on when you hit it,
and turn it off when you hit it again? Toggle scripts allow
you to do exactly this sort of thing.
This class will include the following:
1) A review of last week's lesson.
2) A detailed explanation of a simple toggle script.
3) A session on the clan server to try out your new toggle
script (and to debug it if it does not work).
Back to the top of page
A review of previous script classes:
a) CS has over 250 commands that can be invoked through the
console, directly from a script, or from a bind to one of
your keys.
b) You can create your own commands by using aliases. You
build aliases as a sequence of valid CS commands, each
separated by a semi column and enclosed in double quotes.
Example: alias crouchjump "+duck;wait;wait;+jump;wait;wait;-duck;wait;wait;-jump"
c) Just like the normal commands, the commands you create
can be used from the console, in a script, as part of new
commands etc etc.
Example:
Create a command
alias wait4 "wait;wait;wait;wait"
Now create another command based on the previous one
alias wait8 "wait4;wait4"
Now whenever you use wait4 or wait8 they behave like normal
commands
for example:
alias +selectHE "weapon_hegrenade;wait8"
alias -selectHE "lastinv;wait4"
In this last example, whenever you press a key bound to the
+selectHE alias, the HE grenade is selected.
When you let go of that key, your last selected weapon comes
back automatically.
d) +/- commands are special types of commands that are
normally bound to keys. The plus version is bound to a key.
When the key is pressed, the command is executed, and when
the key is let go, the minus command is executed. You can
use +/- commands in scripts or other aliases, but make sure
that you don't break the semantic of the command by
forgetting to call up the minus command. Forgetting this
could put your game in a state that has you locked up doing
something. For example, is you issue the +forward command
and forget to execute the -forward command, you will forever
being moving forward.
Back to the top of page
A detailed description of a toggle script:
What follows is a toggle script that allows you to toggle
between running and walking
alias walkToggle "walk_on"
alias walk_on "+speed;developer 1;echo walking is
on;developer 0;alias walkToggle walk_off"
alias walk_off "-speed;developer 1;echo walking is
off;developer 0;alias walkToggle walk_on"
bind "1" "walkToggle"
Let's look at this script one line at a time.
1.) alias walkToggle "walk_on" :
In this line I create a new command called walkToggle. This
command, when first executed, will execute the walk_on
command (which is defined on the next line). This command
will change itself to execute something else each time it is
executed. By that I mean that the first time it is executed,
it will execute the walk_on command, the second time it is
executed it will execute the walk_off command, the third
time it is executed it will be back to executing the walk_on
command and so on.
2.) alias walk_on "+speed;developer 1;echo walking is
on;developer 0;alias walkToggle walk_off" :
In this 2nd line, I define the walk_on command. Remember
from the previous line, this is actually what gets executed
the first time the walkToggle command is executed because
the walkToggle command is first aliased to this particular
command. The first thing that this command does is to
execute the +speed command. This has the same effect as if
you pressed and held down the shift key, thus making your
player walk instead of running. The second thing this
command does is to execute the developer 0/echo/developer 1
sequence which puts the walking is on message on the top
left hand corner of your hud (see the description of the
developer/echo command combination I provided in the first
class on scripting). The last thing the walk_on command does
is where the magic lies in toggle script. It executes the
alias command on the walkToggle command, to re-alias the
walkToggle command to its new meaning, namely walk_off. This
means that after executing the walk_on command, the
walkToggle command, when executed again, will execute the
walk_off command. Very cool euh?
3.) alias walk_off "-speed;developer 1;echo walking is
off;developer 0;alias walkToggle walk_on" :
In this third line I define the behaviour of the walk_off
command. After executing the walk_on command, this is the
command that the walkToggle command is aliased to. The first
thing this command does is to execute the -speed command.
This is the same thing as if you released the shit key on
your keyboard, putting your player back into the running
mode. The line then displays the walking is off message on
the top left hand corner of your hud. The last thing this
line does is to re-alias the walkToggle command back to its
original meaning (walk_on) so that when the walkToggle
command is executed again, it will cycle back to its
original meaning which was to make you walk.
4.) bind "1" "walkToggle" :
Aliases by themselves serve very little purpose. You have to
have a way to execute them. This last line binds the 1 key
on your keyboard to the walkToggle command. After executing
this line, every time you hit the 1 key on your keyboard, it
will execute the walkToggle command for you, which will
toggle you back and forth between the walk and run mode.
Personally, I would not put this particular line in my
private script. I would either drop my console and issue
this command from the console (which will automatically
update my config.cfg file) or I would put an entry line
inside my kb_act.lst file and make my bind from the games
controls menu.
That's all there is to toggle scripts. Write this one down
in your autoexec.cfg or private script file and lets go on
the server to try it out.
Back to the top of page
This page was originally created by [TiC]EVIL
28Aug01. Last updated 02/06/03.
|