Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Request A code like GetServerCFG
#1
hi
guys i need a code like "GetServerCFG" that Addon use for read data from sv_config.ini

CSHARP Code
  1. public unsafe string GetServerCFG(string Section, string Key, string Default)

i need that to read other extra data form other files as same way Addon use on GetServerCFG .

Thanks
Reply

#2
(11-10-2012, 09:20)raminr63 Wrote: hi
guys i need a code like "GetServerCFG" that Addon use for read data from sv_config.ini

CSHARP Code
  1. public unsafe string GetServerCFG(string Section, string Key, string Default)

i need that to read other extra data form other files as same way Addon use on GetServerCFG .

Thanks

EDIT:
Found it (can't edit my post on 4D1. also forgot the passwort Big Grin )

First of all:
This is NOT a Mod, it is a tool for Mod-Creators.

I made this to sum up every config for a mod into one File. Also it is now reall easy to read from text-files.
Also because it was a great function in the ServerAddon @itsmods


How to use it(Instructions for the File-Layout):
There is only one File: mod_config.ini . It is located in the admin Folder of your Server
If there is none, create it
Use the following Layout:
CODE: SELECT ALL
[Section]
Variablename=Value
Variablename2=Value45

[MyHighJumpMod]
JumpHeight=453
PlayerSpeed=53453

[YourAwsomeMod]
YourMoreAwsomeVariableName=1337

How to add it in your Mod:
Copy this code inside your class:
CODE: SELECT ALL
/**Searched through the mod_config.ini.
*@ param Section The Section where the Variablename is located
*@ param VariableName The Variablename
*@ param DefaultValue This Value is beeing returned when there is no mod_config.ini or the Section could not be found or the VariableName could not be found
*/
static public String getServerConfig(String Section, String VariableName, String DefaultValue)
{
string Path = "admin\\mod_config.ini";

if (!File.Exists(Path))
return DefaultValue;

StreamReader sr = new StreamReader(Path);

bool InSection = false;
for (String line = sr.ReadLine(); line != null; line = sr.ReadLine())
{
//***** SEARCHING THE CORRECT SECTION
if (!InSection && line.StartsWith("["))
{
line = line.Substring(1, line.Length - 2);
if (line.CompareTo(Section) != 0)
continue;
InSection = true;
continue;
}
//***** SEARCHING THE CORRECT SECTION

if (!InSection)
continue;

//***** EXITING WHEN ANOTHER SECTION BEGINS
if (InSection && line.StartsWith("["))
{
return DefaultValue;
}
//***** EXITING WHEN ANOTHER SECTION BEGINS

//***** SEARCHING FOR THE VARIABLE NAME AND GRABBING THE VALUE
if (InSection)
{
String[] splitted = line.Split('=');
if (splitted.Length != 2)
continue;

if (splitted[0].CompareTo(VariableName) != 0)
continue;

return splitted[1];
}
//***** SEARCHING FOR THE VARIABLE NAME AND GRABBING THE VALUE
}
return DefaultValue;
}
Usage in your code:
CODE: SELECT ALL
int jumpheight=getServerConfig("MyHighJumpMod","JumpHeight","45");
[Image: compiling.png][Image: aLKA8og_460sa.gif]
Reply

#3
relay nice one exactly i need that source
very thanks

So bro Can you Change this source or create a new one and same for "SetServerCFG"

very thanks for useful source.
Reply

#4
I have problem with line starter with "//"
as you know to disable a line we have to use "//"

So can someone add a section to this code to skip that line started with "//"

Thank you.
Reply

#5
In pure INI files you use # as a comment, not //.
You might also be interested in http://easycaptu.re/z0tjQ
Reply

#6
(11-10-2012, 18:24)JariZ Wrote: In pure INI files you use # as a comment, not //.
You might also be interested in http://easycaptu.re/z0tjQ

I just wanted to post this Undecided
C++/Obj-Cdeveloper. Neko engine wip
Steam: Click
Reply



Possibly Related Threads…
Thread Author Replies Views Last Post
  Help Code color crosshairs koren30 3 4,015 10-02-2013, 19:26
Last Post: koren30
  Help need help?how to make plugins code hXnarutoXone 12 8,544 09-01-2013, 18:30
Last Post: Bandarigoda123
  Help Need Help with C# code tubwux 2 3,311 08-27-2013, 18:18
Last Post: tubwux
  [Request] Compile this code please dozsa0 4 4,131 08-10-2013, 21:02
Last Post: Nukem
  Compile this code please First_Semyon 12 9,679 08-08-2013, 14:53
Last Post: Bandarigoda123
  Compile please this code First_Semyon 8 5,636 07-28-2013, 01:52
Last Post: First_Semyon
  Code of vector Bloodfocus 1 2,410 06-23-2013, 11:54
Last Post: Yamato
  problem with gsc code CheGuevara 5 5,616 04-20-2013, 15:06
Last Post: Nekochan
Tongue [Request] read if you have a cs:go code:) rawr-saours 5 4,059 04-05-2013, 18:15
Last Post: SuperNovaAO
Smile Help Help me with a code (who knows) NyZzE 2 2,540 04-05-2013, 01:47
Last Post: NyZzE

Forum Jump:


Users browsing this thread:
2 Guest(s)

Forum Powered By MyBB, Theme by © 2002-2024 Melroy van den Berg.