Raised This Month: $ Target: $400
 0% 

Help on a server_cmd


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
amxnewbie
Junior Member
Join Date: Sep 2007
Old 09-24-2007 , 11:25   Help on a server_cmd
Reply With Quote #1

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.

Last edited by amxnewbie; 09-24-2007 at 11:27. Reason: typo
amxnewbie is offline
vl@d
Senior Member
Join Date: Dec 2006
Location: Romania
Old 09-24-2007 , 12:26   Re: Help on a server_cmd
Reply With Quote #2

What do you trying to do?
you set a cvar to change what?
__________________


I hate Spammers....
vl@d is offline
Lee
AlliedModders Donor
Join Date: Feb 2006
Old 09-24-2007 , 12:54   Re: Help on a server_cmd
Reply With Quote #3

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.
Lee is offline
amxnewbie
Junior Member
Join Date: Sep 2007
Old 09-25-2007 , 04:21   Re: Help on a server_cmd
Reply With Quote #4

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.
amxnewbie is offline
Lee
AlliedModders Donor
Join Date: Feb 2006
Old 09-25-2007 , 08:37   Re: Help on a server_cmd
Reply With Quote #5

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); }

Last edited by Lee; 09-25-2007 at 10:10.
Lee is offline
potatis_invalido
BANNED
Join Date: Jul 2007
Location: 0 (world)
Old 09-25-2007 , 10:54   Re: Help on a server_cmd
Reply With Quote #6

Thats a smart way of doing it, Lee.
potatis_invalido is offline
amxnewbie
Junior Member
Join Date: Sep 2007
Old 09-25-2007 , 12:21   Re: Help on a server_cmd
Reply With Quote #7

Thanks, Lee. It works. Cheers!
Really appreciate your kind help. ^_^
amxnewbie 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 16:15.


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