Official Soldat Forums
Server Talk => Scripting Releases => Topic started by: urraka on November 20, 2007, 11:46:56 am
-
Script Name: INI Functions
Script Description: Has functions that parses INI files and lets you read/save/modify/add/delete entries.
Original Author(s): PerroAZUL
Core Version: 2.6.3
Requirements: xSplit
I made some INI functions that some may find usefull, so I shall share it with the ladies.
It consists of this functions:
function iniLoad(FileName: string): TINIFile;
procedure iniSave(FileName: string; var iniFile: TINIFile);
function iniGetValue(var iniFile: TINIFile; section, key, errorResult: string): string;
procedure iniSetValue(var iniFile: TINIFile; section, key, value: string);
procedure iniDeleteSection(var iniFile: TINIFile; section: string);
procedure iniDeleteKey(var iniFile: TINIFile; section, key: string);
procedure iniWrite(FileName, section, key, value: string);
I don't think they need any more explanation than what a TINIFile is:
type TSection = record
Name: string;
Keys: array of string;
end;
type TINIFile = record
Sections: array of TSection;
end;
The section names are case insensitive. I might add some other functions later, like iniFindSection, which would return the section index in TINIFile.Sections array, and iniFindKey, which would do the same but for TSection.Keys. Not a big deal but could save some writing.
If you happen to find any bug Report!.
I'll add an example:
var ini: TINIFile;
ini := iniLoad('soldat.ini');
WriteLn(iniGetValue(ini, 'network', 'Greeting_Message', ''));
iniSetValue(ini, 'network', 'Greeting_Message', 'Hello!');
iniSetValue(ini, 'custom', 'var', 'x'); // this will add the section [custom] with "var=x"
iniSetValue(ini, 'network', 'lala', '1'); // this will add "lala=1" in [NETWORK]
iniSave('soldat.ini', ini); // must call to save changes
Edit: Found a stupid bug, fixed it.
-
are we allowed to fix misspellings in the comments? :)
nice script
btw, you should make a "LastDelete: array[1..*your undoamount const*]" variable and whenever you delete a section or a key, it's value would be saved in the next open spot wait nevermind, person could just not save the ini, or you could make something to say "Cannot overwrite game INIs, please choose another name"
-
What misspellings? You must be crazy!
-
//---Â Â You may use or modify this script to satisfy whatever
//---Â Â needs or feels your ass.
//---Â Â This commented lines must remain untouched.
//---Â Â If you somehow are able to make money with this code
//---Â Â or part of it, you will be cought by PerroMAFIA and
//---Â Â your ass will be raped.
(and lol, you said "ass" many many times)
and I might be crazy, I'm not sure «_« »_»
-
Well, the mistakes are already there, and it says I can't touch those lines.
-
Sticky: Release Post Template (http://forums.soldat.pl/index.php?topic=7409.0)
Sticky: Release Post Template (http://forums.soldat.pl/index.php?topic=7409.0)
Sticky: Release Post Template (http://forums.soldat.pl/index.php?topic=7409.0)
Sticky: Release Post Template (http://forums.soldat.pl/index.php?topic=7409.0)
Sticky: Release Post Template (http://forums.soldat.pl/index.php?topic=7409.0)
-
Sticky: Release Post Template (http://forums.soldat.pl/index.php?topic=7409.0)
Sticky: Release Post Template (http://forums.soldat.pl/index.php?topic=7409.0)
Sticky: Release Post Template (http://forums.soldat.pl/index.php?topic=7409.0)
Sticky: Release Post Template (http://forums.soldat.pl/index.php?topic=7409.0)
Sticky: Release Post Template (http://forums.soldat.pl/index.php?topic=7409.0)
yeah, I was thinking that too... (except maybe with less repitition) I didn't have any trouble placing/using the script, but other ppl might
-
umm I dont understand what this does.
-
umm I dont understand what this does.
It doesn't do anything, it's just a bunch of functions that you might find usefull if you make a script that has to save/load information.
-
Sorry I take this back of the past, but:
I tried to start a server with my script
the code:function OnCommand(ID: Byte; Text: string): boolean;
begin
var
ini: TINIFile;
if (GetPiece(Text, ' ',1) = '/editwep') then begin
iniSetValue(ini, GetPiece (Text,' ',3), GetPiece (Text,' ',4), GetPiece (Text,' ',5));
iniSave(GetPiece (Text,' ',2), ini); // must call to save changes
end;
if (GetPiece(Text, ' ', 1) = '/dis') then begin
SetWeaponActive(0, GetPiece(Text,' ', 2), false);
end;
if (GetPiece(Text, ' ', 1) = '/en') then begin
SetWeaponActive(0, GetPiece(Text,' ', 2), true);
end;
if (GetPiece(Text, ' ', 1) = '/disID') then begin
SetWeaponActive(GetPiece(Text,' ',2),GetPiece(Text,' ',3), false);
end;
if (GetPiece(Text, ' ', 1) = '/enID') then begin
SetWeaponActive(GetPiece(Text,' ',2),GetPiece(Text,' ',3), true);
end;
Result := false; // Return true if you want to ignore the command typed.
end;
It should enable to edit [edit/enadle/disable/enable for a special player/disable for a special player] weapons
-
You have to use iniLoad before using the other functions...
function OnCommand(ID: Byte; Text: string): boolean;
var
ini: TINIFile;
begin
if (GetPiece(Text, ' ',1) = '/editwep') then begin
ini := iniLoad('YOURINI.INI');
iniSetValue(ini, GetPiece (Text,' ',3), GetPiece (Text,' ',4), GetPiece (Text,' ',5));
iniSave(GetPiece (Text,' ',2), ini); // must call to save changes
end;
You have the 'var' and 'begin' messed up too, i think.
-
Hmm. Pretty nice and handy INI functions. Sure will make lives a lot easier.
-
i apologise for the bump, but do these functions require a begin and end for each in the script before using?
for example:
procedure iniWrite(FileName, section, key, value: string);
begin
end;
function Oncommand..etc
begin
if Text = '/save' then Iniwrite('myfile.ini', 'profits', 'cash', inttostr(Tcash))
end;
is the begin and end all it needs before using or do i need some more code between the begin and end
please dont flame me, i dont see any point in starting a new topic just to ask about an older topic
-
You need to download the attached ini.pas script, which has the actual code for the functions in it.
Copy the functions you want to use into your script, then you can call them like any other function.
-
many thanks :) didnt notice the attachment
From: July 10, 2010, 10:28:27 pm
found a bug
what var type is xsplit supposed to be in IniLoad? its not defined
-
It's alright how it is, just use it.
-
how? this is why im saying it not defined:
unknown identifier "xsplit"
how can i "use" it when its erroring?
whats the code for xsplit?
-
Ouch, auch, google can eat ya!
http://tinyurl.com/2azm5jm (http://tinyurl.com/2azm5jm)
-
The xsplit code is in the attached pas file. You will need to copy that over too.
-
nope, i copied the whole script, and ive even looked at it, there is NO "procedure/function xsplit();" (has anyone even tried compiling the attached file? see below) all i see is
xsplit:= (whatever it was)
theres no xsplit in vars, neither is there a function or procedure for it before it is used, as a result:
the ini.pas fails to compile for the exact problem im having
inifunctions -> [Error] (16:11): Unknown identifier 'xsplit'
so can someone plz post the code for the xsplit function/procedure whatever it is?
has anyone successfully compiled the attached script? if so then why the the hell is my compiler being a douche?
-
My mistake, it isn't in the file. I know it is on the forums somewhere though...
...Here it is. (http://forums.soldat.pl/index.php?topic=12742.0)
-
Requirements: xSplit
-
tx guys :D