This tutorial will teach the reader how to make a buy menu for Counter-Strike Source. This is a intermediate tutorial and i will expect you to know a few things about scripting, such as aliases. All of the actruall code will begin with a "*", when you are typing in the code DO add this, only type in what comes after the "*". Now, lets begin.
First of all we will begin by creating a .cfg file in the 'cstrike\cfg\' folder. Open your "...valve\steam\steamapps\USERNAME\counter-strike source\cstrike\cfg\" folder and copy the config.cfg file and pasting it in the same folder. Change the name of the newly pasted .cfg file to "BuyMenu.cfg". Now open the file in Notepad so we may begin the editing process. For the beginning 3 lines we will make a comment showing the name of the script and who made it. Copy this down into the .cfg file:
*//
*//Buy Menu
*//by:
Change out the with your name, stating that you made this script. Anything that begins with a "<" and ends with a ">" is a variable that you are to change, depending on the case. ex) changes out to your name.
Reset Keys/Echo_on/Echo_off
Now we get down to the real scripting. We must first make all of the neccessary aliases so that our buy menu will function correctly.
The first thing for us to do to make this menu work is to set the keys for the menu. But because the Source Engine reads this file from top to bottom, we have to create the 'resetkeys' alias before the 'setkeys' alias. I'll explain this in more detail later. Copy this line into the 'BuyMenu.cfg' file.
*alias resetkeys "bind 0 slot0;bind 1 slot1;bind 2 slot2;bind 3 slot3;bind 4 slot4;bind 5 slot5;bind 6 slot6"
This alias resets the keys that will be set in the near future by the 'setkeys' alias. It resets the keys so that when you have closed out the menu, you can use the '0'-'6' keys properly, if you do not, when you press 1 it will execute a command for this buymenu instead of selecting your primary weapon from slot1. So this is very important. Now we must talk about the 'echo_on' and 'echo_off' aliases. Copy this line to the .cfg file.
*alias echo_on "developer 1;contimes 8;con_notifytime 35"
*alias echo_off "resetkeys;clear;developer 0;contimes 0;con_notifytime 0"
Now lets take a look at this. The first line consists of "alias echo_on" which sets the alias name to 'echo_on' by which other aliases recognise it. Inside the quotations includes 'devloper 1;contimes 8;con_notifytime 35". Lets look at each one of these commands, or cmds, seperatly. 'Developer 1' sets the developer mode to 1 and displays all console information on the top left-hand side of the screen, very very useful for text menus. The 'contimes 8' line tells the engine to show 8 lines of text, in that top left-hand side of the screen, at a time. 'Con_notifytime 35' is how long it show the text on the screen, for this line, it shows it for 35 seconds. Now, the "echo_off" alias is no different except for the command variables. The '0's' make the amount of lines shown and how long they are shown 0, which basicly clears the top left-hand corner. The 'developer 0' line makes the developer mode 0 and no longer displays any console test in the upper left-hand side of the screen. The only new command is 'clear' which clears the console, makes sense. Now onto the buy combos.
Buy Combos
Now we are to edit and create the combos that buy us the weapons that we say to. Each combo is set differently but set up the same. Copy this code into the .cfg file.
*alias combo1 "buy m4a1;buy ak47;buy deagle;buy kevhelm;echo_off"
*alias combo2 "buy galil;buy famas;buy p228;buy kevhelm;echo_off"
*alias combo3 "buy shotgun;buy deagle;buy kevhelm;buy hegrenade;echo_off"
*alias combo4 "buy tmp;buy mac10;buy fiveseven;buy kevlar;echo_off"
*alias combo5 "buy mp5;buy deagle;buy kevhelm;buy hegranade;buy flashbang;echo_off"
The alias names cannot be changed or else this buy menu will not work, so DO NOT touch them. The first line says "buy m4a1;buy ak47;buy deagle;buy kevhelm;echo_off". Lets analyse this line. The first thing you need to know about this is the command 'buy ' it buys a specific weapon () from the buymenu, but only if you are standing in a buy zone. So the first thing that is bought is your primary weapon, a M4A1 if you are CT, or an AK47 if you are a Terorrist, it automatically doesn't buy a M4A1 if you are a Terorrist and vice-versa if you are a CT. The next thing that is bought is your secondary weapon, the 'deagle' in this case, and the third is Kevlar and a Helmet. So the "combo setup" goes Primary->Secondary->Equipment, use that for all of the combos you make, but in this buy menu only make 5 combos total. The names for the combo aliases have to be; 'combo1', 'combo2', 'combo3', 'combo4' and 'combo5'. If they are not, this buy menu will not be functional. And the last command for the alias combo line is 'echo-off' which like we discussed before clears the text screen. OK, now we are getting into the display and clearing of the menu, as well as the setkeys and resetkeys aliases.
Display and Clearing Menu / Set and Reset Keys
We must now create an alias to clear the menu and reset the keys. It is important that we do this before the 'display_menu' and 'setkeys' aliases because it is referenced by them at a later time. Copy this code into the .cfg file.
*alias clear_menu "echo_off;resetkeys"
Do you remember, only a bit ago, when we talked about the 'resetkeys' alias? Well, it reset the keys that are set by the 'setkeys' alias which we will discuss now. This may be the most crucial part of the menu. It binds the keys that will be used to select which combo to buy. Copy this into the .cfg file.
*alias setkeys "bind 0 clear_menu;bind 1 combo1;bind 2 combo2;bind 3 combo 3;bind 4 combo4;bind 5 combo5;bind 6 buymenu"
This is that later time i was previously talking about where the 'setkeys' alias will reference the 'clear_menu' alias. The first bind, 'bind 0', is bound to the 'clear_menu' alias and when '0' is pressed, the menu will be cleared. Now comes the combo binds. Binds 1-5 bind the appropriate key to the appropriate combo. DO NOT mess this up, this is the key to your menu functioning properly. And last but not least, the 'bind 6 buymenu' command is added. When '6' is pressed, the normal buy menu is shown. That is all for binding keys, so we will now discuss the 'display_menu' alias, which is very important. Copy this to the "BuyMenu.cfg" file.
*alias display_menu "echo_on;echo .:'s Buy Menu:.;echo 1) M4A1/AK47, Deagle, Kevlar&Helm;echo 2) Galil/Famas, P228, Kevlar&Helm;echo 3) Pump Shotgun, Deagle, HEGrenade, Kevlar&Helm;echo 4) Tmp/Mac10, FiveSeven, Kevlar;echo 5) Mp5, Deagle, Kevlar&Helm, FlashBang;echo 6) Normal Buy Menu;echo 0) Cancel;setkeys"
Wow. Thats alot of code. Lets dive into it. This line first sets 'echo_on' on and echos '.:'s Buy Menu:.", which of course you would change the to your name. When the 'echo ' command is executed, the engine creates a new line in the console and displays on it what ever the message () is. Then it echos all of the combos, which are each listed on a different line. It displays the '6) Normal Buy Menu' and the '0) Cancel' lines. The 'display_menu' line is only to show the user what combos can be bought. Here is what it would look like in-game:
.:USERNAME's Buy Menu:.
1) M4A1/AK47, Deagle, Kevlar&Helm
2) Galil/Famas, P228, Kevlar&Helm
3) Pump Shotgun, Deagle, HEGrenade, Kevlar&Helm
4) Tmp/Mac10, FiveSeven, Kevlar;echo 5) Mp5, Deagle, Kevlar&Helm
5) Mp5, Deagle, Kevlar&Helm, FlashBang
6) Normal Buy Menu
0) Cancel
That is what will be displayed in the top left-hand corner of the screen if you press 'b'. Thats all for the 'display_menu' alias, now on to the last part of this script.
Bind B
This is the final line of the script and will be as important to the menu as all the rest of the script is. Copy this line to the .cfg file.
*Bind b display_menu
This binds the 'b' key to display the menu, set the keys and enable the buying of the combos you set. Now save your work. Close the file out and open up the valve.rc file that is in your 'cstrike\cfg\' folder. Create a new line at the bottom of whatever is already in there and type in this.
*exec BuyMenu.cfg
This makes it so that every time you open up Counter-Strike Source, you can use your buy menu by pressing 'b'. If you don't do this, your buy menu will not automatically be exec and you will not be able to use it. Save the valve.rc file and close it. Now open up Counter-Strike Source and test out your new Buy Menu. Enjoy.
-Psykolambchopz |