What Is A Script

the_holethe_hole Join Date: 2004-01-03 Member: 25019Members, Constellation
edited January 2005 in Scripting Discussion
<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)
«1

Comments

  • UzguzUzguz Join Date: 2003-06-05 Member: 17016Members, Constellation
    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.
  • TheTitanTheTitan IL, USA Join Date: 2003-08-28 Member: 20307Members, Constellation
    this is sweet, thank you
  • DragonMechDragonMech Join Date: 2003-09-19 Member: 21023Members, Constellation, Reinforced - Shadow
    If you guys like this, be sure to check out my <a href='http://www.unknownworlds.com/forums/index.php?showtopic=85961' target='_blank'>script pack for NS.</a> It's got many commonly used scripts and I'm continually working on the pack. I'd appreciate any script ideas you guys have for me. <!--emo&:)--><img src='http://www.unknownworlds.com/forums/html/emoticons/smile-fix.gif' border='0' style='vertical-align:middle' alt='smile-fix.gif' /><!--endemo-->
  • cortexcortex Join Date: 2003-11-28 Member: 23707Members
    lol, nice pimpage dragon <!--emo&:p--><img src='http://www.unknownworlds.com/forums/html/emoticons/tounge.gif' border='0' style='vertical-align:middle' alt='tounge.gif' /><!--endemo-->

    nice little write up though, read the first 2 paragraphs and decided it was written well.
  • MintmanMintman Join Date: 2003-05-30 Member: 16866Members
    edited January 2005
    Good guide, but I'm pretty sure:

    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>
  • coriscoris Join Date: 2003-07-08 Member: 18034Members, Constellation
    It contains some small errors but the general impression is that it's very well written (for example it would be alias +walk +forward | alias -walk -forward etc.)

    Great job, but I dont think that this will convert any scripting fundemantalists :/
  • DarkFrostDarkFrost Join Date: 2003-04-03 Member: 15154Members, NS1 Playtester, Constellation
    <!--QuoteBegin-Mintman+Jan 15 2005, 01:14 PM--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>QUOTE</b> (Mintman @ Jan 15 2005, 01:14 PM)</td></tr><tr><td id='QUOTE'><!--QuoteEBegin--> Edit:

    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.
  • the_holethe_hole Join Date: 2004-01-03 Member: 25019Members, Constellation
  • uk_jauk_ja Join Date: 2002-12-20 Member: 11245Members, Constellation
    One of the best posts i have read. Very good work here <!--emo&:)--><img src='http://www.unknownworlds.com/forums/html/emoticons/smile-fix.gif' border='0' style='vertical-align:middle' alt='smile-fix.gif' /><!--endemo-->
  • NolSinklerNolSinkler On the Clorf Join Date: 2004-02-15 Member: 26560Members, Constellation
    The script pack is corrupted.
  • Guardian1Guardian1 Join Date: 2003-09-14 Member: 20853Members
    Maybe you can give the list of CVARs that NS uses so that we know which binds and aliases will work best?

    I'm interested in the communications aspects.
  • the_holethe_hole Join Date: 2004-01-03 Member: 25019Members, Constellation
    Edited, added semicolon and 2 reference links to command list and bindable keys, (thanks to Mintman's thread)
  • SpaceJesusSpaceJesus Join Date: 2004-07-02 Member: 29683Banned
  • Guardian1Guardian1 Join Date: 2003-09-14 Member: 20853Members
    Any idea where I can find the list of CVARs for NS specifically?
  • DragonMechDragonMech Join Date: 2003-09-19 Member: 21023Members, Constellation, Reinforced - Shadow
    <!--QuoteBegin-Guardian1+Jan 15 2005, 12:37 PM--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>QUOTE</b> (Guardian1 @ Jan 15 2005, 12:37 PM)</td></tr><tr><td id='QUOTE'><!--QuoteEBegin--> Any idea where I can find the list of CVARs for NS specifically? <!--QuoteEnd--> </td></tr></table><div class='postcolor'> <!--QuoteEEnd-->
    "cvarlist cl_" in console...have fun
  • the_holethe_hole Join Date: 2004-01-03 Member: 25019Members, Constellation
    <!--QuoteBegin-Guardian1+Jan 15 2005, 01:37 PM--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>QUOTE</b> (Guardian1 @ Jan 15 2005, 01:37 PM)</td></tr><tr><td id='QUOTE'><!--QuoteEBegin--> Any idea where I can find the list of CVARs for NS specifically? <!--QuoteEnd--> </td></tr></table><div class='postcolor'> <!--QuoteEEnd-->
    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.
  • Guardian1Guardian1 Join Date: 2003-09-14 Member: 20853Members
    <!--QuoteBegin-DragonMech+Jan 15 2005, 11:39 AM--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>QUOTE</b> (DragonMech @ Jan 15 2005, 11:39 AM)</td></tr><tr><td id='QUOTE'><!--QuoteEBegin--><!--QuoteBegin-Guardian1+Jan 15 2005, 12:37 PM--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>QUOTE</b> (Guardian1 @ Jan 15 2005, 12:37 PM)</td></tr><tr><td id='QUOTE'><!--QuoteEBegin--> Any idea where I can find the list of CVARs for NS specifically? <!--QuoteEnd--></td></tr></table><div class='postcolor'><!--QuoteEEnd-->
    "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>
  • FuRoNFuRoN Join Date: 2004-09-06 Member: 31448Members
    PRODIGY......................................
  • MrRadicalEdMrRadicalEd Turrent Master Join Date: 2004-08-13 Member: 30601Members
    I know that list isn't entirely up to date.. "impulse 3" is the new "drop" command now. I haven't tried it, but "cvarlist impulse" should work too.
  • obuhobuh Not Quite Smart at NS Join Date: 2003-03-31 Member: 15072Members, Constellation
    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.
  • Guardian1Guardian1 Join Date: 2003-09-14 Member: 20853Members
    edited January 2005
    <!--QuoteBegin-MrRadicalEd+Jan 15 2005, 01:26 PM--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>QUOTE</b> (MrRadicalEd @ Jan 15 2005, 01:26 PM)</td></tr><tr><td id='QUOTE'><!--QuoteEBegin--> I know that list isn't entirely up to date.. "impulse 3" is the new "drop" command now. I haven't tried it, but "cvarlist impulse" should work too. <!--QuoteEnd--></td></tr></table><div class='postcolor'><!--QuoteEEnd-->
    cvarlist impulse does not work. Maybe the devs can help with an updated list?

    And I could SWEAR that up top, Impulse 3 = drop?
  • MrRadicalEdMrRadicalEd Turrent Master Join Date: 2004-08-13 Member: 30601Members
    Yeah my mistake then. I didn't look through the whole list.
  • the_holethe_hole Join Date: 2004-01-03 Member: 25019Members, Constellation
    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.
  • MintmanMintman Join Date: 2003-05-30 Member: 16866Members
    <!--QuoteBegin-DarkFrost+Jan 15 2005, 02:37 PM--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>QUOTE</b> (DarkFrost @ Jan 15 2005, 02:37 PM)</td></tr><tr><td id='QUOTE'><!--QuoteEBegin--> <!--QuoteBegin-Mintman+Jan 15 2005, 01:14 PM--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>QUOTE</b> (Mintman @ Jan 15 2005, 01:14 PM)</td></tr><tr><td id='QUOTE'><!--QuoteEBegin--> Edit:

    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.
  • the_holethe_hole Join Date: 2004-01-03 Member: 25019Members, Constellation
    edited January 2005
    autoexec still is used, same with userconfig...

    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>
  • typical_skeletontypical_skeleton Join Date: 2003-02-24 Member: 13944Members
    you're one of NS's finest players? didn't know. =P
  • the_holethe_hole Join Date: 2004-01-03 Member: 25019Members, Constellation
    Play with me to find out? ;-)
  • SandVaNSandVaN Join Date: 2003-06-25 Member: 17694Members
    <!--QuoteBegin-typical skeleton+Jan 16 2005, 04:42 PM--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>QUOTE</b> (typical skeleton @ Jan 16 2005, 04:42 PM)</td></tr><tr><td id='QUOTE'><!--QuoteEBegin-->you're one of NS's finest players?  didn't know. =P<!--QuoteEnd--></td></tr></table><div class='postcolor'><!--QuoteEEnd-->
    Sad huh?

    j/k. Nice work prodigy very well written
  • the_holethe_hole Join Date: 2004-01-03 Member: 25019Members, Constellation
    edited January 2005
    Updated the one on NSLearn.org, it looks much better, and is easier to find what you are looking for

    <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" :<
  • That_Annoying_KidThat_Annoying_Kid Sire of Titles Join Date: 2003-03-01 Member: 14175Members, Constellation
    <!--QuoteBegin-Uzguz+Jan 14 2005, 07:28 PM--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>QUOTE</b> (Uzguz @ Jan 14 2005, 07:28 PM)</td></tr><tr><td id='QUOTE'><!--QuoteEBegin--> 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. <!--QuoteEnd--> </td></tr></table><div class='postcolor'> <!--QuoteEEnd-->
    ^^

    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
This discussion has been closed.