Raised This Month: $ Target: $400
 0% 

How to setup a config! [Plugin Example]


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
TheNewt
Donor
Join Date: Jun 2006
Location: Where I live.
Old 07-04-2006 , 12:53   How to setup a config! [Plugin Example]
Reply With Quote #1

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
__________________
Quote:
toe3_ left the chat room. (G-lined (AUTO Excessive connections from a single host.))

Last edited by TheNewt; 07-04-2006 at 12:57.
TheNewt is offline
 



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 08:05.


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