What Is A Script

First off, I've had this on my desktop for QUITE some time, and I've been eagerly awaiting the scripting forum as much as lot of people have, and I'm sure this will be phased there if/when it goes up. I had rules written out as well as my moderater status offered, all were declined and now we just have to wait for it to go up... We know how NS devs are........ ANYWAY here. I'll be damned if this doesn't cover everything related to the basics of scripting.

This article is also posted on NSLearn.org and any discussion about it, as well as questions about scripting, can be asked there

What is a script? Basically a script is a series, or string, of commands executed by the hitting of one key.

A very basic script would be:Bind "z" "say_team I need a medpack!; impulse 10"

All it's doing, is binding to your 'z' key, 2 commands, a basic 'say' to your teamates, and the impulse necessary to call for medpacks. Scripting has been around since the beginning of Half-Life games and official mods, and is used in MANY different ways.

The SemicolonBetween all commands in a script, there MUST be a semicolon ( ; ) used, as noted by every script in this post.

Binds:The simplest form of console commands. Basically by typing "bind <a key> <a command>" in console (without the <>) you have executed a bind to a key. Any key on your keyboard can have any command in the game bound to it. Right now, if you've never changed your movement keys, and you type "bind w" in console, it will display something like this: "w" = "+forward" It is letting you know that, bound to your 'w' key, is +forward, the basic forward movement key. Any command in the game can be rebound to any key on your keyboard, allowing more comfort. I have been using a setup like this for quite some time now.

The aliasAliases are used for multiple reasons. One of the most common, is the changing and manipulating of console commands, to be easy to remember. This may be hard to comprehend, so here is a small example:

alias wa "stopsound"bind "w" "wa"

This is the same as binding 'w' to 'stopsound', like mentioned before. So basically, in this example, alias just changes the name of a single command, but more advanced aliasing involves multiple commands aliased into one name... like this:

alias "med" "say_team I need a medpack!; impulse 10"Bind "z" "med"

This is the exact same script from above, just formed into a simple alias that is easy to bind and unbind for whatever reason you would see fit.

Plus and minus (+, -)In reality, for every action, there is a reaction, for every up, there is a down, and in Half-Life, for every +, there is a -. To make this as simple as possible, +attack right now is bound to your mouse1 key (the left mouse button) unless of course you've changed it. When you shoot your LMG, you hold down the key you have +attack bound to. +attack is then executed until you release, which triggers a -attack, which in turn, stops your firing. When you click your pistol, it is programmed to not fire repeatedly by you just holding down the key, so automatically after pressing +attack with your pistol, it stops firing. Now, mind you, -attack is not executed until you release the key, so +attack cannot again be executed until you release mouse1.

Scripting comes into play mostly with + and - commands, and it is the mostly what people tend to complain about. But what they always fail to realize, is that no script right now, allows you to do anything the wouldn't be possible by binding multiple keys to a command, or using just one key, it just makes it easier. When you learn scripting in every aspect, you will see what I mean.

First, before going any further, you must learn the 'wait' command. Wait is what allows you to execute one command and then another command shortly after. No two + or - commands can be executed without a wait, and this is what balances scripting, and keeps it in fine tune with what is possible by your normal hand. The wait command is basically a small halt, that prevents running one command, and running another DIRECTLY, literally DIRECTLY after the first command has been executed.For example:

Bind "space" "+jump; wait; -jump"

This is what jump does with your space key, it executes +jump, then, due to restrictions of not allowing you to hold down space to repeatedly jump, a -jump.

**- commands completely destroy commands, and must be done for another + command to be executed.

Aliasing + and - commandsThis is where scripting gets to be fun :-D. When you make an alias, you can ALSO make it to where it acts as a + and - command, which allows even MORE flexibility. Let's bring down the health call script, and turn it into a +, - alias.

Bind "z" "say_team I need a medpack!; impulse 10"This is what we had to start with, now lets turn it into a +, - command.

This means, that when you bind a key to +med, you press the key down (executing +), as soon as you release, a med call is sent to the commander. Understand now?

+commands are executed by pushing the button down, - commands are executed by lifting the button up. Makes sense, right?

Advanced aliasing for + and - commands.This is the part of scripting most commonly used. Remember the wait command? This is used alot here too. Without needing to explain, because all of that was down in the previous section, I'll get straight to the point. Your basic pistol script:

Basically, you should already know what it does. I press mouse1, +pscript is executed (one bullet is fired, because +attack is all +pscript is), I release mouse1, -pscript is executed automatically (due to the Half-Life engine automatically executing + after -) shooting another bullet. (Recognized by the second "+attack; wait; -attack"). This script lets you shoot your pistol, two shots for every mouse click, but seeing as the pistol is capped at a certain rate of fire, you really cannot shoot as quickly as you would think you can, and it DEFINATELY isn't 2 times faster than normal shooting, because that is impossible without a speedhack. It just allows less clicking for the same, already achievable, speed.

This script should easily be recognized as to what it does. First, I alias a command called "jump" which executes "+jump; wait; -jump" (I did this so I don't have to type '+jump; wait; -jump' three times, I only have to type 'jump')I alias then, +ejump, which executes 3 +jump commands, and -ejump, which remember, is executed automatically after I release the key, kills all of the jump commands with -jump. I then bound it to spacebar.

Now, this script merely executes three jumps with every press of the space bar. No you WILL NOT jump three times. This seems to be everyone's expectations of the script, but that isn't what it does. Half-Life console commands are executed VERYquickly (depending on your FPS), and all this script does is help with timing ONE jump perfectly. A bunnyhop cannot be executed without perfect jump timing, this script just makes that timing easier.

Using the scriptI know this whole time you've been wondering what to do with this commands, so I'm going to give you the most basic way to use a script.

Right click on your desktop, go to new, then text document. Open this document, and paste this script inside:

Go to File, Save As, and where it says "Save as type" change it to say "All files". Name it "pistol.cfg" (without quotes) and save.Move pistol.cfg to your NS directory.

Now executing the cfg can be done 2 ways. Every time you start NS, you can type into the console "exec pistol.cfg" which will run all of the said commands in that configuration file, OR you can do this.

Create another config file, the same way you created this one, and name it autoexec.cfg

Inside autoexec.cfg put "exec pscript.cfg" and everytime you start NS, "exec pscript.cfg" will be ran. This is built into the Half-Life engine to automatically run autoexec.cfg upon game startup.

Attached to this post are both the autoexec.cfg and pscript.cfg, but I greatly suggest trying this no your own, and asking questions if it does not work.

Basically that's it. There is not much more involved in basic Half-Life scripting, so have a blast, and manipulate your game to your heart's desire, because it is allowed, accepted, and used by alot of NS's veterens, and pubbers alike.

This took quite some time for me to write, and I certainly wont appreciate any flames or horrid posts to that extent. People are reading this to gain knowledge as to what a script is, and how to use it, and if I had the power to lock this now, I probably would. When the new forum goes up, this can be phased there, and you can ask questions then, but please hold them for now.

[Edit] Attached as promised, the pistol script, and autoexec. Open with notepad after extracting to view.

Comments

Until such time as this becomes a locked sticky in the Scripting Forum-To-Be, at which point this post would most likely be deleted, I'd like to commend you for writing such a clear, concise, but helpful guide. Someone who is new to scripting would definitely benefit from it, and would have difficulty developing the common misconceptions when so clearly presented with their counters. Hopefully this article will bring understanding to the masses, and greatly complement our cause. Well done.

Useful commands: impulse*Here are the commands they bind keys to in order to be able to chuckle/let people know you're attacking/need medpack/ammo, etc. In order to use them you need to bring down your console window and type the command. You can also bind these commands to certain keys or use them in mini-scripts.

That doesn't work. Impulse isn't a cvar, and there is only one impulse command. You can't see what it does depending on the value it receives.

Psalm 1211I will lift up mine eyes unto the hills, from whence cometh my help. 2My help cometh from the LORD, which made heaven and earth.Psalm 145 18The LORD is nigh unto all them that call upon him, to all that call upon him in truth. 19He will fulfil the desire of them that fear him: he also will hear their cry, and will save them.

Yeah, the majority of any cvars you'll ever need are already bound.. You just mix and match whatever you want.. there aren't too many useful scripts that haven't already been done... Hell, there aren't even too many usefull scripts at all.

This article was also post on NSLearn.org (#nslear irc.gamesurge.net). Check out the tons of other articles, written by some of Natural-Selection's finest players, inculding Mustang, Annihilator, myself, TheAdj, deadcell, and more.

Until such time as this becomes a locked sticky in the Scripting Forum-To-Be, at which point this post would most likely be deleted, I'd like to commend you for writing such a clear, concise, but helpful guide. Someone who is new to scripting would definitely benefit from it, and would have difficulty developing the common misconceptions when so clearly presented with their counters. Hopefully this article will bring understanding to the masses, and greatly complement our cause. Well done.

^^

and now that we have a scripting forum I will wait for nem0 to phase...

how do I know nem0 will phase this? cause he completed his college stuff and regained use of his left hand and is going to spend the rest of the relaxing day forumiting / doing super s3kret stuff