S&box Wiki

Commands

Commands are easy to create and can be called from the console, they are mainly useful for administrative and debugging purposes.

Alternatively RPCs can be used to transmit data between the host and clients with less restrictions then commands.

Creating commands

Commands can be created on any static method by applying the method attribute [ConCmd]

[ConCmd( "test_command" )] public static void TestCommand( string input ) { Log.Info( input ); }

Parameter Types

There is limited support for parameter types as they all need to be converted to a string and back - if you find this too limiting you should probably use RPCs instead.

The following types are allowed: float, double, int, unit, bool, string, long, ulong, Vector2, Vector3, Vector4, Angles, Color, RangedFloat, Rotation.

Types can also be allowed if it satisfies one of the following conditions:

  • It is an enum.
  • Your type has an implicit converter.
  • Your type has a constructor with a single string parameter.

Running commands

Obviously commands can be run directly from the console by name, but they can also be run via ConsoleSystem.Run

protected override void OnStart() { ConsoleSystem.Run( "test_command", "hi!" ); }
You can not call engine console commands with ConsoleSystem.Run - you can only call commands added by the game itself.