menu_bookDocumentation

ConVar and ConCmd: Console Variables and Commands in s&box

calendar_today May 4, 2026 schedule ~1 min read person patrickjr verified 50

ConVar and ConCmd: Console Variables and Commands

s&box uses [ConVar] and [ConCmd] attributes on static properties and methods to expose them to the console system.

ConVar (Console Variable)

CSHARP
// Basic ConVar
[ConVar( "my_speed" )]
public static float MySpeed { get; set; } = 300f;

// With flags and help text
[ConVar( "my_debug", ConVarFlags.Protected, Help = "Enable debug mode" )]
public static bool DebugMode { get; set; } = false;

// Saved to config file
[ConVar( "my_volume", ConVarFlags.Saved )]
public static float Volume { get; set; } = 1.0f;

// With min/max clamping
[ConVar( "my_fov", Min = 60f, Max = 120f )]
public static float FieldOfView { get; set; } = 90f;

ConCmd (Console Command)

CSHARP
// Basic command
[ConCmd( "my_command" )]
public static void MyCommand( string arg1, int arg2 = 0 )
{
    Log.Info( $"Called with {arg1}, {arg2}" );
}

// Admin-only command
[ConCmd( "kick_player", ConVarFlags.Admin )]
public static void KickPlayer( string name )
{
    // Only runs if caller is host
}

// Access the caller connection
[ConCmd( "my_cmd" )]
public static void MyCmd( Connection caller, string arg )
{
    // First parameter of type Connection receives the caller
    Log.Info( $"{caller.DisplayName} called with {arg}" );
}

ConVarFlags

FlagEffect
ProtectedCannot be changed by game code
SavedPersisted to config file via CookieContainer
ReplicatedServer value is replicated to clients
UserInfoClient value is sent to server (accessible via Connection userinfo)
CheatRequires sv_cheats 1
AdminOnly host can run
HiddenNot visible in autocomplete
ServerOnly runs on server

Name Validation

ConVar/ConCmd names must contain only ASCII letters, digits, underscores, dots, or hyphens. Spaces, semicolons, and quotes are not allowed.

Was this helpful?