Skip to main content

ConVars

Namespace: DeadworksManaged.Api

A ConVar is a named setting you can read or change from the console.

Use [ConVar] when you want a simple plugin setting that server admins can tweak without rebuilding your plugin.

For custom ConVars, start the name with dw_.

Quick Start

using DeadworksManaged.Api;

namespace MyPlugin;

public class MyPlugin : DeadworksPluginBase
{
[ConVar("dw_my_plugin_enabled", Description = "Turn the plugin on or off")]
public bool Enabled { get; set; } = true;

[ConVar("dw_my_plugin_damage", Description = "Damage multiplier", ServerOnly = true)]
public float DamageMultiplier { get; set; } = 1.0f;
}

That gives you console settings named:

  • dw_my_plugin_enabled
  • dw_my_plugin_damage

If you type the name by itself, Deadworks prints the current value.

If you type the name followed by a value, Deadworks updates it.

For example:

  • dw_my_plugin_enabled
  • dw_my_plugin_enabled false
  • dw_my_plugin_damage 1.5

ConVarAttribute

Use [ConVar] on a property in your plugin.

Supported property types are:

  • int
  • float
  • bool
  • string
SettingTypeDescription
NamestringThe console name, like dw_my_plugin_enabled
DescriptionstringShort help text shown in console
ServerOnlyboolOnly let the server console change it

ConVar Class

Use ConVar when you want to read or change console variables from code.

This is useful when you want to change built-in game settings in OnStartupServer.

MethodReturnsDescription
Find(string name)ConVar?Find an existing ConVar
Create(string name, string defaultValue, string description = "", bool serverOnly = false)ConVar?Create a new ConVar
SetInt(int value)voidSet the value as an integer
SetFloat(float value)voidSet the value as a float
public override void OnStartupServer()
{
ConVar.Find("citadel_allow_duplicate_heroes")?.SetInt(1);
ConVar.Find("citadel_player_starting_gold")?.SetInt(0);
ConVar.Find("citadel_voice_all_talk")?.SetInt(1);
}