[1.0.5] Static Setting Objects - ntoxin66/Dynamic GitHub Wiki

[This page is under construction!]

Dynamic exposes some global objects for the storage of Server and Player settings. These objects are stored in such a way that Natives are not required to access pointers to these dynamic objects. This means you can obtain references incredibly fast to these settings which is ideal for use in high performance forwards such as OnGameFrame or OnClientUserCmd.

What makes these settings so useful?

Server and Player settings can be used to easily share data between plugins without the need to write natives.

Server Settings

You can access Server Settings via the Dynamic.GetSettings(); method. Any members stored within this object are valid for the lifetime of the server instance.

public void OnPluginStart()
{
	// Get global server settings
	Dynamic settings = Dynamic.GetSettings();
	
	// Create plugin settings
	Dynamic pluginsettings = Dynamic();
	pluginsettings.SetBool("Enabled", true);
	
	// Store plugin settings in the server settings object
	settings.SetDynamic("MyPluginName", pluginsettings);
}

You can see we create a new dynamic instance and create a member called Enabled and set this member to true. Another plugin could then access this member like so.

public void OnClientConnected(int client)
{
	Dynamic pluginsettings = Dynamic.GetSettings().GetDynamic("MyPluginName");
	if (!pluginsettings.GetBool("Enabled"))
	{
		// Plugin is not enabled so throw error or do nothing
		return;
	}
}

Player Settings

You can access Player Settings via the Dynamic.GetPlayerSettings(int client) method. Any members stored within this object are valid until the client disconnects.

public void OnClientConnected(int client)
{
	Dynamic playersettings = Dynamic.GetPlayerSettings(client);
}

Player Settings objects are created when Dynamic initialises and are accessible at any point regardless if a player is connected or not. Player Settings members are reset during Sourcemod's OnClientDisconnect_Post forward, this means the Player Settings are accessible during Sourcemod's standard OnClientDisconnect forward.