AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   How to setup a config! [Plugin Example] (https://forums.alliedmods.net/showthread.php?t=40832)

TheNewt 07-04-2006 12:53

How to setup a config! [Plugin Example]
 
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. :P
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

Hawk552 07-04-2006 13:29

Re: How to setup a config! [Plugin Example]
 
This makes no sense. There's so much irrelevant and useless code.

Brad 07-04-2006 13:45

Re: How to setup a config! [Plugin Example]
 
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.

jtp10181 07-04-2006 21:51

Re: How to setup a config! [Plugin Example]
 
why do we need a tutorial on how to exec a config file?

Hawk552 07-05-2006 11:02

Re: How to setup a config! [Plugin Example]
 
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.

TheNewt 07-05-2006 18:38

Re: How to setup a config! [Plugin Example]
 
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.

Hawk552 07-05-2006 19:04

Re: How to setup a config! [Plugin Example]
 
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.

Brad 07-07-2006 01:10

Re: How to setup a config! [Plugin Example]
 
Moved to "Scripting Help" because it doesn't meet the unspoken and unknown criteria for being in "Code Snippets/Tutorials".

Xanimos 07-07-2006 01:28

Re: How to setup a config! [Plugin Example]
 
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.

TheNewt 07-07-2006 09:32

Re: How to setup a config! [Plugin Example]
 
Alright, I have no problem with that. Haha.


All times are GMT -4. The time now is 08:05.

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