S&box Wiki

ClientData ConVars

ClientData ConVars

A client data convar is like a replicated convar, except instead of being replicated from the server to the clients, it's replicated from each client to the server.

When the value changes on the client it is sent to the server.

These values are accessible on the server for each client using Client.GetUserString( "var_name" ).

Defining

[ConVar.ClientData( "tool_current" )] public static string UserToolCurrent { get; set; } = "boxgun"

Accessing

// On the client you can access it directly currentTool = UserToolCurrent; // Or via the console system currentTool = ConsoleSystem.GetValue( "tool_current" ); // On the server you need to access via a Client object public override void Simulate( Client owner ) { currentTool = owner.GetUserString( "tool_current" ); }

Pawn Member

You can also store your convar as a member on an Entity (ie - not a static)

[ConVar.ClientData( "tool_current" )] public string UserToolCurrent { get; set; } = "boxgun"

This works pretty much the same, except on both the server and client it can be accessed directly.

// Will always access the convar value on the client, but on the server will access // it via the entity's GetClientOwner(). If the entity has no client owner, will be null. currentTool = UserToolCurrent;

Special Pages


Wikis

?

Render Time: 11ms

DB GetPage 1
Generate Html 1
SaveChanges (1) 6
Render Body 0
Render Sidebar 0