Skip to main content

Console Commands & ConVars

Namespace: DeadworksManaged.Api

ConCommandAttribute

Marks a method as a console command handler. The method must have signature void Handler(ConCommandContext ctx).

[ConCommand("dw_killme")]
public void OnKillMe(ConCommandContext ctx)
{
var pawn = ctx.Controller?.GetHeroPawn();
if (pawn == null) return;

pawn.Hurt(99999, pawn, pawn, pawn);
}

ConCommandContext

Context passed to [ConCommand] handlers.

PropertyTypeDescription
CallerSlotintPlayer slot of the caller, or -1 if invoked from server console
CommandstringThe command name that was typed (args[0])
Argsstring[]All arguments including the command name at index 0
ArgStringstringThe argument string after the command name. Empty if no args
IsServerCommandbooltrue when invoked from server console (no player)
ControllerCCitadelPlayerController?The player controller, or null if invoked from server console

ConVarAttribute

Marks a property as a console variable. Supports int, float, bool, and string types.

Typing the name in console prints the current value; typing with an argument sets it.

[ConVar("my_plugin_enabled")]
public bool Enabled { get; set; } = true;

[ConVar("my_plugin_damage")]
public float DamageMultiplier { get; set; } = 1.0f;

ConVar Class

Programmatic access to Source 2 console variables.

Static Methods

MethodReturnsDescription
Find(string name)ConVar?Looks up an existing ConVar by name. Verified working
Create(string name, string defaultValue, string description, bool notify)ConVar?Creates and registers a new ConVar. Currently returns null — use [ConVar] attribute instead

Instance Methods

MethodDescription
SetInt(int value)Sets the cvar's value as an integer
SetFloat(float value)Sets the cvar's value as a float

Example: Modifying Game Settings

public override void OnStartupServer()
{
// Modify existing game convars
ConVar.Find("citadel_trooper_spawn_enabled")?.SetInt(0);
ConVar.Find("citadel_npc_spawn_enabled")?.SetInt(0);
ConVar.Find("citadel_allow_duplicate_heroes")?.SetInt(1);
ConVar.Find("citadel_player_starting_gold")?.SetInt(0);
ConVar.Find("citadel_voice_all_talk")?.SetInt(1);
}

Server.ClientCommand

Send a console command to a specific client:

Server.ClientCommand(playerSlot, "echo Hello from the server!");
ParameterTypeDescription
slotintThe player slot to send the command to
commandstringThe console command string (e.g. "echo hello", "playgamesound ...")

Blocking Client Commands

Use the OnClientConCommand hook to intercept and block specific client console commands. This is useful for preventing players from performing certain actions.

Known Client Commands

CommandDescription
selectheroPlayer selects/changes hero
citadel_hero_pickHero pick during selection
sellitemPlayer sells an item. Args: [sellitem, <ability_name>]

Blocking Item Sales

Prevent players from selling specific items by checking the sellitem command and its arguments:

private static readonly HashSet<string> _blockedItems = new(StringComparer.OrdinalIgnoreCase) {
"upgrade_critshot",
"upgrade_unstable_concoction",
};

public override HookResult OnClientConCommand(ClientConCommandEvent e)
{
// Block selling specific items
if (e.Command == "sellitem" && e.Args.Length >= 2 && _blockedItems.Contains(e.Args[1]))
return HookResult.Stop;

return HookResult.Continue;
}

Blocking Hero Changes Outside Spawn

public override HookResult OnClientConCommand(ClientConCommandEvent e)
{
if (e.Command == "selecthero")
{
var pawn = e.Controller?.GetHeroPawn()?.As<CCitadelPlayerPawn>();
if (pawn != null && !pawn.InRegenerationZone && pawn.Health > 0)
return HookResult.Stop;
}
return HookResult.Continue;
}

ClientConCommandEvent

PropertyTypeDescription
CommandstringThe command name (e.g. "sellitem", "selecthero")
Argsstring[]All arguments including the command name at index 0
ControllerCCitadelPlayerController?The player who sent the command

See Also

  • Chat Commands — Player chat commands ([ChatCommand])
  • Plugin BaseOnClientConCommand hook for intercepting client commands