AutoConfigs (AMX Mod X Scripting)

From AlliedModders Wiki
Jump to: navigation, search
Language: English  • français


AMX Mod X 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/

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.



AutoExecConfig(bool:autoCreate = true, const name[] = "", const folder[] = "")
Specifies that the given config file should be executed after plugin load.
autoCreate     If true, AMX Mod X will dump all cvars 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.amxx becomes plugin-hat.cfg.
folder     Optionally change the folder under the main configs folder. By default configs go in /amxmodx/configs/.
Note:It is possible to write nested folders; AMX Mod X 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.
Example:// Default values. /configs/plugins/plugin-hat.cfg will be created (if not present) and executed.
// plugin-hat.cfg will executed only.
AutoExecConfig(.autoCreate = false);
// plugin-MyHat.cfg will be created (if not present) and executed.
AutoExecConfig(.name = "MyHat");
// /configs/my-plugins/plugin-hat.cfg will be created (if not present) and executed.
AutoExecConfig(.folder = "my-plugins");


Called when the map has loaded, and all configs are done executing.
This includes servercfgfile (server.cfg), amxx.cfg, plugin's config, and per-map config.
Note:This is best place to initialize plugin functions which are based on cvar data.
Note:This will always be called once and only once per map. It will be called few seconds after plugin_cfg().
Example:public OnConfigsExecuted()
    new const value = get_cvar_num("mp_timelimit");
Called when the map has loaded, right after plugin_cfg() but any time before OnConfigsExecuted().
It's called after amxx.cfg and all AutoExecConfig exec commands have been added to the server command buffer.
Note:This will always be called once and only once per map.


#include <amxmodx>
public plugin_init()
    register_plugin("Hat", "User", "1.0");
    create_cvar("mysqlk_database", "", .description = "MySQL database");
    create_cvar("mysqlk_host", "localhost", .description = "MySQL host, use this to configure various^nthings for your server.");

That would export a config file that looks like this:

// This file was auto-generated by AMX Mod X (v1.9)
// Cvars for plugin "Hat" by "User" (hat.amxx, v1.0)
// MySQL database
// -
// Default: ""
mysqlk_database ""
// MySQL host, use this to configure various
// things for your server.
// -
// Default: "localhost"
mysqlk_host "localhost"