Official Soldat Forums

Server Talk => Scripting Releases => Topic started by: urraka on November 20, 2007, 11:46:56 am

Title: INI Functions
Post 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:

Code: [Select]
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:

Code: [Select]
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:
Code: [Select]
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.
Title: Re: INI Functions
Post by: Kavukamari on November 20, 2007, 08:52:27 pm
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"
Title: Re: INI Functions
Post by: urraka on November 20, 2007, 08:56:40 pm
What misspellings? You must be crazy!
Title: Re: INI Functions
Post by: Kavukamari on November 20, 2007, 09:05:37 pm
Quote
//---   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 «_« »_»
Title: Re: INI Functions
Post by: urraka on November 20, 2007, 09:11:10 pm
Well, the mistakes are already there, and it says I can't touch those lines.
Title: Re: INI Functions
Post by: EnEsCe on November 21, 2007, 04:30:54 am
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)
Title: Re: INI Functions
Post by: Kavukamari on November 27, 2007, 12:50:15 pm
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
Title: Re: INI Functions
Post by: pinOi32 on December 24, 2007, 02:28:05 pm
umm I dont understand what this does.
Title: Re: INI Functions
Post by: urraka on December 24, 2007, 06:20:01 pm
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.
Title: Re: INI Functions
Post by: LORD KILLA on December 21, 2008, 10:01:58 am
Sorry I take this back of the past, but:

I tried to start a server with my script

the code:
Code: [Select]
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
Title: Re: INI Functions
Post by: urraka on December 24, 2008, 06:16:31 pm
You have to use iniLoad before using the other functions...

Code: [Select]
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.
Title: Re: INI Functions
Post by: rayanaga on December 25, 2008, 12:22:30 am
Hmm. Pretty nice and handy INI functions. Sure will make lives a lot easier.
Title: Re: INI Functions
Post by: frosty on July 09, 2010, 07:39:44 pm
i apologise for the bump, but do these functions require a begin and end for each in the script before using?

for example:
Code: (pascal) [Select]

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


Title: Re: INI Functions
Post by: chutem on July 09, 2010, 10:22:32 pm
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.
Title: Re: INI Functions
Post by: frosty on July 09, 2010, 10:25:41 pm
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
Title: Re: INI Functions
Post by: Swompie on July 11, 2010, 03:58:13 am
It's alright how it is, just use it.
Title: Re: INI Functions
Post by: frosty on July 11, 2010, 01:18:45 pm
how? this is why im saying it not defined:

Code: [Select]
unknown identifier "xsplit"

how can i "use" it when its erroring?

whats the code for xsplit?
Title: Re: INI Functions
Post by: Zapper on July 11, 2010, 02:26:41 pm
Ouch, auch, google can eat ya!
http://tinyurl.com/2azm5jm (http://tinyurl.com/2azm5jm)
Title: Re: INI Functions
Post by: chutem on July 11, 2010, 06:49:56 pm
The xsplit code is in the attached pas file. You will need to copy that over too.
Title: Re: INI Functions
Post by: frosty on July 11, 2010, 07:46:18 pm
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
Code: [Select]
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

Code: [Select]
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?
Title: Re: INI Functions
Post by: chutem on July 12, 2010, 02:11:14 am
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)
Title: Re: INI Functions
Post by: Swompie on July 12, 2010, 07:27:06 am
Requirements: xSplit
Title: Re: INI Functions
Post by: frosty on July 12, 2010, 01:03:14 pm
tx guys :D