This has been very useful to me, so i figured I would post it here. It loads the whole weapons.ini into arrays that are easily and quickly used in-script, without the memory leak of readini();
const
sdamage = 0;
sfireinterval = 1;
sammo = 2;
sreloadtime = 3;
sspeed = 4;
sbulletstyle = 5;
sstartuptime = 6;
sbink = 7;
smovementacc = 8;
srecoil = 9;
var
weapons: array[0..16] of array[0..9] of integer;
procedure LoadWeapons();
var wepfile: array of string; wepstart: array of integer; curwepnum: byte; curstat: string; i,ii,l: integer;
begin
wepfile := xsplit(readfile('weapons.ini'),(chr(13)+chr(10)));
curwepnum := 1;
setarraylength(wepstart,17);
for l := 0 to 16 do begin
if (l <> 8) AND (l <> 12) AND (l <> 13) AND (l <> 16) then wepstart[l] := getstringindex('['+weaponnamebynum(l)+']',wepfile);
if l = 8 then wepstart[l] := getstringindex('[Barret M82A1]',wepfile);
if l = 12 then wepstart[l] := getstringindex('[Rambo Bow]',wepfile);
if l = 13 then wepstart[l] := getstringindex('[Flamed Arrows]',wepfile);
if l = 16 then wepstart[l] := getstringindex('[M72 LAW]',wepfile);
end;
for i := 0 to 16 do begin
for ii := wepstart[i]+1 to wepstart[i]+10 do begin
curstat := getpiece(wepfile[ii],'=',0);
if curstat <> '' then begin
weapons[i][ii-wepstart[i]-1] := strtoint(getpiece(wepfile[ii],'=',1));
end;
end;
end;
writeln('Weapons Loaded Successfully');
end;
For example to get the damage of the barret you would do:
weapons[8][sdamage];