Raised This Month: $ Target: $400
 0% 

How to setup a config! [Plugin Example]


Post New Thread Reply   
 
Thread Tools Display Modes
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
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 07-04-2006 , 13:29   Re: How to setup a config! [Plugin Example]
Reply With Quote #2

This makes no sense. There's so much irrelevant and useless code.
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
Brad
AMX Mod X Team Member
Join Date: Jun 2004
Old 07-04-2006 , 13:45   Re: How to setup a config! [Plugin Example]
Reply With Quote #3

Agreed.

When you post code in this forum, you should only post the working code needed to get the point across. Extraneous code just confuses the issue.

Also of note, if you only have a single file for your plugin, it makes no sense to create another subdirectory to contain that one file. You should only create a subdirectory if you have 2 or more files for your plugin. If you just have one, place it in the .\configs directory itself.
__________________
Brad is offline
jtp10181
Veteran Member
Join Date: May 2004
Location: Madison, WI
Old 07-04-2006 , 21:51   Re: How to setup a config! [Plugin Example]
Reply With Quote #4

why do we need a tutorial on how to exec a config file?
__________________
jtp10181 is offline
Send a message via ICQ to jtp10181 Send a message via AIM to jtp10181 Send a message via MSN to jtp10181 Send a message via Yahoo to jtp10181
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 07-05-2006 , 11:02   Re: How to setup a config! [Plugin Example]
Reply With Quote #5

Quote:
Originally Posted by jtp10181
why do we need a tutorial on how to exec a config file?
Because there are people that seem to think absolutely anything that comes out of their mouths / hands (typing) is useful.
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
TheNewt
Donor
Join Date: Jun 2006
Location: Where I live.
Old 07-05-2006 , 18:38   Re: How to setup a config! [Plugin Example]
Reply With Quote #6

Quote:
Because there are people that seem to think absolutely anything that comes out of their mouths / hands (typing) is useful.
You mean like that comment. I found absolutely no tutorial, or any doc on how to do this. I'm just trying to help out anyone who wants to know how to do it.
__________________
Quote:
toe3_ left the chat room. (G-lined (AUTO Excessive connections from a single host.))
TheNewt is offline
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 07-05-2006 , 19:04   Re: How to setup a config! [Plugin Example]
Reply With Quote #7

Quote:
Originally Posted by MysticDeath
You mean like that comment. I found absolutely no tutorial, or any doc on how to do this. I'm just trying to help out anyone who wants to know how to do it.
let's write tutorials about how to register cvars. actually, here's one now

Code:
register_cvar("LOL","ZOMG")

I couldn't find this ANYWHERE, therefore it's useful. Also, I didn't really explain how it works, just assume it does.
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
Brad
AMX Mod X Team Member
Join Date: Jun 2004
Old 07-07-2006 , 01:10   Re: How to setup a config! [Plugin Example]
Reply With Quote #8

Moved to "Scripting Help" because it doesn't meet the unspoken and unknown criteria for being in "Code Snippets/Tutorials".
__________________
Brad is offline
Xanimos
Veteran Member
Join Date: Apr 2005
Location: Florida
Old 07-07-2006 , 01:28   Re: How to setup a config! [Plugin Example]
Reply With Quote #9

Quote:
Originally Posted by Brad
Moved to "Scripting Help" because it doesn't meet the unspoken and unknown criteria for being in "Code Snippets/Tutorials".
You should write one.
Xanimos is offline
Send a message via AIM to Xanimos Send a message via MSN to Xanimos
TheNewt
Donor
Join Date: Jun 2006
Location: Where I live.
Old 07-07-2006 , 09:32   Re: How to setup a config! [Plugin Example]
Reply With Quote #10

Alright, I have no problem with that. Haha.
__________________
Quote:
toe3_ left the chat room. (G-lined (AUTO Excessive connections from a single host.))
TheNewt is offline
Reply


Thread Tools
Display Modes

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:04.


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