What Is A Script

the_holethe_hole Join Date: 2004-01-03 Member: 25019Posts: 437Members, Constellation
edited January 2005 in Scripting Discussion
An introduction to the basics
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

http://nslearn.org/EEpVApVkZZTFjWVVbv.shtml





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:
http://www.csnation.net/view.php/csinfo/sc...bindlisting.csn
This is a list of all keys bindable by the console, their ingame, and out of game names. (Thanks to mint's thread)

http://www.planethalflife.com/commands/commands/index.shtml
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)
zip
zip
scripts.zip
303B
Post edited by Unknown User on
Ingame Nick:: Prodigy / kfR
«1

Comments

  • UzguzUzguz Join Date: 2003-06-05 Member: 17016Posts: 342Members, 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 Join Date: 2003-08-28 Member: 20307Posts: 132Members, Constellation
    this is sweet, thank you
  • DragonMechDragonMech Join Date: 2003-09-19 Member: 21023Posts: 6,781Members, Constellation, Reinforced - Shadow
    If you guys like this, be sure to check out my script pack for NS. 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. smile-fix.gif
    I see custom titles. <_< >_>

    QUOTE (DOOManiac @ Jul 10 2005, 07:00 PM)
    I for one can't imagine downloading several gigs of pornography from a typewriter.
  • cortexcortex Join Date: 2003-11-28 Member: 23707Posts: 410Members
    lol, nice pimpage dragon tounge.gif

    nice little write up though, read the first 2 paragraphs and decided it was written well.
    image
    image
  • MintmanMintman Join Date: 2003-05-30 Member: 16866Posts: 1,198Members
    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: http://www.unknownworlds.com/forums/index....showtopic=74222
    Post edited by Unknown User on
    user posted image
  • coriscoris Join Date: 2003-07-08 Member: 18034Posts: 2,064Members, 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 :/
    LOL BLOG!
    also known as narc
  • DarkFrostDarkFrost Join Date: 2003-04-03 Member: 15154Posts: 1,417Members, NS1 Playtester, Constellation
    QUOTE (Mintman @ Jan 15 2005, 01:14 PM)
    Edit:

    Also HL uses userconfig.cfg instead of autoexec.cfg since the switch to steam.

    HL uses whatever .cfg you tell it to.
  • the_holethe_hole Join Date: 2004-01-03 Member: 25019Posts: 437Members, Constellation
    corrected, thanks
    Ingame Nick:: Prodigy / kfR
  • uk_jauk_ja Join Date: 2002-12-20 Member: 11245Posts: 75Members, Constellation
    One of the best posts i have read. Very good work here smile-fix.gif
  • NolSinklerNolSinkler On the Clorf Join Date: 2004-02-15 Member: 26560Posts: 1,604Members, Constellation
    The script pack is corrupted.
    image
  • Guardian1Guardian1 Join Date: 2003-09-14 Member: 20853Posts: 94Members
    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: 25019Posts: 437Members, Constellation
    Edited, added semicolon and 2 reference links to command list and bindable keys, (thanks to Mintman's thread)
    Ingame Nick:: Prodigy / kfR
  • SpaceJesusSpaceJesus Join Date: 2004-07-02 Member: 29683Posts: 938Banned
    *applauds*
    *IMAGE BALEETED.* Sigs are not to exceed 400x75 or 22KB. No exceptions. -Talesin
  • Guardian1Guardian1 Join Date: 2003-09-14 Member: 20853Posts: 94Members
    Any idea where I can find the list of CVARs for NS specifically?
  • DragonMechDragonMech Join Date: 2003-09-19 Member: 21023Posts: 6,781Members, Constellation, Reinforced - Shadow
    QUOTE (Guardian1 @ Jan 15 2005, 12:37 PM)
    Any idea where I can find the list of CVARs for NS specifically?

    "cvarlist cl_" in console...have fun
    I see custom titles. <_< >_>

    QUOTE (DOOManiac @ Jul 10 2005, 07:00 PM)
    I for one can't imagine downloading several gigs of pornography from a typewriter.
  • the_holethe_hole Join Date: 2004-01-03 Member: 25019Posts: 437Members, Constellation
    QUOTE (Guardian1 @ Jan 15 2005, 01:37 PM)
    Any idea where I can find the list of CVARs for NS specifically?

    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.
    Ingame Nick:: Prodigy / kfR
  • Guardian1Guardian1 Join Date: 2003-09-14 Member: 20853Posts: 94Members
    QUOTE (DragonMech @ Jan 15 2005, 11:39 AM)
    QUOTE (Guardian1 @ Jan 15 2005, 12:37 PM)
    Any idea where I can find the list of CVARs for NS specifically?

    "cvarlist cl_" in console...have fun

    That doesn't show impulse commands. After a bit of googling, I was able to find a great guide at http://www.ausns.com/content/tutorials_gui...e_commands.html

    Those Aussies know their stuff!

    X---snip---X

    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

    X---snip---X
  • FuRoNFuRoN Join Date: 2004-09-06 Member: 31448Posts: 18Members
    PRODIGY......................................
    Sig image limits are at 400*75 pixels and 22KB. No exceptions.

    -- Nem


    one of few niccaz in ns... betta be grateful
  • MrRadicalEdMrRadicalEd Turrent Master Join Date: 2004-08-13 Member: 30601Posts: 716Members
    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.
    What if we crowdfund the Director's Chair?
  • obuhobuh Not Quite Smart at NS Join Date: 2003-03-31 Member: 15072Posts: 701Members, 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.
    Psalm 121
    1I 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
    .
  • Guardian1Guardian1 Join Date: 2003-09-14 Member: 20853Posts: 94Members
    edited January 2005
    QUOTE (MrRadicalEd @ Jan 15 2005, 01:26 PM)
    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.

    cvarlist impulse does not work. Maybe the devs can help with an updated list?

    And I could SWEAR that up top, Impulse 3 = drop?
    Post edited by Unknown User on
  • MrRadicalEdMrRadicalEd Turrent Master Join Date: 2004-08-13 Member: 30601Posts: 716Members
    Yeah my mistake then. I didn't look through the whole list.
    What if we crowdfund the Director's Chair?
  • the_holethe_hole Join Date: 2004-01-03 Member: 25019Posts: 437Members, 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.
    Ingame Nick:: Prodigy / kfR
  • MintmanMintman Join Date: 2003-05-30 Member: 16866Posts: 1,198Members
    QUOTE (DarkFrost @ Jan 15 2005, 02:37 PM)
    QUOTE (Mintman @ Jan 15 2005, 01:14 PM)
    Edit:

    Also HL uses userconfig.cfg instead of autoexec.cfg since the switch to steam.

    HL uses whatever .cfg you tell it to.

    True, but it uses userconfig.cfg automatically. It used to use autoexec.cfg automatically but no longer does.
    user posted image
  • the_holethe_hole Join Date: 2004-01-03 Member: 25019Posts: 437Members, 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.

    http://nslearn.org/EEpVApVkZZTFjWVVbv.shtml
    Post edited by Unknown User on
    Ingame Nick:: Prodigy / kfR
  • typical_skeletontypical_skeleton Join Date: 2003-02-24 Member: 13944Posts: 572Members
    you're one of NS's finest players? didn't know. =P
  • the_holethe_hole Join Date: 2004-01-03 Member: 25019Posts: 437Members, Constellation
    Play with me to find out? ;-)
    Ingame Nick:: Prodigy / kfR
  • SandVaNSandVaN Join Date: 2003-06-25 Member: 17694Posts: 22Members
    QUOTE (typical skeleton @ Jan 16 2005, 04:42 PM)
    you're one of NS's finest players?  didn't know. =P

    Sad huh?

    j/k. Nice work prodigy very well written
    -Sand]V[aN
    "I do what I do the way I do it." - Macgyver
  • the_holethe_hole Join Date: 2004-01-03 Member: 25019Posts: 437Members, Constellation
    edited January 2005
    Updated the one on NSLearn.org, it looks much better, and is easier to find what you are looking for

    http://nslearn.org/EEpVApVkZZTFjWVVbv.shtml

    And ty sandman :>

    "Mr. I don't play competitively anymore" :<
    Post edited by Unknown User on
    Ingame Nick:: Prodigy / kfR
  • That_Annoying_KidThat_Annoying_Kid Sire of Titles Join Date: 2003-03-01 Member: 14175Posts: 5,579Members, Constellation
    QUOTE (Uzguz @ Jan 14 2005, 07:28 PM)
    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
«1
This discussion has been closed.