Mintman's Scripting Tutorial

MintmanMintman Join Date: 2003-05-30 Member: 16866Members
edited January 2005 in Scripting Discussion
<b>Mintman?s guide to scripting</b>

<span style='color:red'>First of all I would like to point out that this is not a discussion on whether scripts are good or bad so I do not want opinions from either side within this thread.</span>

This is here to hopefully help educate people as to how to create scripts for Natural Selection. The techniques used here can be used for all Half-Life mods.

First of all, within script there are two main commands you need to understand: the <b>bind</b> command and the <b>alias</b> command. Binds are used to tie commands to keys and aliases are used to give one or more serial commands a different command name.

<b>The bind command</b>
The bind command is used to assign the execution of a command or commands to the pressing of a key or mouse button.

The syntax (the pattern to use to create a correct bind) for a bind is:<!--c1--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>CODE</b> </td></tr><tr><td id='CODE'><!--ec1-->bind key "command"<!--c2--></td></tr></table><div class='postcolor'><!--ec2-->
An example of a correct bind commands is:<!--c1--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>CODE</b> </td></tr><tr><td id='CODE'><!--ec1-->bind mouse2 "+jump"<!--c2--></td></tr></table><div class='postcolor'><!--ec2-->
A list of all the keys it is possible to bind to can be found here: <a href='http://www.csnation.net/view.php/csinfo/scripting/basic-bindlisting.csn' target='_blank'>http://www.csnation.net/view.php/csinfo/sc...bindlisting.csn</a>
A picture of which key names bind to which key (useful for people with non-US/English keyboards), thanks Zaggy: <a href='http://home.no.net/slix/bilder/CS/tutorials/buyscript/cskeynames.JPG' target='_blank'>http://home.no.net/slix/bilder/CS/tutorial.../cskeynames.JPG</a>

<b>The alias command</b>
The basic use for an alias command is to give a command or commands a different name.

The syntax for an alias is:<!--c1--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>CODE</b> </td></tr><tr><td id='CODE'><!--ec1-->alias name "command"<!--c2--></td></tr></table><div class='postcolor'><!--ec2-->

For example, a common alias in scripting for doing something dependant on time is:<!--c1--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>CODE</b> </td></tr><tr><td id='CODE'><!--ec1-->alias w "wait;wait;wait;wait;wait"<!--c2--></td></tr></table><div class='postcolor'><!--ec2-->This code enables you to put 5 waits within a script where you put a single <i>w</i> command.

There are advanced versions of aliases which use two sections to execute a command or commands when you press the assigned key and to assign another command or some other commands when you release the assigned key.

Example code:<!--c1--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>CODE</b> </td></tr><tr><td id='CODE'><!--ec1-->alias +example "say Pressed"
alias -example "say Released"

bind x "+example"<!--c2--></td></tr></table><div class='postcolor'><!--ec2-->This code would mean that when you pressed the key <i>x</i> you would say "Pressed" in chat and when you released it you would say "Released" in chat. Notice that the key is bound to the <i>+</i> section of the alias rather than the <i>-</i> section.

A command within a bind or an alias can consist of several commands as we saw within the <i>alias w</i> script. These multiple commands must be separated within the alias or bind by a semi-colon: <b>;</b>

<b>Creating a toggle script</b>
One of the more advanced scripts you can create is a toggling script. An example of this is a script that toggles walking (can be useful when cloaking). They generally work by combining two aliases that bind a key to each other. Sounds complicated? Here's an example of a walk toggling script:<!--c1--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>CODE</b> </td></tr><tr><td id='CODE'><!--ec1-->alias walkon "+walk;bind X walkoff"
alias walkoff "-walk;bind X walkon"

bind X "walkon"<!--c2--></td></tr></table><div class='postcolor'><!--ec2-->
This code allows you to press the key X which will start you walking, pressing it again will stop you walking and so on. Be sure that <i>X</i> is the same in all three sections of the script.

A list of the default Half-Life commands with their description can be found here: <a href='http://planethalflife.com/commands/commands/index.shtml' target='_blank'>http://planethalflife.com/commands/commands/index.shtml</a>
<i>Note: not all of these will work in NS</i>

A list of the impulse commands that can be used in NS can be found here: <a href='http://www.natural-selection.org/forums/index.php?showtopic=27019' target='_blank'>http://www.natural-selection.org/forums/in...showtopic=27019</a>

That basically covers all you need to know about how to creating scripts. I will update this soon to contain information about all the commands you can use.

Comments

  • chaochao Join Date: 2004-01-30 Member: 25739Members, Constellation
    Looking forward to some advanced scripting explanation.
  • UrdUrd Join Date: 2003-05-25 Member: 16696Members, Constellation
    edited June 2004
    Here are some toggle aliases that are very usefull.

    This is a cycler alias, used to do a bunch of things on one key in order.
    <!--c1--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>CODE</b> </td></tr><tr><td id='CODE'><!--ec1-->
    alias ss s1
    alias s1 "say Quote #1; alias ss s2"
    alias s2 "say Quote #2; alias ss s3"
    alias s3 "say Quote #3; alias ss s4"
    alias s4 "say Quote #4; alias ss s1"
    bind x ss
    <!--c2--></td></tr></table><div class='postcolor'><!--ec2-->

    This is a combo alias, used to double bind keys to save keyboard space, or make important scripts require 2 keys to execute, so you don't quit in the middle of a game or something by hitting your quit button.
    <!--c1--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>CODE</b> </td></tr><tr><td id='CODE'><!--ec1-->
    alias sss! "say This is slot 1!"
    alias +tog "bind 1 sss!"
    alias -tog "bind 1 slot1"
    bind c +tog
    <!--c2--></td></tr></table><div class='postcolor'><!--ec2-->
  • MintmanMintman Join Date: 2003-05-30 Member: 16866Members
    Ta Urd, I was thinking of expanding the tutorial to cover tricks such as that.
  • ZaggyZaggy NullPointerException The Netherlands Join Date: 2003-12-10 Member: 24214Forum Moderators, NS2 Playtester, Reinforced - Onos, Subnautica Playtester
    <a href='http://home.no.net/slix/bilder/CS/tutorials/buyscript/cskeynames.JPG' target='_blank'>This</a> is a nice binding pic too.

    Nice tutorial Mitman <!--emo&:)--><img src='http://www.unknownworlds.com/forums/html//emoticons/smile.gif' border='0' style='vertical-align:middle' alt='smile.gif' /><!--endemo-->
  • MintmanMintman Join Date: 2003-05-30 Member: 16866Members
    Cheers Zaggy, that makes the keys you can use even clearer!
Sign In or Register to comment.