Raised This Month: $ Target: $400
 0% 

variable from server config


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
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 #1

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 #2

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
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