Difference between revisions of "How to make a script"

From Fortress Forever Wiki
Jump to navigationJump to search
(Category:0-Star_Articles)
(Note image implemented.)
Line 229: Line 229:
 
;d_9;d_0"
 
;d_9;d_0"
 
bind f "default"</pre></code>
 
bind f "default"</pre></code>
<small>NOTE: In this script we have aliased several things: d_2, d_3, d_4, d_5, d_6, d_7, d_8, d_9, d_0, and default. We then use a [[How_to_make_a_script#What_is_a_bind.|bind]] to link them all together.</small>
+
<small>[[Image:Note.png]]''' NOTE:''' In this script we have aliased several things: d_2, d_3, d_4, d_5, d_6, d_7, d_8, d_9, d_0, and default. We then use a [[How_to_make_a_script#What_is_a_bind.|bind]] to link them all together.</small>

Revision as of 15:16, 13 February 2008


Overview

What is a bind?

A bind in Fortress Forever is a command, or sting or commands, which when executed perform a desired action.

What is a config?

A config in Fortress Forever is a file that contains a series of binds. When the config is executed, it consults the binds to see what parameters are in effect.

Where are binds stored?

Binds are stored in your default config files.

The game stores all of your config files in the following file:
\Steam\steamapps\SourceMods\FortressForever\cfg

You can view a copy of the default config files by looking at the Default Configs Section of this wiki.

By default the game contains 12 config files. These are generally catagorized into two groups.

Default Config Files

Class Specific Config File

The class specific config files are executed every time you respawn. You will want to keep that in mind when considering what to put in your class specific configs.

Syntax

For any key binding or alias binding script within the Source engine developer console, the following format must be followed:

COMMAND <argument1> <argument2>

Quotation marks are NOT necessary for binds or aliases with singular arguments, such as bind 1 slot1.

Getting Started

What programs do I need?

You can use any text editing program to create a bind. However depending on he difficulty of the bind you are going to be creating you may want to look at getting an external program.

Simple binds:

When writing a simple bind there are no specific programs that are needed. It is suggested that you use notepad but your favorite text editing program will work.

Advanced binds:

For more advanced scripting it is suggested that you use either notepad or notepad++.

Key configurations

When writing binds, it is important that you use the correct key configurations. For example if we want to have the melee weapon of a class be activated by pressing the control key. We would have to write a bind that looks like this:

bind CTRL slot1

In this senario we have to use “CTRL” to define the control key.

For a complete list of each key and how it is defined see the script reference page.

Are there any commands I cannot use?

Yes, although you have a lot of access to commands. It would be unfair and potentially dangerous for the developers to allow access to every command in the game. For more information on this please visit the commands and cvars section.

Basic Scripting

Writing a simple bind

A simple bind takes the form of:

bind <key> <command>

For example if we wanted to have the melee weapon of a class be activated by pressing the 1 key, then we could write a bind that looks like this:

bind 1 slot1

“slot1” is the command to activate the melee weapon by default

Each bind you write must be written on a separate line. For example if we wanted to have the melee weapon of a class be acticated by pressing the 1 key and have the secondary weapon of a class be active by pressing the 2 key. We could write a bind that looks like this:

bind 1 slot1
bind 2 slot2

“slot1” is the command to activate the melee weapon and “slot2” is the command to active the secondary weapon by default

Once we have created a simple bind we will need to place it in a config file. This will ensure that the bind is executed while in game.

Example of a simple bind

An example of simple binds can be found here.

Idea: I want to be able to press the "g" key to change to my crowbar as a scout.

Solution using a simple bind: In this example we would want to use a bind to change our weapon to the crowbar.

bind g slot1

g is our key and slot1 is the command to change to the crowbar.

Binds that have parameters

Some commands take arguments when used in the console. For example:

name WhenFFwillout

This command changes your name to the default moniker of Fortress Forever.

If you wish to bind a command that takes a parameter, you must use quotes around the command and argument part of the bind. For example:

bind k "say_team I've got the flag!"

This will send that message to all members of your team.

Another usage:

bind KP_ENTER "detpack 15"

This is a bind to the command to place a 15 second detpack, when playing as the Demoman.

Creating a simple config file

To create a simple config file we will first need to write a simple bind. The next step is to determine whether or not our simple bind will be used by all classes or by a single class. And finally we need to place this bind into a config file to ensure that the bind is executed while in game.


For this, we will use the example above. In this example we are using a simple bind that would be used by all classes. Binds that are used by all classes should be placed into our userconfig.cfg file.


So we have a simple bind, and we know that it is going to be used by all classes. The next stop is to place this bind into a config file.


To do this we must first open our config file. We can do this by navigating our way to the appropiate config file. Again in this example we will be using our userconfig.cfg which is located at the following destination:

steam/steamapps/FortressForever/cfg/userconfig.cfg

For an example of what a default userconfig.cfg looks like see the default configs section of this wiki.


Once we have our config file open we need to place our bind into the file. This is just a matter of copying and pasting the text into the file. Using our example from above our new userconfig.cfg should look like this:

echo User Config Loaded

//Place binds that will be used by all classes here
bind g slot1

We can place as many binds in our configs as we want, just remeber not to attempt to bind 2 keys to the same thing.


Once we have placed the desired binds into our config we will need to save the document. This can be done by either clicking save or going to file/save.


Finally we will need to test our new bind. This can only be done in-game, so we will need to get into FortressForever. Once we are in the game (and have joined a server) we can test out our new bind by pressing the desired key. Again using the example above, if we press "g" our character should change weapons to our melee weapon.

Advanced Scripting

For advanced scripting you will need to have some basic knowledge of scripting to begin. If you are new to scripting you may want to review the basic scripting section first. You may also want to consider getting a better text editing program. However, as with basic scripting, any text editor will suffice.


What makes it advanced?

Advanced Scripting generally consists of nothing more then a series of basic scripts combined into one config file.

However as you begin scripting more you will need to use more complex commands and parameters. To begin we will outline these new parameters.

New Commands and Parameters

Below you will find a list of the most commonly used parameters and a brief description of each and how it is used.

This list is by no means meant to be a list of the only commands you can use.

Command Parameter Description
Alias Alias <alias name> "command" Alias a command. An example can be found below.
bind bind <key> "command" binds a key to preform a desired action
bindtoggle bindtoggle <key> "command" binds a key to toggle a specific command
wait Stop command parsing until next frame. One wait command is equal to .01 seconds.
+ (plus) + <command / alias> Alone it does nothing. However when used in conjunction with a command / alias, the "+" tells the game to only activate the bind while the specified button is being pressed.
- (minus) - <command / alias> Alone it does nothing. However when used in conjunction with a command / alias, the "-" tells the game to de-activate once the specified button has been released.
; The ; is used in advanced binds / scripts to link serveral commands together into one bind.

Example of an alias

  • Alias - An alias is used in conjunction with a bind. We can think of an alias like making a new command with whatever parameters we want. Remeber we must still call upon the alias within a bind for the game to recognize the alias and preform the desired command. When creating an alias the name can be anything we want, however we need to make sure that we have not already aliased that name in another script / config. The simplest way to do this is to use the find command in the console. Not all situations will require an alias, however if we are making a large script / bind we may want consider using alias' to make things simpler. In the example below we will be aliasing several commands. We will then call on the commands with a bind. Feel free to test the example in game to see it in action!
alias d_1 "bind 1 slot1"
alias d_2 "bind 2 slot2"
alias d_3 "bind 3 slot3"
alias d_4 "bind 4 slot4"
alias d_5 "bind 5 slot5"
alias d_6 "bind 6 slot6"
alias d_7 "bind 7 slot7"
alias d_8 "bind 8 slot8"
alias d_9 "bind 9 slot9"
alias d_0 "bind 0 slot0"
alias default "d_1;d_2;d_3;d_4;d_5;d_6;d_7;d_8
;d_9;d_0"
bind f "default"

File:Note.png NOTE: In this script we have aliased several things: d_2, d_3, d_4, d_5, d_6, d_7, d_8, d_9, d_0, and default. We then use a bind to link them all together.