Tutorials Navigation

Tutorials :: New :: Popular :: Top Rated

Tutorials: 18,357 Categories: 12

Total Tutorial Views: 42,399,246

The Complete CFG Coding Tutorial

Tutorial Name: The Complete CFG Coding Tutorial  

Category: Xbox 360 Tutorials

Submitted By: -XeXWill-

Date Added:

Comments: 5

Views: 3,690

Related Forum: Xbox Forum

Share:

-The Complete CFG Coding Tutorial-


By XeXWill


CHAPTER 1: The Basics

I will begin by explaining what CFG is. CFG is a type of command based programming language. It is used primarily in the CoD franchise.

The first thing to talk about is binds. Binds are what activate commands, and are the backbone to any scripts.

The command to bind things is, well, "bind".

For Example:

bind (button here)


I will use the down dpad for this.

So,

bind DPAD_DOWN [command]


That will do a command when you press dpad down.

Here is a list of all the buttons you can bind:

DPAD_UP
DPAD_DOWN
DPAD_LEFT
DPAD_RIGHT
BUTTON_BACK
BUTTON_START
BUTTON_LTRIG (Left Trigger)
BUTTON_RTRIG (Right Trigger)
BUTTON_RSHLDR (Right Bumper)
BUTTON_LSHLDR (Left Bumper)
BUTTON_A
BUTTON_B
BUTTON_Y
BUTTON_X


Now in the game files, they set the buttons to various commands.

So DPAD_DOWN is set to "+actionslot 2", BUTTON_BACK is set to "togglescores".

But how to you assign commands? Easy! Just put the command right after the button.

So lets say I want to make it so that when I press the BACK button, I toggle god mode.

For this, I would do this:

bind BUTTON_BACK god


But when you do this, it stops you from seeing the scores. To see the scores, you simply add 2 commands to 1 button.

bind BUTTON_BACK god;togglescores


All commands are separated with a semi-colon.

Here is the list of default commands, with corrosponding buttons.

DPAD_UP +actionslot 1
DPAD_DOWN +actionslot 2
DPAD_LEFT +actionslot 3
DPAD_RIGHT +actionslot 4
BUTTON_BACK togglescores
BUTTON_START togglemenu
BUTTON_LTRIG +speed_throw
BUTTON_RTRIG +attack
BUTTON_RSHLDR +frag
BUTTON_LSHLDR +smoke
BUTTON_A +gostand
BUTTON_B +melee
BUTTON_Y weapnext
BUTTON_X +usereload


Now it's all fine and dandy that you can do that, but in the next chapter, we will cover putting commands into patches.

CHAPTER 2: Binds in patches

Ever since the release of the infamous mapname bind exploit, binds have been everywhere. Most people know them as "Infections".

But for those JTAG users, there is a much simpler and easier way.

The standard mapname exploit works like this.

self setClientDvar( "ui_mapname", "mp_shipment;bind BUTTON_BACK [commands]" );


That requires you to get infected, then go into splitscreen and press back.

But using a dvar called "activeAction", you can make it much easier. activeAction basically runs commands on the first frame of the game.

So as soon as you connect, it will run any command.

For Example,

self setClientDvar( "activeAction", "g_speed 600" );


This will make the game speed 600 as soon as the host connects.

The problem with activeAction is that it resets once the command(s) are initiated.

To avoid having to keep getting infected, you can do this.

self setClientDvar( "activeAction", "vstr loop" );
self setClientDvar( "loop", "set activeAction vstr loop;[commands here]" );

This basically loops itself, but is jumping the gun a little.

CHAPTER 3: Variable Strings and Mod Menus

Variable strings are what make mod menus possible.

I will explain them in GPD terms as it is much easier to explain that way.

Variable strings work like this.

bind DPAD_DOWN vstr x
set x [commands here]


The command for a variable string is "vstr".

When you press dpad down, it will run any commands set to x.

This may seem inconvinient, why not just do it with one line? I will explain.


Say if I wanted to make it so that when I press down once, it sets the game speed to 600. But when I press it a second time, it changes the timescale?

To do this, you would do this.

bind DPAD_DOWN vstr 0
set 0 vstr 1
set 1 set 0 vstr 2;g_speed 600
set 2 set 0 vstr 1;timescale 0.5


This would alternate between changing the timescale and the game speed.

But if you want to change just 1 dvar through multiple values, you use the command "toggle".

For Example:

bind BUTTON_BACK toggle g_speed 100 200 300 400 500


You separate each value with a space. Now everytime you press back, it will change the game speed to the next value.

Now, you might ask, "How do I make a mod menu with that!?" Well, its very simple.

The say command prints text onto your screen. You can print a maximum of 8 lines, which can be changed with the dvar "cg_chatHeight".

To make a mod menu, you do this.

self setClientDvar( "activeaction", vstr loop" );
self setClientDvar( "loop", "set activeaction vstr loop;say ^1Press ^0[^1DOWN^0] ^1For Mod Menu;bind DPAD_DOWN vstr menu" );
self setClientDvar( "menu", "vstr 0;bind DPAD_DOWN vstr DOWN;bind DPAD_UP vstr UP;bind BUTTON_A vstr EXEC;bind BUTTON_B vstr exit" );
self setClientDvar( "DOWN", "vstr 0" );
self setClientDvar( "UP", "vstr 7" );
self setClientDvar( "0", "set DOWN vstr 1;set UP vstr 7;vstr say1;set EXEC vstr command1" );
self setClientDvar( "1", "set DOWN vstr 2;set UP vstr 1;vstr say2;set EXEC vstr command2" );
self setClientDvar( "2", "set DOWN vstr 3;set UP vstr 2;vstr say3;set EXEC vstr command3" );
self setClientDvar( "3", "set DOWN vstr 4;set UP vstr 3;vstr say4;set EXEC vstr command4" );
self setClientDvar( "4", "set DOWN vstr 5;set UP vstr 4;vstr say5;set EXEC vstr command5" );
self setClientDvar( "5", "set DOWN vstr 6;set UP vstr 5;vstr say6;set EXEC vstr command6" );
self setClientDvar( "6", "set DOWN vstr 7;set UP vstr 6;vstr say7;set EXEC vstr command7" );
self setClientDvar( "7", "set DOWN vstr 0;set UP vstr 7;vstr say8;set EXEC vstr command8" );
self setClientDvar( "say1", "say ^1Option 1;say Option 2;say Option 3;say Option 4;say Option 5;say Option 6;say Option 7;say Option 8" );
self setClientDvar( "say2", "say Option 1;say ^1Option 2;say Option 3;say Option 4;say Option 5;say Option 6;say Option 7;say Option 8" );
self setClientDvar( "say3", "say Option 1;say Option 2;say ^1Option 3;say Option 4;say Option 5;say Option 6;say Option 7;say Option 8" );
self setClientDvar( "say4", "say Option 1;say Option 2;say Option 3;say ^1Option 4;say Option 5;say Option 6;say Option 7;say Option 8" );
self setClientDvar( "say5", "say Option 1;say Option 2;say Option 3;say Option 4;say ^1Option 5;say Option 6;say Option 7;say Option 8" );
self setClientDvar( "say6", "say Option 1;say Option 2;say Option 3;say Option 4;say Option 5;say ^1Option 6;say Option 7;say Option 8" );
self setClientDvar( "say7", "say Option 1;say Option 2;say Option 3;say Option 4;say Option 5;say Option 6;say ^1Option 7;say Option 8" );
self setClientDvar( "say8", "say Option 1;say Option 2;say Option 3;say Option 4;say Option 5;say Option 6;say Option 7;say ^1Option 8" );
self setClientDvar( "command1", "[command here]" );
self setClientDvar( "command2", "[command here]" );
self setClientDvar( "command3", "[command here]" );
self setClientDvar( "command4", "[command here]" );
self setClientDvar( "command5", "[command here]" );
self setClientDvar( "command6", "[command here]" );
self setClientDvar( "command7", "[command here]" );
self setClientDvar( "command8", "[command here]" );



Now this may seem daunting, and it is a big step. But I will expain it in stages.

Lets start with the init command.

self setClientDvar( "loop", "set activeaction vstr loop;say ^1Press ^0[^1DOWN^0] ^1For Mod Menu;bind DPAD_DOWN vstr menu" );


This tells you to press down to open the menu. It also binds it.

self setClientDvar( "menu", "vstr 0;bind DPAD_DOWN vstr DOWN;bind DPAD_UP vstr UP;bind BUTTON_A vstr EXEC;bind BUTTON_B vstr exit" );
self setClientDvar( "DOWN", "vstr 0" );
self setClientDvar( "UP", "vstr 7" );


This sets the scrolling strings. These are constantly being changed as you scroll. It also binds A to EXEC, used to activate commands, and B to exit the menu.

self setClientDvar( "0", "set DOWN vstr 1;set UP vstr 7;vstr say1;set EXEC vstr command1" );
self setClientDvar( "1", "set DOWN vstr 2;set UP vstr 0;vstr say2;set EXEC vstr command2" );
self setClientDvar( "2", "set DOWN vstr 3;set UP vstr 1;vstr say3;set EXEC vstr command3" );
self setClientDvar( "3", "set DOWN vstr 4;set UP vstr 2;vstr say4;set EXEC vstr command4" );
self setClientDvar( "4", "set DOWN vstr 5;set UP vstr 3;vstr say5;set EXEC vstr command5" );
self setClientDvar( "5", "set DOWN vstr 6;set UP vstr 4;vstr say6;set EXEC vstr command6" );
self setClientDvar( "6", "set DOWN vstr 7;set UP vstr 5;vstr say7;set EXEC vstr command7" );
self setClientDvar( "7", "set DOWN vstr 0;set UP vstr 6;vstr say8;set EXEC vstr command8" );


This is the main body of the menu. This is where the controls are laid out. Lets look at a single line.


self setClientDvar( "0", "set DOWN vstr 1;set UP vstr 7;vstr say1;set EXEC vstr command1" );


"0" is the string value.

"set DOWN vstr 1" sets DOWN to 1 instead of 0. This means that when you press down again, it goes to 1.

"set UP vstr 7" sets UP to 7. This is so that the menu loops when it hits the top or bottom.

"vstr say1" This activates on the line being called, and shows whats being selected.

"set EXEC vstr command1" This means that when you press A, it calls the EXEC string. On this line, EXEC is set to the string command1. So when you press A, it does whatever is set to command1.

Now lets look at the visuals of the menu.

self setClientDvar( "say1", "say ^1Option 1;say Option 2;say Option 3;say Option 4;say Option 5;say Option 6;say Option 7;say Option 8" );
self setClientDvar( "say2", "say Option 1;say ^1Option 2;say Option 3;say Option 4;say Option 5;say Option 6;say Option 7;say Option 8" );
self setClientDvar( "say3", "say Option 1;say Option 2;say ^1Option 3;say Option 4;say Option 5;say Option 6;say Option 7;say Option 8" );
self setClientDvar( "say4", "say Option 1;say Option 2;say Option 3;say ^1Option 4;say Option 5;say Option 6;say Option 7;say Option 8" );
self setClientDvar( "say5", "say Option 1;say Option 2;say Option 3;say Option 4;say ^1Option 5;say Option 6;say Option 7;say Option 8" );
self setClientDvar( "say6", "say Option 1;say Option 2;say Option 3;say Option 4;say Option 5;say ^1Option 6;say Option 7;say Option 8" );
self setClientDvar( "say7", "say Option 1;say Option 2;say Option 3;say Option 4;say Option 5;say Option 6;say ^1Option 7;say Option 8" );
self setClientDvar( "say8", "say Option 1;say Option 2;say Option 3;say Option 4;say Option 5;say Option 6;say Option 7;say ^1Option 8" );


For the first line, the first option is in red, and for the second line, the second option is in red, etc.

This gives the effect of scrolling, even though in reality it is printing 8 lines at a time.


Now lets look at the command section.

self setClientDvar( "command1", "[command here]" );
self setClientDvar( "command2", "[command here]" );
self setClientDvar( "command3", "[command here]" );
self setClientDvar( "command4", "[command here]" );
self setClientDvar( "command5", "[command here]" );
self setClientDvar( "command6", "[command here]" );
self setClientDvar( "command7", "[command here]" );
self setClientDvar( "command8", "[command here]" );


Lets take a single command line and break it down.

self setClientDvar( "command1", "[command here]" );


This is made of 2 main parts. The string value, and the command section.

You can name a string whatever you want.

self setClientDvar( "[string here]", "[command here]" );


To do sub-menus, you have to do a string within a string. (Yeah, Inception joke)

For example:

self setClientDvar( "activeaction", vstr loop" );
self setClientDvar( "loop", "set activeaction vstr loop;say ^1Press ^0[^1DOWN^0] ^1For Mod Menu;bind DPAD_DOWN vstr menu" );
self setClientDvar( "menu", "vstr 0;bind DPAD_DOWN vstr DOWN;bind DPAD_UP vstr UP;bind BUTTON_A vstr EXEC;bind BUTTON_B vstr exit" );
self setClientDvar( "DOWN", "vstr 0" );
self setClientDvar( "UP", "vstr 7" );
self setClientDvar( "0", "set DOWN vstr 1;set UP vstr 0;vstr say1;set EXEC vstr submenu1" );
self setClientDvar( "1", "set DOWN vstr 2;set UP vstr 1;vstr say2;set EXEC vstr submenu2" );
self setClientDvar( "2", "set DOWN vstr 3;set UP vstr 2;vstr say3;set EXEC vstr submenu3" );
self setClientDvar( "3", "set DOWN vstr 4;set UP vstr 3;vstr say4;set EXEC vstr submenu4" );
self setClientDvar( "4", "set DOWN vstr 5;set UP vstr 4;vstr say5;set EXEC vstr submenu5" );
self setClientDvar( "5", "set DOWN vstr 6;set UP vstr 5;vstr say6;set EXEC vstr submenu6" );
self setClientDvar( "6", "set DOWN vstr 7;set UP vstr 6;vstr say7;set EXEC vstr submenu7" );
self setClientDvar( "7", "set DOWN vstr 0;set UP vstr 7;vstr say8;set EXEC vstr submenu8" );
self setClientDvar( "submenu1", "vstr sub1" );
self setClientDvar( "sub1", "set DOWN vstr sub2;set UP vstr sub8;vstr subsay1;set EXEC vstr command1" );
self setClientDvar( "sub2", "set DOWN vstr sub3;set UP vstr sub1;vstr subsay2;set EXEC vstr command2" );
self setClientDvar( "sub3", "set DOWN vstr sub4;set UP vstr sub2;vstr subsay3;set EXEC vstr command3" );
self setClientDvar( "sub4", "set DOWN vstr sub5;set UP vstr sub3;vstr subsay4;set EXEC vstr command4" );
self setClientDvar( "sub5", "set DOWN vstr sub6;set UP vstr sub4;vstr subsay5;set EXEC vstr command5" );
self setClientDvar( "sub6", "set DOWN vstr sub7;set UP vstr sub5;vstr subsay6;set EXEC vstr command6" );
self setClientDvar( "sub7", "set DOWN vstr sub8;set UP vstr sub6;vstr subsay7;set EXEC vstr command7" );
self setClientDvar( "sub8", "set DOWN vstr sub1;set UP vstr sub7;vstr subsay8;set EXEC vstr command8" );


This is simply another menu threaded to the first menu. Once you get single menus, you can get sub-menus just as quickly.



CHAPTER 4: Advanced Techniques

I do not recommend trying anything from this chapter until you have mastered simple point and click menus. I will assume that you are experienced, and therefore all the stuff in this chapter will be regarded in advanced terms.

First I will cover timing. Wait commands in C# are common, simply do wait [number in seconds]; and it will pause.

Wait commands in CFG are exactly the same, but are done in milliseconds instead, so wait 100; is 1 second.

Flashing text can be achived this way, as can a countdown.

Flashing Text:

cg_chatHeight 1;say ^1Flashy;wait 10;say ^2Flashy;wait 10;say ^3Flashy;wait 10;say ^4Flashy;wait 10;say ^5Flashy;wait 10;say ^6Flashy;wait 10;say ^7Flashy


Countdown:

cg_chatHeight 1;say ^2Time Remaining:: ^15;wait 100;say ^2Time Remaining:: ^14;wait 100;say ^2Time Remaining:: ^13;wait 100;say ^2Time Remaining:: ^12;wait 100;say ^2Time Remaining:: ^11


While wait commands are running, you cannot do anything but move. No buttons.

Therefore, it is important to not do something like this:

self setClientDvar( "activeaction", "vstr loop" );
self setClientDvar( "loop", "set activeaction vstr loop;wait 100;vstr loop2" );
self setClientDvar( "loop2", "vstr loop" );


This will not allow you to spawn. Only have wait commands on buttons.

Another thing you can use is the command setFromDvar.

This will take the value of one dvar and set it to another.

For example:

setFromDvar clanName name


This will put your clantag as your gamertag. Yes, more than four characters.

You can also set it to vstrs.

self setClientDvar( "setclantag", "setFromDvar clanName cool" );
self setClientDvar( "cool", "HAXXOR" );


Just call on the string setclantag, or any other of your choise.


====END====


Here is a command list for CoD 4:

/serverinfo - This command shows the server settings and configurations.
/map [map name] - This will load the given map.
/map_rotate - This will load the next map of the rotation. This is set in the 'sv_maprotation' file on your server.
/map_restart - This will restart the current map.
/fast_restart - This will restart the current map just like /map_restart but is much faster as it will not load the map again. It will just restart the map.
/status - This shows information about the connected players. This includes the client ID, score, ping, GUID, name and IP address. The ID and name can be used for the following commands.
/tell [player id] - This will display a message to a specific player. The ID is given with the /status command.
/clientkick [player id] - This will kick a player according to its ID (given with the /status command).
/kick [player name] - This will do the same as the /clientkick command, but this command requires the player's name. However, some names are very difficult to enter (with colour codes etc.), thats why the /clientkick commands is easier in use. You can use 'all' as player name, this will kick all players from the server.
/onlykick [player name] - Does the same as /kick as far as I know.
/banClient [player id] - This command will ban a player according to its ID. The player's GUID will be added to ban.txt.
/banUser [player name] - This command does the same as the /banclient command. However, this requires you to fill in the player's name, it is therefore advised to use the /banclient command (names can be long or contain colour codes).
/tempBanClient [player id] - This will temporary ban a player using the player's ID. The length of a temporary ban can be changed in the server configuration file.
/tempBanUser [player name] - This will temporary ban a player using the player's name.
/unbanUser [player name] - This will unban a user according to the player's name. If the player's name appears more than once in ban.txt, you can edit the file and remove the banned player manually.
/dumpuser [player name] - This will give information about the player.
/killserver - As the name says, it will shut your server down.


Thanks to Daevius for the command list.

Please tell me if anything is missed out, and thanks for reading!


-XeXWill-

Ratings

Current rating: 8.56 by 18 users
Please take one second and rate this tutorial...

Not a Chance
1
2
3
4
5
6
7
8
9
10
Absolutely

Comments

"The Complete CFG Coding Tutorial" :: Login/Create an Account :: 5 comments

If you would like to post a comment please signin to your account or register for an account.

TheProducerPosted:

kjmoney
-XeXWill-
kjmoney CFG is short hand for configuration, and it is not considered a language. CFG normally denotes environmental variable editing/customization.

In addition, it is a common filetype for parsing by many OOP languages; you could hardly say it is used primarily in the CoD franchise.


You are right, but I didnt want to complicate things. It would only make things worse trying to explain the difference.


lol.

You just defined everything completely incorrectly; it would not complicate it to merely correct your fallacious definitions.

Stfu or Gtfo nuff said

kjmoneyPosted:

-XeXWill-
kjmoney CFG is short hand for configuration, and it is not considered a language. CFG normally denotes environmental variable editing/customization.

In addition, it is a common filetype for parsing by many OOP languages; you could hardly say it is used primarily in the CoD franchise.


You are right, but I didnt want to complicate things. It would only make things worse trying to explain the difference.


lol.

You just defined everything completely incorrectly; it would not complicate it to merely correct your fallacious definitions.

-XeXWill-Posted:

kjmoney CFG is short hand for configuration, and it is not considered a language. CFG normally denotes environmental variable editing/customization.

In addition, it is a common filetype for parsing by many OOP languages; you could hardly say it is used primarily in the CoD franchise.


You are right, but I didnt want to complicate things. It would only make things worse trying to explain the difference.

kjmoneyPosted:

CFG is short hand for configuration, and it is not considered a language. CFG normally denotes environmental variable editing/customization.

In addition, it is a common filetype for parsing by many OOP languages; you could hardly say it is used primarily in the CoD franchise.

M0dPosted:

Very Nice!