MAIN MENU:
Home
About us
FORUM
Links
Contact us
JOINING:
Join
Rules
Clan Structure
Required Items
Required Binds
Help us
EVENTs & PROJECTs:
Events & Projects
Event Calendar
Host an Event Form
Events Department
Training Department
Recruiting Department
MyTuner Project
MyTuner Manual
MyTuner Eval Form
Map Terminolgy Proj.
[TiC] Magazine
Special Ops Group:
S.O.G.
Challenge us
PRIVATE SECTION:
Private Area
(Note: We log
everything)
SEARCH:

Site
visitors
Since 5 June, 1999.
|
| Tips
& Tutorials/
[TiC-G]MeanGoof's Scripting
Tutorial/ Lesson#2: |
|
![MeanGoof wrote this scripting tutorial to help the MiGHTY [TiC]Clan and others.](http://www.ticclan.com/tutorials/meangoofs-script-lessons/images/meangoof.gif)
MeanGoof's Scripting Tutorials:
(17 July, 2002)
(By: "Meangoof")
(Former [TiC]Clan Guest)
Lesson #2:
Buy Scripts for CS:
What is a buy
script ? :
A buy script is a tool that you put in place
to expedite the ritual that takes place every time you respawn
after a round of counterstrike. By that I mean the ceremony of
opening up the buy menu half a dozen times to buy all the
goodies you can afford so you can get on with the frags in the
new round. One problem though, if you don't buy your stuff
very quickly, you will be left behind by the rest of your team
who will be getting out to the frags first because they found
a faster way to buy all of their stuff. This faster way is
what buy scripts are all about. You pack all of the
functionality to buy the kit you want to buy behind a
particular key, and all you need to do when you respawn is hit
that key and whammo, all your stuff has been purchased and you
are the first one to go.
It is a little bit more complicated than that, but you get the
picture.
In essence, what you buy is limited by:
a) What options are currently available on the map you are
playing. For example, on oil rig, if you are the VIP, all that
you can buy is ammo for your pistol.
b) The amount of money you have.
But before we go on making buy script, I need to cover a few
new commands that we have not seen yet.
Back to the top of page
Commands
used in buy scripts:
1.) buy :
When executed, this command opens up the buy menu. On my
computer, this command is bound to my b key on my keyboard.
2.) buyequip :
When executed, this command opens the buy equipment menu,
bypassing the buy main menu altogether.
3.) buyammo1 :
When executed, and if you have enough money, this command buys
you some primary ammo.
4.) buyammo2 :
When executed, and if you have enough money, this command buys
you secondary ammo.
5.) menuselect :
A two part command to select a particular option from a menu.
Example, menuselect 1 selects the first option of the menu
that is currently opened.
6.) slot10 :
Selects the cancel option of the currently opened menu.
Back to the top of page
Server lag issue:
One thing you must always be aware of when writing buy scripts
is that the buy commands are very sensitive to your ping on
the current server. Because of this, many buy scripts will
work fine when used on a particular server, but will fail
miserably when used on another server that has a high ping.
Why is that? The reason is because the buy command requires to
communicate with the server, so if you issue the buy command
and follow this with the immediate execution of particular
menuselect commands, the menuselect commands will end up being
executed before the buy menu is even opened. Needless to say,
issuing a menuselect command without any menu options
available because the menu is not opened, will get you nowhere
fast.
So how do we solve this problem. Well, if I worked for Valve,
I would create a new CS command to synchronize with the server
before I issue my menuselect commands. but since I don't work
for Valve, I have to use the kludge that they have provided us
with, known as the wait command. The number of wait commands
you use depend on the type of connection you have (dial-up use
more than DSL or cable), and on the ping of the particular
server that you will be playing on. Since most of us play on
more than one server, the above information is pretty useless.
So if you want your buy command to work on all the servers
that you play on, test it on the server that has the highest
ping, if it works there, it will likely work on all servers.
The drawback from this approach, is that the execution time of
your script will be slower than it should be when you are on a
fast server (but it will still be much faster than going
through the menus manually).
So the folks at Valve, if you read this, in your next version
of half-life, it would be nice if you could create
synchronization commands.
Before I go through a buy script with you I am first providing
you with the hierarchy of the buy menus.
Back to the top of page
Buy menus
Hierarchy:
When you buy something, you have to manually
navigate through the buy menus. Well your scripts are not
immune from this, they too have to navigate (albeit much
faster) through the menus. So for reference, here is the
hierarchy of the buy menus:
For Counter-terrorists:
1 Pistols - 1 USP Tact $500
- 2 Glock 18 $400
- 3 Desert Eagle $650
- 4 P228 $600
- 6 Five-Seven $750
- 0 cancel
2 Shotguns - 1 M3 Super 90 $1700
- 2 XM1014 $3000
- 0 cancel
3 SMGs - 1 MP5/N $1500
- 2 TMP $1250
- 3 P90 $2350
- 5 UMP45 $1700
- 0 cancel
4 Rifles - 3 M4A1 $3100
- 4 Steyr Aug $3500
- 5 Steyr Scout $2750
- 6 AW/M $4750
- 8 SIG 550 $4200
- 0 cancel
5 Machine Guns - 1 M249 $5750
- 0 cancel
6 Primary ammo $60
7 Secondary Ammo $40
8 Equipment - 1 Kevlar $650
- 2 Kevlar + Helmet $1000
- 3 Flashbang $300
- 4 HE grenade $300
- 5 Smoke grenade $300
- 6 defusal kit $200
- 7 night vision $1250
- 0 cancel
0 Cancel
For Terrorists:
1 Pistols - 1 USP Tact $500
- 2 Glock 18 $400
- 3 Desert Eagle $650
- 4 P228 $600
- 5 96G Elites $1000
- cancel
2 Shotguns - 1 M3 Super 90 $1700
- 2 XM1014 $3000
- 0 cancel
3 SMGs - 1 MP5/N $1500
- 3 P90 $2350
- 4 MAC-10 $1400
- 5 UMP45 $1700
- 0 cancel
4 Rifles - 1 AK-47 $2500
- 2 SG-552 $3500
- 5 Steyr Scout $2750
- 6 AW/M $4750
- 7 G3/SG-1 $5000
- 0 cancel
5 Machine Guns - 1 M249 $5750
- 0 cancel
6 Primary ammo $60
7 Secondary Ammo $40
8 Equipment - 1 Kevlar $650
- 2 Kevlar + Helmet $1000
- 3 Flashbang $300
- 4 HE grenade $300
- 5 Smoke grenade $300
- 7 night vision $1250
- 0 cancel
As you can see, there are slight differences in the menus
depending on which side you are playing.
Back to the top of page
Strategies for buy kits:
Before we go all out with gun blazing
writing buy scripts, we have to do some thinking about how we
can built them so they can be useful. After all, the stuff you
buy will depend on many things like: what map you are playing,
are you T or CT, how much money you have, as well as your
personal tastes, it will also depend on what the team
strategies are.
One approach would be to develop a list of possible kits that
you could buy given that you have a particular amount of
money. One example follows:
If you had $800 (starting amount on many servers) you could
have the choice of the following kits (others are possible
too, this is just an example):
kit a - Desert Eagle $650, secondary ammo $40 = $690.
kit b - Flashbang $300, HE grenade $300, Defuser kit $200 =
$800.
If you had $1000
kit a - Desert Eagle $650, Secondary ammo $40,HE grenade $300
= $990.
Kit b - Same as kit a, but defuser kit instead of grenade =
$650+$40+200 = $890
And so on. You get the picture. Before you get started on buy
script, you must know how you want to organize each one so
that they meet your need (which is to buy you what you need
for the current situation faster than if you had to go through
the menus manually.)
One strategy (and this is one amongst many) would be to create
three buy keys. One buy key to buy your primary weapon with
primary ammo, one buy key to buy your secondary weapon with
secondary ammo, and a third buy key to buy equipment. The
reason for this approach is that you don't need to buy
everything every round. If you survive a round, your may not
need to buy a new weapon, but may need to refill your
equipment. To supplement this approach, you may want to create
a cycler key that will allow you to cycle between different
amounts of money that you want to spend (i.e. the cycler would
change the buy script that your other three keys are bound to,
so that they don't buy anymore than what you specify in the
cycler). This would allow your buy key to change with the
value of the cycler, giving you more buying power as you
amount of cash increases. By using a combination of a cycler
and three buy keys, you limit the number of keys you have to
remember (if you had a key for each different kit you want to
buy you would end up with so many different keys that you
would end up not buying what you want because of finger
problems).
Just remember one thing, the approach is up to you, whatever
you feel comfortable with. This class is not about cycler
scripts (that was last class) it is about buy scripts, and
this section is solely to give you some ideas on how you can
go about giving some structure to your buy scripts. There are
those who just want one kind of weapon and some kevlar and
grenades every time they respawn, no matter how much money
they have. So one approach is to put the items in the order of
priority in the script and try to buy the whole kadoodle each
time, and when you run out of money, the script will stop
purchasing (just as if you went into the buy menu manually and
tried to buy something that you can't afford).
Okay, enough about buy script strategies, now we will get on
writing a simple buy script.
Back to the top of page
A simple buy
script:
In this section I tried to keep the script as simple as
possible, while still exposing all of the issues associated
with buy scripts. We start with the following simple script
that I will then dissect line by line:
alias wait4 "wait;wait;wait;wait"
alias wait8 "wait4;wait4"
alias wait16 "wait8;wait8"
alias +buyFlashbang "buy;wait16;menuselect 8;wait16;menuselect
3;wait16"
alias -buyFlashbang "slot10;wait16;slot10;wait16"
bind "f1" "+buyFlashbang"
The first three lines of the script are there for the purpose
of creating a wait16 command. I did it in three lines because
to do it in one line would have required me to type the wait
command 16 times on one line, and I am too lazy to do that.
The fourth line: alias +buyFlashbang "buy;wait16;menuselect
8;wait16;menuselect 3;wait16"
-----------------------------------------------------------------------------------------
This line creates a new command known as +buyFlashbang. When
executed, this command will buy you a flashbang grenade. The
first thing this command does is to execute the buy command.
The buy command, as explained earlier, opens up the buy menu.
The next thing done by this command is to just sit and wait
for 16 game tics. I used this number arbitrarily, you may find
that only two tics are sufficient on the server you use, this
is something that you have to fine tune, but it is required.
If this wait command(s) was not at this position, the
menuselect 8 command would execute immediately after the buy
command is started (and before the buy menu was opened)
causing the script to fail. Incidentally, the 8th option on
the main buy menu opens the equipment menu, which is why the
third command executed by the +buyFlashbang command is
menuselect 8. Again after the menuselect 8 command I have put
another wait16 command (this is something that you should fine
tune). The second to last thing that the +buyFlashbang command
does is to select the third option from the equipment menu,
which happens to be the flashbang grenade (menuselect 3). And
finally, I added a wait16 command to give the script a chance
to complete the selection.
The fifth line: alias -buyFlashbang
"slot10;wait16;slot10;wait16"
-----------------------------------------------------------------
This line defines the -buyFlashbang command. Since this is a
+/- command, when the key bound to this command is pressed,
the + version of the command is executed (fourth line above),
and when the key bound to the + version is released, the -
version is magically executed for you. So if you were to bind
the f1 key to +buyFlashbang, when you press the key it would
buy you the goodies, and when you release the key it would do
the funny things you see written in the fifth line.
The slot10 command closes down the menu. I am not sure why,
but in all examples I have seen out there on the net, it
appears that this command needs to be issued at least twice to
close the menu properly. You also have some wait commands in
between to give each slot10 commands a chance to execute
properly. In this case, I put 16 (overkill, but will probably
work on every server).
That's all there is to writing buy scripts. By the way, the
script above may not be the best way to buy stuff from the
equipment menu. There is a command called buyequip which
automatically gets you into the equipment menu, so another
script that would do the job would be:
alias wait4 "wait;wait;wait;wait"
alias wait8 "wait4;wait4"
alias wait16 "wait8;wait8"
alias +buyFlashbang "buyequip;wait16;menuselect 3;wait16"
alias -buyFlashbang "slot10;wait16;slot10;wait16"
That is all, write this script into a script file. I would not
myself put the bind directly into the script file, I would
instead type it directly from the game console or use the
kb_act.lst file in combination with the games controls menu.
So type it in and let's get on the server to try it out.
Back to the top of page
This page was originally created by [TiC]EVIL
28Aug01. Last updated 02/06/03.
|
|
SERVERs:
[TiC]Clan Servers
Player's Code of
Conduct
Rcon Guidelines
[TiC] CS Server STATS
[TiC] CS Gametiger
Find your IP Number
SCRIPTs:
Scripts
TFC Scripting Tutorial
CS Scripting Tutorial
TFC Script Set
HL Speak Commands
TIPs:
Tips
Half-life & CS Tweaks
Crosshairs & Sprites
TFC Strategies
CS & TFC Newbie
Guide
Counter-Terrorism
Guide
Logo WareHouse
Color Logo Bible
Clan Leader's Bible







|