Raised This Month: $51 Target: $400
 12% 

[INC] Config Loader


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
cam0
Senior Member
Join Date: Feb 2015
Old 12-24-2015 , 01:46   [INC] Config Loader
Reply With Quote #1

Simple configuration loading method, credit to Bara.

Example usage:
Code:
void OnPluginStart(){     char file[PLATFORM_MAX_PATH];     BuildPath(Path_SM, file, sizeof(file), "configs/mysettings.cfg");     if(Config_Setup("Server-Settings", file)){         bool mybool = Config_LoadBool("mybool", true, "Default bool description");         int myint = Config_LoadInt("myint", 0, "Default int description");         float myfloat = Config_LoadFloat("myfloat", 0.0, "Default float description");         char buffer[128];         Config_LoadString("mystring", "default string description", "Default string description", buffer, sizeof(buffer));         Config_Done();     } }

This example was updated 2/25/2016 to reflect the change made on the repository on 1/12/2016.

This has been available for some time and is seen in use in the Trouble in Terrorist Town plugin; I am just now posting it here in the hopes more people will find use in it.

GitHub: https://github.com/whocodes/config-loader
__________________

Last edited by cam0; 02-25-2016 at 18:00.
cam0 is offline
cam0
Senior Member
Join Date: Feb 2015
Old 01-12-2016 , 17:32   Re: [INC] Config Loader
Reply With Quote #2

Updated to re-use the same KeyValues handle instead of opening several.
__________________
cam0 is offline
Disowned
Member
Join Date: Oct 2015
Old 01-13-2016 , 07:32   Re: [INC] Config Loader
Reply With Quote #3

Plugins can also opt for putting configs into convars.
Example:
PHP Code:
bool g_Enabled;
Handle g_Cvar_Enabled;

public 
OnPluginStart() {
    
g_Cvar_Enabled CreateConVar("something_enable""1""Enable or Disable [0 = FALSE, 1 = TRUE, DEFAULT: 1]",FCVAR_NONEtrue0.0true1.0);
    
AutoExecConfig(true"haletracks");
}

public 
OnConfigsExecuted() {

    
g_Enabled GetConVarBool(g_Cvar_Enabled);

AutoExecConfig will automatically generate a config file that includes the 'CreateConVar' keys and values. It will load these values if the file exists.

Last edited by Disowned; 01-13-2016 at 07:34.
Disowned is offline
WildCard65
Veteran Member
Join Date: Aug 2013
Location: Canada
Old 01-13-2016 , 08:26   Re: [INC] Config Loader
Reply With Quote #4

Quote:
Originally Posted by Disowned View Post
Plugins can also opt for putting configs into convars.
Example:
PHP Code:
bool g_Enabled;
Handle g_Cvar_Enabled;

public 
OnPluginStart() {
    
g_Cvar_Enabled CreateConVar("something_enable""1""Enable or Disable [0 = FALSE, 1 = TRUE, DEFAULT: 1]",FCVAR_NONEtrue0.0true1.0);
    
AutoExecConfig(true"haletracks");
}

public 
OnConfigsExecuted() {

    
g_Enabled GetConVarBool(g_Cvar_Enabled);

AutoExecConfig will automatically generate a config file that includes the 'CreateConVar' keys and values. It will load these values if the file exists.
AutoExecConfigs places the config into the engine's config list to execute commands from automatically. If file doesn't exist, AutoExecConfig generates it based on the CVars the plugin owns(you can see list via sm plugins cvars #pluginnumhere) then adds it to list.
WildCard65 is offline
cam0
Senior Member
Join Date: Feb 2015
Old 02-25-2016 , 14:57   Re: [INC] Config Loader
Reply With Quote #5

Updated the include with new method using only one KeyValues handle. Check up on the new example for how to make it work.
__________________
cam0 is offline
8guawong
AlliedModders Donor
Join Date: Dec 2013
Location: BlackMarke7
Old 04-25-2016 , 21:55   Re: [INC] Config Loader
Reply With Quote #6

ummm with convar we can set the convar values on the fly
how to do it with this system....?

and why is there a need for this??
__________________
8guawong is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 00:54.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode