Author Topic: procedure LoadWeapons();  (Read 1124 times)

0 Members and 1 Guest are viewing this topic.

Offline Hacktank

  • Camper
  • ***
  • Posts: 462
  • Soldat Scripter
    • HTZRPG
procedure LoadWeapons();
« on: December 12, 2009, 04:29:24 pm »
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();

Code: [Select]
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:
Code: [Select]
weapons[8][sdamage];


Offline Gizd

  • Flagrunner
  • ****
  • Posts: 586
  • (Re)tired
    • Eat-this! community site
Re: procedure LoadWeapons();
« Reply #1 on: December 12, 2009, 05:02:37 pm »
Dynamic arrays have some side effects as far as I know...