AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   variable from server config (https://forums.alliedmods.net/showthread.php?t=126173)

sparkey 05-06-2010 09:30

variable from server config
 
Hi,

How do i get a self defined variable from the default server.cfg?

Best regards

drekes 05-06-2010 10:13

Re: variable from server config
 
could you give an example?

sparkey 05-06-2010 10:48

Re: variable from server config
 
Thanks for your quick answer.

From cstrike/server.cfg
Code:

hlds_serverid 13
And then in the amxx file i try to get the variable with the following
Code:

new serverid;
get_cvar_num("hlds_serverid");

That config file is being loaded when i start hlds

drekes 05-06-2010 11:07

Re: variable from server config
 
do you register it in another plugin?

sparkey 05-06-2010 11:14

Re: variable from server config
 
nah probably not :)

I am writing my own plugin and are just trying to get a cvar from the main server config that is loaded with hlds but maybe its not as easy as i thought ;p

YamiKaitou 05-06-2010 11:18

Re: variable from server config
 
The cvar needs to be registered before it will work

wrecked_ 05-07-2010 01:10

Re: variable from server config
 
Untested. If this doesn't work, type "amx_showrcon amxx list" without the quotes in your console and output the result in [code] tags.
Code:
#include <amxmodx> new const filename[] = "yourfile.cfg" public plugin_init() {     register_plugin( "Cvar Config Example", "1.0", "Wrecked" )         if( !Read_Cvar_File() )     {         set_fail_state( "Error loading config file!" )     } } Read_Cvar_File() {     if( !file_exists( filename ) )     {         return 0;     }         new f = fopen( filename, "r" )         if( !f )     {         return 0;     }         new info[64]     new cvarname[32]     new val[8]         while( !feof( f ) )     {         fgets( f, info, 63 )         trim( info )                 if( info[0] == ';' || !info[0] )         {             continue;         }                 parse( info, cvarname, 31, val, 7 )                 register_cvar( cvarname, val )     }         fclose( f )         return 1; }

The config file should look like this and be located in your cstrike dir. If you'd like it in your config directory then just tell me. You asked for server.cfg so I figured you'd want it in here.
Code:

;cvar_name value
;semicolon prefixes are skipped

hero_health 250
other_cvar 90

To test it you can just type "amx_cvar hero_health" or whatever your cvar name and see if it gives you the value or tells you if it's an invalid cvar.

Sorry if I made any careless typos in the code.

sparkey 05-08-2010 15:10

Re: variable from server config
 
Thx for your good answer and code but does not that code loop through the entire config grepping everything inside cause i got alot of stuff in that config :)?

Is there any way to get a startup variable which i define when i run hlds_run for example?

Thx again for your time

wrecked_ 05-08-2010 16:32

Re: variable from server config
 
You just confused me. Could you explain it a little clearer, please?

fysiks 05-08-2010 16:42

Re: variable from server config
 
Wow, this makes no sense. All you need to do is register the cvar in the plugin. It's super easy.


All times are GMT -4. The time now is 03:35.

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