Raised This Month: $ Target: $400
 0% 

Help running config


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
666
Senior Member
Join Date: Mar 2015
Old 10-12-2022 , 18:48   Help running config
Reply With Quote #1


PHP Code:
#include <amxmodx>
#include <amxmisc>

enum CVARS
{
    
NAME[MAX_RESOURCE_PATH_LENGTH],
    
VALUE[MAX_RESOURCE_PATH_LENGTH]
};

new 
cvar_list[][CVARS] = 
{
    {
"mp_timeleft""0"},
    {
"mp_timelimit""0"},
    {
"mp_tkpunish""0"},
    {
"mp_windifference""1"},
    {
"mp_winlimit""0"},
};

public 
plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
}

public Function()
{
    
ExecuteGameConfig(cvar_list)
}

public 
ExecuteGameConfig(const cvars[])
{
    for ( new 
0sizeof(cvars); i++ )
    {
        
set_cvar_string(cvarscvars);
    }

__________________

Last edited by 666; 10-13-2022 at 14:12.
666 is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 10-12-2022 , 23:07   Re: Help running config
Reply With Quote #2

So, what is your question? How exactly are you wanting this plugin to work? Are you actually wanting to use a file or or a variable?

If you just want to execute a cfg file, simply use the server's 'exec' command:

Code:
server_cmd("exec path/to/config/game.cfg")
server_exec()
If you're trying to use variables then you've made many mistakes in the code.
__________________
fysiks is offline
666
Senior Member
Join Date: Mar 2015
Old 10-13-2022 , 10:47   Re: Help running config
Reply With Quote #3

Quote:
Originally Posted by fysiks View Post
So, what is your question? How exactly are you wanting this plugin to work? Are you actually wanting to use a file or or a variable?

If you just want to execute a cfg file, simply use the server's 'exec' command:

Code:
server_cmd("exec path/to/config/game.cfg")
server_exec()
If you're trying to use variables then you've made many mistakes in the code.
Hi, friend. Sorry for not explaining well what I want is to set the cvar that are in the cvar list. what complicates me is the constant, I don't know what to do there. I want to do it that way.

it would be something like this:
PHP Code:
enum CVARS
{
    
NAME[MAX_RESOURCE_PATH_LENGTH],
    
VALUE[MAX_RESOURCE_PATH_LENGTH]
};

new 
cvar_list[][CVARS] = 
{
    {
"mp_timeleft""0"},
    {
"mp_timelimit""0"},
    {
"mp_tkpunish""0"},
    {
"mp_windifference""1"},
    {
"mp_winlimit""0"},
};

public Function()
{
    
ExecuteGameConfig(cvar_list)
}

public 
ExecuteGameConfig(const cvars[])
{
    for ( new 
0sizeof(cvars); i++ )
    {
        
set_cvar_string(cvarscvars);
    }

__________________
666 is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 10-13-2022 , 21:00   Re: Help running config
Reply With Quote #4

To use a variable that is defined with an enum, you have to index it with the enum members. For example, if defined a variable with the CVARS enum like this:

PHP Code:
new aCvar[CVARS
Then you would use the aCvar variable like this:

PHP Code:
server_print("CvarName: %s"aCvar[NAME])
server_print("CvarValue: %s, aCvar[VALUE]) 
So, if you're doing this with an array of the CVARS enum like you do, you would include the index for the first dimension:

PHP Code:
server_print("CvarName: %s"cvar_list[i][NAME])
server_print("CvarValue: %s, cvar_list[i][VALUE]) 
Then, to be able to pass the variable into the function, I ended up having to do this:

PHP Code:
public Function()
{
    
ExecuteGameConfig(cvar_listsizeof cvar_list)
}

public 
ExecuteGameConfig(cvars[][CVARS], size)
{
    for ( new 
0sizei++ )
    {
        
set_cvar_string(cvars[i][NAME], cvars[i][VALUE]);
    }

I only tested this by compiling but I believe it should work.
__________________
fysiks is offline
666
Senior Member
Join Date: Mar 2015
Old 10-13-2022 , 23:26   Re: Help running config
Reply With Quote #5

Quote:
Originally Posted by fysiks View Post
To use a variable that is defined with an enum, you have to index it with the enum members. For example, if defined a variable with the CVARS enum like this:

PHP Code:
new aCvar[CVARS
Then you would use the aCvar variable like this:

PHP Code:
server_print("CvarName: %s"aCvar[NAME])
server_print("CvarValue: %s, aCvar[VALUE]) 
So, if you're doing this with an array of the CVARS enum like you do, you would include the index for the first dimension:

PHP Code:
server_print("CvarName: %s"cvar_list[i][NAME])
server_print("CvarValue: %s, cvar_list[i][VALUE]) 
Then, to be able to pass the variable into the function, I ended up having to do this:

PHP Code:
public Function()
{
    
ExecuteGameConfig(cvar_listsizeof cvar_list)
}

public 
ExecuteGameConfig(cvars[][CVARS], size)
{
    for ( new 
0sizei++ )
    {
        
set_cvar_string(cvars[i][NAME], cvars[i][VALUE]);
    }

I only tested this by compiling but I believe it should work.
Understood thanks friend, working perfectly
__________________
666 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 08:49.


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