What Is A Script
the_hole
Join Date: 2004-01-03 Member: 25019Members, Constellation
<div class="IPBDescription">An introduction to the basics</div> 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.
<b>This article is also posted on NSLearn.org and any discussion about it, as well as questions about scripting, can be asked there
<a href='http://nslearn.org/EEpVApVkZZTFjWVVbv.shtml' target='_blank'>http://nslearn.org/EEpVApVkZZTFjWVVbv.shtml</a></b>
-----------------------------------
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 Semicolon
Between 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.
"s" = "+back" Move backward
"d" = "+moveleft" Strafe left
"f" = "+moveright" Strafe right
"g" = "+forward" Move forward
Uncommon, I know, but comfortable for me.
The alias
Aliases 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 - commands
This 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.
alias +med "say_team I need a medpack!"
alias -med "impulse 10"
bind "z" "+med"
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:
alias +pscript "+attack"
alias -pscript "-attack; wait; +attack; wait; -attack"
bind "mouse1" "+pscript"
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.
Let's do another, your basic 3jump script:
alias jump "+jump;wait;-jump"
alias +ejump "jump;wait;jump;wait;+jump"
alias -ejump "-jump"
bind space "+ejump"
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 VERY
quickly (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 script
I 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:
alias +pscript "+attack"
alias -pscript "-attack; wait; +attack; wait; -attack"
bind "mouse1" "+pscript"
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.
[Edit2]
Links:
<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>
This is a list of all keys bindable by the console, their ingame, and out of game names. (Thanks to mint's thread)
<a href='http://www.planethalflife.com/commands/commands/index.shtml' target='_blank'>http://www.planethalflife.com/commands/commands/index.shtml</a>
This is a link to the names of all Half-Life console commands. Remember some do not work in NS. (Thanks again to mint's thread)
<b>This article is also posted on NSLearn.org and any discussion about it, as well as questions about scripting, can be asked there
<a href='http://nslearn.org/EEpVApVkZZTFjWVVbv.shtml' target='_blank'>http://nslearn.org/EEpVApVkZZTFjWVVbv.shtml</a></b>
-----------------------------------
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 Semicolon
Between 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.
"s" = "+back" Move backward
"d" = "+moveleft" Strafe left
"f" = "+moveright" Strafe right
"g" = "+forward" Move forward
Uncommon, I know, but comfortable for me.
The alias
Aliases 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 - commands
This 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.
alias +med "say_team I need a medpack!"
alias -med "impulse 10"
bind "z" "+med"
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:
alias +pscript "+attack"
alias -pscript "-attack; wait; +attack; wait; -attack"
bind "mouse1" "+pscript"
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.
Let's do another, your basic 3jump script:
alias jump "+jump;wait;-jump"
alias +ejump "jump;wait;jump;wait;+jump"
alias -ejump "-jump"
bind space "+ejump"
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 VERY
quickly (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 script
I 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:
alias +pscript "+attack"
alias -pscript "-attack; wait; +attack; wait; -attack"
bind "mouse1" "+pscript"
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.
[Edit2]
Links:
<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>
This is a list of all keys bindable by the console, their ingame, and out of game names. (Thanks to mint's thread)
<a href='http://www.planethalflife.com/commands/commands/index.shtml' target='_blank'>http://www.planethalflife.com/commands/commands/index.shtml</a>
This is a link to the names of all Half-Life console commands. Remember some do not work in NS. (Thanks again to mint's thread)
This discussion has been closed.
Comments
nice little write up though, read the first 2 paragraphs and decided it was written well.
alias walk "+forward"
bind "w" "walk"
Would mean once you pressed it you'd be walking forward permenantly whether you let go or not. This is because releasing w won't trigger the -forward command.
Edit:
Also HL uses userconfig.cfg instead of autoexec.cfg since the switch to steam.
I also made a scripting tutorial ages ago which covers how to make a toggle script: <a href='http://www.unknownworlds.com/forums/index.php?showtopic=74222' target='_blank'>http://www.unknownworlds.com/forums/index....showtopic=74222</a>
Great job, but I dont think that this will convert any scripting fundemantalists :/
Also HL uses userconfig.cfg instead of autoexec.cfg since the switch to steam.
<!--QuoteEnd--> </td></tr></table><div class='postcolor'> <!--QuoteEEnd-->
HL uses whatever .cfg you tell it to.
I'm interested in the communications aspects.
"cvarlist cl_" in console...have fun
The majority of what yous see for clients DO work, take into consideration that you can use common sense to pitch out the ones that don't. I.E. buy menu obvioulsy wouldn't fit in NS. Etc.
"cvarlist cl_" in console...have fun<!--QuoteEnd--></td></tr></table><div class='postcolor'><!--QuoteEEnd-->
That doesn't show impulse commands. After a bit of googling, I was able to find a great guide at <a href='http://www.ausns.com/content/tutorials_guides/impulse_commands.html' target='_blank'>http://www.ausns.com/content/tutorials_gui...e_commands.html</a>
Those Aussies know their stuff!
<b>X---snip---X</b>
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.
Marines
Classic
impulse 1 - Switches to next weapon (same as "invnext")
impulse 2 - Reloads gun (same as "+reload; wait; -reload")
impulse 3 - Drops gun (same as "drop")
impulse 6 - Casts vote to eject commander
impulse 80 - Requests orders from commander
impulse 81 - Acknowledge
Combat
impulse 20 - Armor 1
impulse 21 - Armor 2
impulse 22 - Armor 3
impulse 23 - Weapons 1
impulse 24 - Weapons 2
impulse 25 - Weapons 3
impulse 62 - Welder
impulse 64 - Shotgun
impulse 65 - HMG
impulse 66 - Grenade Launcher
impulse 37 - Hand Grenades
impulse 61 - Mines
impulse 38 - Heavy Armor
impulse 39 - Jetpack
impulse 27 - Catalyst
impulse 31 - Resupply
impulse 53 - Scanner Sweep
impulse 33 - Motion Tracking
Communications
impulse 7 - Follow Me
impulse 8 - Covering
impulse 9 - Taunt
impulse 10 - Need Health
impulse 11 - Need Ammo
impulse 12 - In Position
impulse 13 - Enemy Spotted
impulse 14 - Move Out
impulse 15 - All Clear
Aliens
Classic
impulse 91 - Build Offense Chamber
impulse 92 - Build Defense Chamber
impulse 94 - Build Movement Chamber
impulse 93 - Build Sensory Chamber
impulse 90 - Build Resource Tower
impulse 95 - Build Hive
impulse 113 - Skulk
Combat
impulse 118 - Unlock second hive ability
impulse 126 - Unlock third hive ability
Both
impulse 7 - Chuckle
impulse 8 - "Need Healing" saying
impulse 114 - Gorge
impulse 115 - Lerk
impulse 116 - Fade
impulse 117 - Onos
impulse 101 - Carapace
impulse 102 - Regeneration
impulse 103 - Redemption
impulse 107 - Celerity
impulse 108 - Adrenaline
impulse 109 - Silence
impulse 110 - Cloaking
impulse 111 - Focus
impulse 112 - Scent of Fear
Both
impulse 5 - Go to the Ready Room (same as "readyroom")
impulse 100 - Toggle flashlight/hive sight
impulse 201 - Spray logo
<b>X---snip---X</b>
cvarlist impulse does not work. Maybe the devs can help with an updated list?
And I could SWEAR that up top, Impulse 3 = drop?
Also HL uses userconfig.cfg instead of autoexec.cfg since the switch to steam.
<!--QuoteEnd--></td></tr></table><div class='postcolor'><!--QuoteEEnd-->
HL uses whatever .cfg you tell it to. <!--QuoteEnd--> </td></tr></table><div class='postcolor'> <!--QuoteEEnd-->
True, but it uses userconfig.cfg automatically. It used to use autoexec.cfg automatically but no longer does.
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.
<a href='http://nslearn.org/EEpVApVkZZTFjWVVbv.shtml' target='_blank'>http://nslearn.org/EEpVApVkZZTFjWVVbv.shtml</a>
Sad huh?
j/k. Nice work prodigy very well written
<a href='http://nslearn.org/EEpVApVkZZTFjWVVbv.shtml' target='_blank'>http://nslearn.org/EEpVApVkZZTFjWVVbv.shtml</a>
And ty sandman :>
"Mr. I don't play competitively anymore" :<
^^
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