Skip to Content
Modlock

Console

Set console variables and run commands, within limits.

The modlock/console module sets the game's console variables and runs its console commands. The setter for each variable takes the type the game declares for it.

import { run, set } from 'modlock/console'

set('citadel_allow_purchasing_anywhere', true)
set('citadel_trooper_gold_reward', 40)
run('changelevel', 'street_test')
local console = require("@modlock/console")

console.setBoolean("citadel_allow_purchasing_anywhere", true)
console.setNumber("citadel_trooper_gold_reward", 40)
console.run("changelevel", "street_test")
from modlock import console

console.set_boolean("citadel_allow_purchasing_anywhere", True)
console.set_number("citadel_trooper_gold_reward", 40)
console.run("changelevel", "street_test")
import "github.com/paralin/modlock/mod/console"

_ = console.CitadelAllowPurchasingAnywhere.Set(true)
_ = console.CitadelTrooperGoldReward.Set(40)
_ = console.Changelevel.Run("street_test")

Every call runs one console line through serverCommand, which can also set a development-only or cheat-protected variable. A variable whose value is a vector or a color has no typed setter, so set it with serverCommand yourself.

Set up a mode

apply(settings) sets several variables in order and returns the names the server refused. For a custom mode, start from arena, which empties the map. The server keeps running with no one connected, and no troopers, neutrals, practice bots or zipline starts appear. Spread it and add your mode's own settings:

import { apply, arena } from 'modlock/console'

apply({ ...arena, citadel_allow_duplicate_heroes: true })
local console = require("@modlock/console")

-- When two tables set the same variable, the later table's value wins.
console.apply(console.arena, { citadel_allow_duplicate_heroes = true })
from modlock import console

console.apply({**console.ARENA, "citadel_allow_duplicate_heroes": True})
import "github.com/paralin/modlock/mod/console"

// Arena returns its settings as a slice, and To makes a setting of your own.
console.Apply(append(console.Arena(), console.CitadelAllowDuplicateHeroes.To(true))...)

Limits

Your mod's console lines can change the game, but nothing outside it. They may set the game's rules and bots, change or reload the map, kick a player, quit and set the time scale. They may also start the game's own recording with tv_enable and tv_record <name>, where the name contains only letters, digits, - and _. They may not reach:

AreaRefused
Filesexec and its kin, saves, demo playback, config and path variables, and file-writing commands such as condump or writeip
Logginglog, log_*, con_log*, sv_log*, and console redirection
The networkconnect, rcon*, addresses and ports, IP bans, passwords, Steam account and group settings, and broadcast, relay and playcast tv_* settings
The processCrash and minidump commands, debuggers, tools, and shutdown
Lines stored to run lateralias, cmd, bind*, unbind*, execute_command_every_frame, and the test script's test_* commands, which run the commands they take
Entitiesent_create, ent_fire*, ent_call, firetarget, and give for a class createEntity refuses
The script VMscript_*

toggle, incrementvar and multvar set the variable they take, so the server refuses each of them for a variable your mod may not set directly. The server checks every command in a line, after each ; or newline. When it refuses one, the error gives the first command it refused.

On this page