A complete guide to scripting by J2K! Difficulty: Beginner |
| Category: CS:S > Scripting | Author(s): J2K |

//===================================
//A complete guide to scripting by J2K!
//===================================
Hey all!
Welcome to J2K's guide to all that is scripting in Counter-Strike Source!
I have been scripting since CS 1.5 and have created many original scripts which can be accessed through my submissions page of my profile. Hopefully, by the time you have read this tutorial, you will have had some of your own ideas go through your head and have a good idea how to implement them!
//====================================
//Part 1 - Required files
//====================================
Before we get started, lets make the necessary files!
Go to your Counter-Strike Source directory
C:\Program Files\Steam\SteamApps\UserName\Counter-strike Source
If it does not exist, create a folder named cstrike
In the cstrike folder, if it does not exist, create a
folder named cfg
Now to create the blank config files to work with, open NotePad and click
File > Save as...
For the name type
"autoexec.cfg"
For the file type select
All Files
Save it into the cfg folder
Repeat the process to create "userconfig.cfg"
You should now have 2 files within the cfg folder
autoexec.cfg
userconfig.cfg
//====================================
//Part 2 - What is a script?
//====================================
A script is a combination of commands and / or settings that make life easier for the user and save a lot of time and effort.
Scripts perform things from buying multiple items in one button, changing network and control settings quickly and simplifying in game actions so you can spend less time pressing buttons and entering settings, and more time fragging your opponents.
//====================================
//Part 3 - How do scripts work
//====================================
Scripts are stored in config files that Counter-Strike Source can execute. The only two files that you need are the two we created earlier in this tutorial;
autoexec.cfg
userconfig.cfg
There is a file called avalve.rc that automatically executes the above two files every time you load Counter-Strike Source.
Within autoexec.cfg aliases are stored. An alias is a name given to your custom command that can associate a number of actions or settings when the key bound to that alias is pressed.
Within userconfig.cfg are bindings for your custom commands.
//====================================
//Part 4 - The alias command
//====================================
In this step, we will make our first alias to be bound to a key. We will start with something simple, a script that buys a pistol and some armour in one button.
Open autoexec.cfg and type the following into it:
alias deaglearmour "buy deagle; buy vest;"
alias sets the name of the script to the name that follows.
deaglearmour is the name of the script and what we will bind to a key later.
"buy deagle; buy vest;" is the commands associated with our alias that will be performed when we hit the bound key.
Now open userconfig.cfg and enter the following
bind P deaglearmour
bind tells CS: Source to bind a key to a command.
P is the key we are binding our alias to.
deaglearmour is the name of the alias we set up before that we are binding to the P key.
If we go into the game at this point, pressing the P key would result in the purchasing of a Desert Eagle pistol and a Kevlar Vest in a single key press!
//====================================
//Part 5 - Toggle and cycle scripts
//====================================
Toggle and cycle scripts rely heavily on the alias command. It becomes second nature making toggle scripts once you learn the general pattern they follow. I'll go through one step by step for you.
For simplicity's sake i will make a fake script first, and write a real one afterwards.
alias toggler option1
toggler is the name of what needs to be toggled, and what you eventually bind to a key.
option1 refers to the first option to be toggled.
alias option1 "command; alias toggler option2;"
option1 is the name of the first option in the toggler.
command is the command you wish to associate with the first toggle option.
"alias toggler option2;" tells the toggler bind to change to option2 on the next key press.
alias option2 "command; alias toggler option1;"
option2 is the name of the second option in the toggler.
command is the command you wish to associate with the second toggle option.
"alias toggler option1;" tells the toggler bind to change back to option1 on the next key press.
bind = toggler
You can do this for as many options as you wish, as long as the final option refers to the first option, creating an endless cycle.
A working example of this is below.
alias namechanger name1
alias name1 "name Name 1; alias namechanger name2;"
alias name2 "name Name 2; alias namechanger name3;"
alias name3 "name Name 3; alias namechanger name1;"
bind = namechanger
Now when you go into the game, pressing the = key several times will change your name differently each time! |
| Added: 1 year ago | Tags: guide, scripting, alias, bind, toggle, cycle |
 Add Feedback Provide constructive feedback. What is "constructive"?You cannot post yet!Get involved on FPSB by posting your thoughts. Give authors your feedback to help them develop. To post in this submission register or login. |
 You cannot assess yet!Moderating FPSB is in your hands - when you assess a submission your vote determines its success or failure. To vote on this submission register or login. This Tutorial in a nutshell... Well Written & Helpful 4 x Well Written 3 x Helpful 3 x Useful 2 x Detailed 2 x Informative 1 x Handy You cannot stamp yet!Stamps let you apply characteristics to submissions to help others understand them. To stamp this submission register or login.
 |
Sabotage Studios Originality, Creativity, Simplicity |
| Membership: On Request |
| Primary Skills: ? |
| Inception: 2 years ago |
Want more? Find related tuts. |