Difference between revisions of "AutoConfigs (AMX Mod X Scripting)"

From AlliedModders Wiki
Jump to: navigation, search
(Added AutoConfigs documentation)
 
m (Fixed category link)
Line 78: Line 78:
 
</pawn>
 
</pawn>
  
[[Category:AMX Mod X Scripting]]
+
[[Category:Scripting_(AMX_Mod_X)]]

Revision as of 15:40, 16 June 2017

Language: English  • français


Purpose

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/amxmodx.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

Native

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.

Forward

OnConfigsExecuted()
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().
OnAutoConfigsBuffered()
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.

Example

#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.");
 
    AutoExecConfig();
}

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"