Meh, I was looking how to do this myself, couldn't find any good tutorial, so I felt like making an example for anyone whos looking like me.
testconfig.amxx
Sets a config path, and loads cvars from that.
Note- Make a folder named "Test" inside your config folder, and make a config file named "Test" with the cvar "Test_Enabled 1" or "Test_Enabled 0".
Code:
/**************************************************************************************************/
#include <amxmodx>
#include <amxmisc>
/**************************************************************************************************/
#define PLUGIN "TestConfig"
#define VERSION "1.0"
#define AUTHOR "Sphinx"
/**************************************************************************************************/
new gTestConfig[128] // Needed for the config file.
/**************************************************************************************************/
public plugin_init() {
register_plugin("TestConfig", "1.0", "Sphinx")
SetupConfig() // We need to set up the config path
register_cvar("Test_Enabled", "1"); // Example Cvar, very standard.
register_concmd("say hi", "hi_response"); // We will use this to test to see if it worked
}
/**************************************************************************************************/
public plugin_cfg() {
LoadConfig() // Lets load up the config
CVAR_Check() // Initial CVAR check
set_task(5.0, "CVAR_Check") // Checking again!
}
/**************************************************************************************************/
public hi_response(id) {
if(get_cvar_num("Test_enabled") == 1) {
client_print(id, print_chat, "[Test] Hi!")
}
else {
client_print(id, print_chat, "[Test] Test Turned Off")
}
}
/**************************************************************************************************/
public CVAR_Check() {
new pEnabled = get_cvar_num("Test_Enabled") // pEnabled (plugin enabled) stores the cvar we just retrieved
if ( pEnabled > 1 ) set_cvar_num("Test_Enabled", 1) // if they accidently put something above 1, we will set it to 1
if ( pEnabled < 0 ) set_cvar_num("Test_Enabled", 0) // Same thing, except below 0, set to 0.
}
/**************************************************************************************************/
public SetupConfig() {
new ConfigDir[128] // We will store the path in this.
get_configsdir(ConfigDir,127) // Gets your directory path
format(gTestConfig,127,"%s/Test/Test.cfg",ConfigDir) // Stores the config into gTestConfig
}
/**************************************************************************************************/
public LoadConfig() {
if (file_exists(gTestConfig)) { // Lets check to see if it exists first.
server_cmd("exec %s",gTestConfig) // Loads the config we stored in gTestConfig
}
}
/**************************************************************************************************/
Looked at other plugins on how to do this, so it might look familiar to some people
__________________