AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Help on a server_cmd (https://forums.alliedmods.net/showthread.php?t=61220)

amxnewbie 09-24-2007 11:25

Help on a server_cmd
 
During the init of a plugin, I would like to get two values from a file, (abc.cfg) under amx conf directory.

Code:

public plugin_init() {
 register_plugin(PLUGIN, VERSION, AUTHOR)
 
 //deffault value
 register_cvar("ip_common", "127.0.0.1")
 
 new configsDir[64], HostIP[32]
get_configsdir(configsDir, 63)
server_cmd("exec %s/abc.cfg", configsDir)
 
 get_cvar_string("ip_common",HostIP,31)
}

In the addons\amxmodx\configs\abc.cfg, I have:
Code:

ip_common "210.245.126"
My understanding for server_cmd("exec %s/abc.cfg", configsDir) is to assign the value to the the registered VAR. I follow AMX admin.sma in which it has default MySQL parameters and it also reads the setting from sql.cfg.

However, it always returns me the default value, 127.0.0.1

I went throught the tutorial, but no good news. Thanks for any suggestions.

vl@d 09-24-2007 12:26

Re: Help on a server_cmd
 
What do you trying to do?
you set a cvar to change what?

Lee 09-24-2007 12:54

Re: Help on a server_cmd
 
The difference between your version and admin.sma is that the new cvar value is read inside a function called by a server command.

Commands sent with server_cmd() aren't executed immediately and that's why get_cvar_string() is reading the old value. You could try using server_exec() after server_cmd() or you could copy the workaround in admin.sma.

amxnewbie 09-25-2007 04:21

Re: Help on a server_cmd
 
cl@d, I want read a CVAR from a file instead of hardcoding.
Lee, your suggestion is nice, but I changed this to:
Code:

public plugin_init() {
 register_plugin(PLUGIN, VERSION, AUTHOR)
 
 //deffault value
 register_cvar("ip_common", "127.0.0.1")
 
 new configsDir[64], HostIP[32]
get_configsdir(configsDir, 63)
server_cmd("exec %s/abc.cfg", configsDir)
 server_exec()

 get_cvar_string("ip_common",HostIP,31)
}

It still gives me the old value, can you give me any idea on the admin.sma way? THanks.

Lee 09-25-2007 08:37

Re: Help on a server_cmd
 
Code:
public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR);     register_cvar("ip_common", "127.0.0.1");     register_srvcmd("read_value", "readValue");         new configsDir[64];     get_configsdir(configsDir, 63);         server_cmd("exec %s/abc.cfg", configsDir);     server_cmd("read_value"); } public readValue() {     new ip[16];     get_cvar_string("ip_common", ip, 15); }

potatis_invalido 09-25-2007 10:54

Re: Help on a server_cmd
 
Thats a smart way of doing it, Lee.

amxnewbie 09-25-2007 12:21

Re: Help on a server_cmd
 
Thanks, Lee. It works. Cheers!
Really appreciate your kind help. ^_^


All times are GMT -4. The time now is 16:15.

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