console.Command
Object → console.Command
The console command object.
Constructor
console.Command(options: console.CommandOptions): console.CommandFields
| Name | Type | Description |
|---|---|---|
name | string | The name of the command. |
description | string | The description of the command. |
flags | integer | The flags of the command. |
autocomplete | console.Command.AutoComplete | nil | The auto-complete function of the command. |
unregistered | boolean? | If this is set, don't add to linked list, etc. READ-ONLY |
development_only | boolean? | Hidden in released products.
Flag is removed automatically if ALLOW_DEVELOPMENT_CVARS is defined in C++.
READ-ONLY |
game_dll | boolean? | Defined by the game DLL. READ-ONLY |
client_dll | boolean? | Defined by the client DLL. READ-ONLY |
protected | boolean? | It's a server cvar, but we don't send the data since it's a password, etc.
Sends 1 if it's not blank/zero, 0 otherwise as value.
Garry's Mod never calls cvars.OnConVarChanged for protected variables, so
console.Variable keeps the first value it read and never emits "change".
READ-ONLY |
sponly | boolean? | This cvar cannot be changed by clients connected to a multiplayer server. READ-ONLY |
archive | boolean? | Save the cvar value into either client.vdf or server.vdf.
READ-ONLY |
notify | boolean? | For server-side cvars, notifies all players with blue chat text when the value gets changed, also makes the convar appear in A2S_RULES. READ-ONLY |
userinfo | boolean? | For client-side commands, sends the value to the server. READ-ONLY |
cheat | boolean? | In multiplayer, prevents this command/variable from being used unless the server has sv_cheats turned on.
If a client connects to a server where cheats are disabled (which is the default), all client side console variables labeled as cheat are reverted to their default values and can't be changed as long as the client stays connected.
Console commands marked as cheat can't be executed either.
As a general rule of thumb, any client-side command that isn't specifically meant to be configured by users should be marked with this flag, as even the most harmless looking commands can sometimes be misused to cheat.
For server-side only commands you can be more lenient, since these would have no effect when changed by connected clients anyway.
READ-ONLY |
printable_only | boolean? | This cvar's string cannot contain unprintable characters ( e.g., used for player name etc ). READ-ONLY |
unlogged | boolean? | If this is a server-side, don't log changes to the log file / console if we are creating a log. READ-ONLY |
never_as_string | boolean? | Tells the engine to never print this console variable as a string. This is used for variables which may contain control characters. READ-ONLY |
replicated | boolean? | When set on a console variable, all connected clients will be forced to match the server-side value. This should be used for shared code where it's important that both sides run the exact same path using the same data. (e.g. predicted movement/weapons, game rules) READ-ONLY |
demo | boolean? | When starting to record a demo file, explicitly adds the value of this console variable to the recording to ensure a correct playback. READ-ONLY |
dont_record | boolean? | Opposite of demo, ensures the cvar is not recorded in demos.
READ-ONLY |
reload_materials | boolean? | If set and this variable changes, it forces a material reload. READ-ONLY |
reload_textures | boolean? | If set and this variable changes, it forces a texture reload. READ-ONLY |
not_connected | boolean? | Prevents this variable from being changed while the client is currently in a server, due to the possibility of exploitation of the command (e.g. fps_max).
READ-ONLY |
material_system_thread | boolean? | Indicates this cvar is read from the material system thread. READ-ONLY |
archive_xbox | boolean? | Like archive, but for Xbox 360.
Needless to say, this is not particularly useful to most modders.
Save the cvar value into config.vdf on XBox.
READ-ONLY |
accessible_from_threads | boolean? | Used as a debugging tool necessary to check material system thread convars. READ-ONLY |
server_can_execute | boolean? | The server is allowed to execute this command on clients via ClientCommand/NET_StringCmd/CBaseClientState::ProcessStringCmd.
READ-ONLY |
server_cannot_query | boolean? | If this is set, then the server is not allowed to query this cvar's value (via IServerPluginHelpers::StartQueryCvarValue).
READ-ONLY |
clientcmd_can_execute | boolean? | IVEngineClient::ClientCmd is allowed to execute this command.
READ-ONLY |
material_thread_mask | boolean? | Summary of reload_materials, reload_textures and material_system_thread.
READ-ONLY |
lua_client | boolean? | Sets automatically on all cvars and console commands created by the client Lua state.
READ-ONLY |
lua_server | boolean? | Sets automatically on all cvars and console commands created by the server Lua state.
READ-ONLY |
Static functions
get | Returns the console command with the given name. |
isBlacklisted | Checks if the console command is blacklisted. |
translateAlias | Translates a console command alias, basically reverse of the alias console command. |
#console.Command.get
function console.Command.get(name: any): console.Command | nil
Returns the console command with the given name.
Parameters
| Name | Type | Description |
|---|---|---|
name | any |
Returns
| Type | Name | Description |
|---|---|---|
console.Command | nil | obj | The console command with the given name, or nil if it does not exist. |
#console.Command.isBlacklisted
function console.Command.isBlacklisted(name: string): boolean
Checks if the console command is blacklisted.
Parameters
| Name | Type | Description |
|---|---|---|
name | string | The name of the console command. |
Returns
| Type | Name | Description |
|---|---|---|
boolean | is_blacklisted | true if the console command is blacklisted, false otherwise. |
#console.Command.translateAlias
function console.Command.translateAlias(str: string): string | nil
Translates a console command alias, basically reverse of the alias console command.
Parameters
| Name | Type | Description |
|---|---|---|
str | string | The alias to lookup. |
Returns
| Type | Name | Description |
|---|---|---|
string | nil | cmd | The command(s) this alias will execute if ran, or nil if the alias doesn't exist. |
Methods
attach | Attaches a handler called on every execution of the command, attaching the same handler twice is a no-op. |
await | Waits for the console command to be executed. |
clear | Removes every handler of the command, pending handlers of a running execution are skipped. |
detach | Detaches a handler previously passed to attach or once. |
isBlacklisted | Returns whether the console command is blacklisted. |
once | Attaches a one-shot handler, detached right before the next execution calls it. |
run | Runs the console command. |
#Command:attach
function console.Command:attach(handler: console.Command.Callback | Hook | Event)
Attaches a handler called on every execution of the command, attaching the same handler twice is a no-op.
Handlers run in protected mode, one failing handler is reported and never stops the others.
Parameters
| Name | Type | Description |
|---|---|---|
handler | console.Command.Callback | Hook | Event | The callback or callable object. |
#Command:await
async function console.Command:await(): console.Command, garrysmod.Player | nil, string[], string
Waits for the console command to be executed.
Returns
| Type | Name | Description |
|---|---|---|
console.Command | command | |
garrysmod.Player | nil | client | |
string[] | args | |
string | argument_string |
#Command:clear
function console.Command:clear()
Removes every handler of the command, pending handlers of a running execution are skipped.
#Command:detach
function console.Command:detach(handler: console.Command.Callback | Hook | Event): boolean
Detaches a handler previously passed to attach or once.
Parameters
| Name | Type | Description |
|---|---|---|
handler | console.Command.Callback | Hook | Event | The exact handler reference. |
Returns
| Type | Name | Description |
|---|---|---|
boolean | removed | true if the handler was attached. |
#Command:isBlacklisted
function console.Command:isBlacklisted(): boolean
Returns whether the console command is blacklisted.
Returns
| Type | Name | Description |
|---|---|---|
boolean | is_blacklisted | true if the console command is blacklisted, false otherwise. |
#Command:once
function console.Command:once(handler: console.Command.Callback | Hook | Event)
Attaches a one-shot handler, detached right before the next execution calls it.
Parameters
| Name | Type | Description |
|---|---|---|
handler | console.Command.Callback | Hook | Event | The callback or callable object. |
#Command:run
function console.Command:run(...: string)
Runs the console command.
Parameters
| Name | Type | Description |
|---|---|---|
... | string | The arguments to pass to the console command. |