Skip to content

Server script commands

Noah Metzger edited this page Sep 9, 2020 · 3 revisions

The following console commands are supported in cMod to extend the capabilities of server config scripts.

These commands should remain supported in future versions of cMod, unless specifically marked as "experimental". If it becomes necessary to make changes to non-experimental commands in a way that may break existing scripts, the changes will be documented on this page.

Special Arguments

Many of the commands on this page support the following special arguments, which can be used in place of standard text arguments.

  • *{cvar-name}: Refers to the contents of the cvar {cvar-name}.
  • **{cvar-name}: Refers to the contents of the cvar named by the cvar {cvar-name}.
  • &none: Equivalent to "" (empty string), but suitable for when quotes are syntactically unavailable.
  • &space: Equivalent to " ", but suitable for when quotes are syntactically unavailable.
  • &semi: Equivalent to ";", but suitable for when quotes are syntactically unavailable.
  • &asterisk: Equivalent to "*", but avoids conflict with cvar operators above.

These operations may not make sense by themselves, but they are important for the functionality of other commands below.

If command

The "if" command provides basic support for conditional operations. It uses the following syntax:

if <argument> <comparator> <argument> <command ...>

The trailing command will be executed if the two arguments meet the comparator criteria. The following comparison conditions are supported:

  • s=, s!=: String comparison. s= evaluates to true and executes the command if both arguments are the same strings. s!= executes the command if the arguments are different strings. This comparison is not case sensitive.
  • e=, e!=: Case-sensitive 'exact' string comparison. Same as above, but case sensitive.
  • i=, i!=, i<, i<=, i>, i>=: Executes command if the integer comparison is satisfied.
  • f=, f!=, f<, f<=, f>, f>=: Executes command if the floating point comparison is satisfied.
  • b=, b!=: Boolean comparison. b= executes the command if both arguments have the same boolean state, and b!= executes the command if arguments have different boolean states. Arguments such as "true", "yes", "1", "2", and "-1" are treated as equivalent states, and "false", "no", and "0" are treated as the opposite state.

For the if command to be useful, you typically need to use the special argument syntax and include a * when referencing a cvar value. Arguments without the * are treated as constants. Example:

set is_ctf false
if *g_gametype i= 4 set is_ctf true
if *is_ctf b= true set g_speed 300

Due to technicalities of the Quake command interpreter, I recommend avoiding the use of quotes in any part of an if command, as it can lead to confusing and unexpected behavior. Fortunately there are easy workarounds in cases you might want to do this. Examples:

// Instead of this:
if *g_gametype i= 4 "vstr team_cfg ; vstr ctf_cfg"

// Do this:
set temp "vstr team_cfg ; vstr ctf_cfg"
if *g_gametype i= 4 vstr temp

// Instead of this:
if *g_pModInstagib b= true set sv_hostname " Server Name with Extra  Spaces!!"

// Do this:
set temp " Server Name with Extra  Spaces!!"
if *g_pModInstagib b= true setop sv_hostname copy *temp

Setop command

The "setop" command, which stands for "set operation", sets the value of a cvar based on the result of certain engine-defined commands. The general syntax is as follows:

setop <target cvar> <command> <arguments...>

The number and type of supported arguments vary depending on the command. The following is a list of currently supported commands.

command arguments description
copy <string> Copies string without modification.
join <separator> <str1> <...> Concatenates strings, inserting separator between non-empty arguments.
replace <string> <search1> <replace1> <...> Copies string, replacing instances of search term(s) with replace term(s).
str_contains_str <string> <search_term> Returns boolean indicating if given string contains substring. Case insensitive.
str_contains_term <string> <search_term> <delimiter> Returns boolean indicating if string contains given term.
Delimiter optional (defaults to &space). Case insensitive.
token_at <string> <index> <delimiter> Returns token at specified index (0=first, -1=last).
Delimiter optional (defaults to &space).
tokens_from <string> <index> <delimiter> Returns all tokens starting at and including index (0=first, -1=last).
Delimiter optional (defaults to &space).
tokens_until <string> <index> <delimiter> Returns all tokens up to but excluding index (0=first, -1=last).
Delimiter optional (defaults to &space).
char_at <string> <index> Returns character at specified index (0=first, -1=last).
chars_from <string> <index> Returns characters starting at and including index (0=first, -1=last).
chars_until <string> <index> Returns characters up to but excluding index (0=first, -1=last).
add <arg1> <arg2> <...> Adds two (or more) numeric values.
subtract <arg1> <arg2> Subtracts arg2 from arg1.
multiply <arg1> <arg2> Multiplies arg1 and arg2.
divide <arg1> <arg2> Divides arg1 by arg2.
rand <min_value> <max_value> Returns a random integer value in the range from min to max, inclusive.
randf <min_value> <max_value> Returns a random floating point value in the range from min to max.
file_exists <path> Returns boolean indicating if specified file exists in the virtual filesystem.

Examples:

// Copy example
set test1 "Some Value"
setop test2 copy *test1
test2    // "Some Value"

// Join example
// Notice that quoted value is treated as single argument containing spaces
set test1 "value1"
setop test2 join &semi *test1 "quoted value" value2
test2    // "value1;quoted value;value2"

// Replace example
set test1 "abcdefghi"
setop test2 replace *test1 def jkl
test2    // "abcjklghi"

// Add example
set counter 1
setop counter add *counter 1
counter    // 2

// Random map example
set m1 "map hm_voy1"
set m2 "map hm_dn1"
set m3 "map hm_cam"
set m_template "vstr m{num}"
set m_getnum "setop m_num rand 1 3"
set m_getcmd "setop m_cmd replace *m_template {num} *m_num"
set nextmap "vstr m_getnum ; vstr m_getcmd ; vstr m_cmd"

Cvar commands

The following commands are added to support setting cvars with certain flags:

  • setn: Sets a norestart cvar which is not reset by cvar_restart. Can be used to store persistant data for server configs that call cvar_restart during map changes or other reset events.

  • setr: Sets a read-only cvar, which is not reset by cvar_restart, and also cannot be modified by future set and setr commands. Can be useful to prevent bugs if you know a certain cvar is not meant to change.

Both commands have the same syntax as set and currently require that you specify a value at the time they are run. These commands can also be used in command line arguments when starting the server.

Clone this wiki locally