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

[TUT] Config files


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
r4ndomz
Senior Member
Join Date: Jul 2009
Location: The Hood
Old 12-03-2010 , 16:16   [TUT] Config files
Reply With Quote #1

Config files

This is a basic example of a config that you can add to your work.
What it does basicly is just create a config file, write to it, and execute it just
like the server would execute server.cfg or autoexec.cfg.



1. In plugin_init(), add ExecuteConfigs();

PHP Code:
public plugin_init()
{
    
register_plugin("Config""1.00""Exolent")

    
ExecuteConfigs();     //if this isnt here the server wont bother what your about to do below

2. Create your ExecuteConfigs() function, and initially create the file

PHP Code:
public ExecuteConfigs()
{
    new 
sConfig[64];     //Create the variable
    
get_localinfo("amxx_configdir"sConfig63)     //get the configs directory (addons/amxmodx/configs/)
    
add(sConfig63"/tutorial.cfg"0);     //create the file being used
    
    
if( file_exists(sConfig) )     //if its already there just execute it
    
{
        
server_cmd("exec %s"sConfig);
        
server_exec();
    }
    else
    {
        
make_config(sConfig);     //if its not then create it with the information we made here
    
}

3. Pick up where you left off

PHP Code:
make_config(const sConfig[])
{
    new 
fopen(sConfig"wt");     //open the file with the flags Write and Text
    
    
fputs(f"// This is where the configs thing is.^n^n^n");     //Add a comment line with 3 spaces (Note ^n means "New line")
    
    
fprintf(f"config_cvar %i^n"get_pcvar_num(p_cvar)); //Write the cvars for your plugin in the form used to change the cvars ex. amx_cvar "sv_gravity"

    
    
fclose(f);     //close the file

Add it all together and check if it works (Note: The below example has what you need to test, above does not)

Code:
#include <amxmodx>


new p_cvar


public plugin_init()
{
    register_plugin("Config", "1.00", "r4ndomz")

    p_cvar = register_cvar("config_cvar", "1337")
    register_clcmd("say pcvar", "print_pcvar")

    ExecuteConfigs();
}


public ExecuteConfigs()
{
    new sConfig[64];
    get_localinfo("amxx_configdir", sConfig, 63)
    add(sConfig, 63, "/tutorial.cfg", 0);
    
    if( file_exists(sConfig) )
    {
        server_cmd("exec %s", sConfig);
        server_exec();
    }
    else
    {
        make_config(sConfig);
    }
}

make_config(const sConfig[])
{
    new f = fopen(sConfig, "wt");
    
    fputs(f, "// This is where the configs thing is.^n^n^n");
    
    fprintf(f, "config_cvar %i^n", get_pcvar_num(p_cvar));

    
    fclose(f);
}


public print_pcvar(id)
{
    client_print(id, print_chat, "Pcvar is currently set at %i", get_pcvar_num(p_cvar))
}
Credit to exolent, original code from him.
Don't do drugs.
__________________
HideNSeek bug fixed here:http://forums.alliedmods.net/showpos...&postcount=951

PM me if you want a nice HideNSeek shop
NEED PLUGIN TESTERS PM ME

Last edited by r4ndomz; 12-04-2010 at 13:42.
r4ndomz is offline
Send a message via Skype™ to r4ndomz
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 12-03-2010 , 17:03   Re: [TUT] Config files
Reply With Quote #2

Ummm . . . what? I see not logic for something like this (what ever it is).
__________________
fysiks is offline
r4ndomz
Senior Member
Join Date: Jul 2009
Location: The Hood
Old 12-03-2010 , 20:38   Re: [TUT] Config files
Reply With Quote #3

Quote:
Originally Posted by fysiks View Post
Ummm . . . what? I see not logic for something like this (what ever it is).
The logic is to make a configuration file. Did you even read it?

A while ago i wanted to make a config file..but i did not know how to do it. I searched and didnt find anything related to this matter.

This is a clear-cut way of making a config file. You wont need to look through a plugin that already has a config file in its code and try to find out how it works.
__________________
HideNSeek bug fixed here:http://forums.alliedmods.net/showpos...&postcount=951

PM me if you want a nice HideNSeek shop
NEED PLUGIN TESTERS PM ME

Last edited by r4ndomz; 12-03-2010 at 20:41.
r4ndomz is offline
Send a message via Skype™ to r4ndomz
Kreation
Veteran Member
Join Date: Jan 2010
Location: Illinois
Old 12-03-2010 , 21:57   Re: [TUT] Config files
Reply With Quote #4

So did this come from your brain? Or someone else's( Exolent ). You know what I mean, give credit where credit is due please. Thanks.
__________________
Hi.
Kreation is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 12-03-2010 , 23:20   Re: [TUT] Config files
Reply With Quote #5

Quote:
Originally Posted by r4ndomz View Post
The logic is to make a configuration file. Did you even read it?

A while ago i wanted to make a config file..but i did not know how to do it. I searched and didnt find anything related to this matter.

This is a clear-cut way of making a config file. You wont need to look through a plugin that already has a config file in its code and try to find out how it works.
Yes, I read the post but I also have this very rarely used and highly secret program that I use called Notepad to create a config file. And, I can document it as well instead of it just being a plain list of cvars.
__________________

Last edited by fysiks; 12-03-2010 at 23:24.
fysiks is offline
r4ndomz
Senior Member
Join Date: Jul 2009
Location: The Hood
Old 12-03-2010 , 23:28   Re: [TUT] Config files
Reply With Quote #6

Quote:
Originally Posted by fysiks View Post
Yes, I read the post but I also have this very rarely used and highly secret program that I use called Notepad to create a config file. And, I can document it as well instead of it just being a plain list of cvars.
Then this is an example of doing that in code.


Quote:
Originally Posted by Kreation View Post
So did this come from your brain? Or someone else's( Exolent ). You know what I mean, give credit where credit is due please. Thanks.
Thanks for the reminder.
__________________
HideNSeek bug fixed here:http://forums.alliedmods.net/showpos...&postcount=951

PM me if you want a nice HideNSeek shop
NEED PLUGIN TESTERS PM ME

Last edited by r4ndomz; 12-03-2010 at 23:31.
r4ndomz is offline
Send a message via Skype™ to r4ndomz
wrecked_
Veteran Member
Join Date: Jan 2010
Location: New York (GMT-5)
Old 12-03-2010 , 23:37   Re: [TUT] Config files
Reply With Quote #7

Quote:
Originally Posted by r4ndomz View Post
Then this is an example of doing that in code.
This is an example of someone defending a cause without reasoning, only because their elite role model had done it in the past.
__________________
[ Paid Requests ]
DO NOT PM ME ABOUT BLOCKMAKER
NO PRIVATE SUPPORT
wrecked_ is offline
Excalibur.007
Veteran Member
Join Date: Sep 2009
Location: Singapore
Old 12-03-2010 , 23:49   Re: [TUT] Config files
Reply With Quote #8

Use get_localinfo, so you wouldn't need amxmisc .
Excalibur.007 is offline
r4ndomz
Senior Member
Join Date: Jul 2009
Location: The Hood
Old 12-04-2010 , 00:47   Re: [TUT] Config files
Reply With Quote #9

Quote:
Originally Posted by wrecked_ View Post
This is an example of someone defending a cause without reasoning, only because their elite role model had done it in the past.

And who exactly is my elite role model?
__________________
HideNSeek bug fixed here:http://forums.alliedmods.net/showpos...&postcount=951

PM me if you want a nice HideNSeek shop
NEED PLUGIN TESTERS PM ME
r4ndomz is offline
Send a message via Skype™ to r4ndomz
shuttle_wave
Veteran Member
Join Date: Apr 2009
Location: New Zealand
Old 12-04-2010 , 04:25   Re: [TUT] Config files
Reply With Quote #10

Quote:
Originally Posted by r4ndomz View Post
Then this is an example of doing that in code.
Example to Copy and Paste from Exolent's Code
__________________
JailBreak Mod with Plugin API ( 90% ) Public
shuttle_wave 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 01:02.


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