Difference between revisions of "AutoConfigs (SourceMod Scripting)"

From AlliedModders Wiki
Jump to: navigation, search
m (Removed old language switch)
 
(One intermediate revision by one other user not shown)
Line 14: Line 14:
  
 
''Note'': If you have multiple <tt>AutoExecConfig</tt> calls marked with '''autoCreate''' being true, the first file to be auto created will prevent any others from being created.  Thus, there is no way to automatically split cvars between multiple files.
 
''Note'': If you have multiple <tt>AutoExecConfig</tt> calls marked with '''autoCreate''' being true, the first file to be auto created will prevent any others from being created.  Thus, there is no way to automatically split cvars between multiple files.
 +
 +
''Note'': If a cvar has the flag <tt>FCVAR_DONTRECORD</tt>, it will not show up in the autoconfig. A good example of a use for this flag in a cvar, would be for the '''version''' cvar plugins need for the sake of tracking.
  
  
Line 37: Line 39:
  
 
[[Category:SourceMod Scripting]]
 
[[Category:SourceMod Scripting]]
 
{{LanguageSwitch}}
 

Latest revision as of 02:37, 7 June 2017

Language: English  • 한국어

SourceMod provides a system for simple plugins to automatically generate config files which get executed on load. This is done via the AutoExecConfig native in scripting/include/sourcemod.inc.

Once all configuration files are executed, OnConfigsExecuted is called. This forward will always be called, even if your plugin had no configs or if it was loaded late.

Usage

There are three parameters to this call:

  • autoCreate - If true, SourceMod will dump all ConVars created by the plugin into a config file if the specified config file does not exist.
  • name - Name of the config file (excluding the .cfg extension). If empty, the plugin's name will be used instead, with plugin. prepended. For example, hat.smx becomes plugin.hat.cfg.
  • folder - Optionally change the folder under the main cfg folder. By default this is sourcemod, and configs go in cfg/sourcemod/. If empty, the config will be in cfg/.

Note: It is possible to write nested folders; SourceMod will attempt to create each one.

Note: If you have multiple AutoExecConfig calls marked with autoCreate being true, the first file to be auto created will prevent any others from being created. Thus, there is no way to automatically split cvars between multiple files.

Note: If a cvar has the flag FCVAR_DONTRECORD, it will not show up in the autoconfig. A good example of a use for this flag in a cvar, would be for the version cvar plugins need for the sake of tracking.


Example Dump

The autoCreate feature exports a config file that looks like this:

// This file was auto-generated by SourceMod (v1.0.0.986)
// ConVars for plugin "hat.smx"


// MySQL database
// -
// Default: ""
mysqlk_database ""

// MySQL host, use this to configure various
// things for your server.
// -
// Default: "localhost"
mysqlk_host "localhost"