Raised This Month: $ Target: $400
 0% 

variable from server config


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
sparkey
Senior Member
Join Date: May 2010
Old 05-06-2010 , 09:30   variable from server config
Reply With Quote #1

Hi,

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

Best regards
sparkey is offline
drekes
Veteran Member
Join Date: Jul 2009
Location: Vault 11
Old 05-06-2010 , 10:13   Re: variable from server config
Reply With Quote #2

could you give an example?
__________________

Quote:
Originally Posted by nikhilgupta345 View Post
You're retarded.
drekes is offline
Send a message via MSN to drekes
sparkey
Senior Member
Join Date: May 2010
Old 05-06-2010 , 10:48   Re: variable from server config
Reply With Quote #3

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
sparkey is offline
drekes
Veteran Member
Join Date: Jul 2009
Location: Vault 11
Old 05-06-2010 , 11:07   Re: variable from server config
Reply With Quote #4

do you register it in another plugin?
__________________

Quote:
Originally Posted by nikhilgupta345 View Post
You're retarded.
drekes is offline
Send a message via MSN to drekes
sparkey
Senior Member
Join Date: May 2010
Old 05-06-2010 , 11:14   Re: variable from server config
Reply With Quote #5

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
sparkey is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 05-06-2010 , 11:18   Re: variable from server config
Reply With Quote #6

The cvar needs to be registered before it will work
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
wrecked_
Veteran Member
Join Date: Jan 2010
Location: New York (GMT-5)
Old 05-07-2010 , 01:10   Re: variable from server config
Reply With Quote #7

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.
__________________
[ Paid Requests ]
DO NOT PM ME ABOUT BLOCKMAKER
NO PRIVATE SUPPORT

Last edited by wrecked_; 05-07-2010 at 01:12.
wrecked_ is offline
sparkey
Senior Member
Join Date: May 2010
Old 05-08-2010 , 15:10   Re: variable from server config
Reply With Quote #8

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
sparkey is offline
wrecked_
Veteran Member
Join Date: Jan 2010
Location: New York (GMT-5)
Old 05-08-2010 , 16:32   Re: variable from server config
Reply With Quote #9

You just confused me. Could you explain it a little clearer, please?
__________________
[ Paid Requests ]
DO NOT PM ME ABOUT BLOCKMAKER
NO PRIVATE SUPPORT
wrecked_ is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 05-08-2010 , 16:42   Re: variable from server config
Reply With Quote #10

Wow, this makes no sense. All you need to do is register the cvar in the plugin. It's super easy.
__________________
fysiks 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 03:35.


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