Author Topic: Map Randomizer (nothing to do with Avarax's script)  (Read 764 times)

0 Members and 1 Guest are viewing this topic.

Offline Kavukamari

  • Camper
  • ***
  • Posts: 435
  • 3.14159265358979, mmm... pi
Map Randomizer (nothing to do with Avarax's script)
« on: December 04, 2007, 09:10:49 pm »
I think this is a valid script, but whenever I try the command to use the script it says:

  • [Error] MapRandom -> (OnCommand): Out Of Range


and Im not sure why it is out of range...
Code: [Select]
procedure RandomizeMaps(const MapList: string; const WriteName: string);
var
  i, lines: integer;
  OldString: string;
  NewString: string;
  Used: array of boolean;
begin
  OldString:=ReadFile(MapList+'.txt');
  lines:=StrPos(OldString,chr(13)+chr(10));
  for i:=0 to lines do Used[i]:=false;
  i:=Random(0,lines);
  if not Used[i] then begin
    if NewString = '' then begin
      NewString:=GetPiece(OldString,chr(13)+chr(10),i);
      Used[i]:=true;
    end else begin
      NewString:=NewString+chr(13)+chr(10)+GetPiece(OldString,chr(13)+chr(10),i);
      Used[i]:=true;
    end;
  end;
  WriteFile(WriteName+'.txt',NewString);
  Command('/loadlist '+WriteName);
  for i:=1 to lines do begin
    Used[i]:=false;
  end;
end;

function OnCommand(ID:Byte;Text:string):boolean;
begin
  if text = '/rantest' then RandomizeMaps('mapslist','mlist');
end;
« Last Edit: December 04, 2007, 09:22:22 pm by Kavukamari »
"Be mindful of fame, show a mighty courage, watch against foes. Nor shalt thou lack what thou desirest, if with thy life thou hast comest out from that heroic task."

Offline urraka

  • Soldat Developer
  • Flagrunner
  • ******
  • Posts: 703
Re: Map Randomizer (nothing to do with Avarax's script)
« Reply #1 on: December 04, 2007, 10:44:25 pm »
analize this code:

Code: [Select]
procedure [...]
var
  lines: TStringArray;
  i: integer;
begin
  lines := xsplit(ReadFile(MapList+'.txt'), chr(13)+chr(10));
  for i := 0 to GetArrayLength(lines) - 1 do
  begin
    // here u use line[i] for the line
  end;
end;
urraka

Offline Kavukamari

  • Camper
  • ***
  • Posts: 435
  • 3.14159265358979, mmm... pi
Re: Map Randomizer (nothing to do with Avarax's script)
« Reply #2 on: December 05, 2007, 02:00:34 pm »
why do I need XSplit?

Date Posted: December 04, 2007, 11:19:46 pm
Code: [Select]
function xsplit(const source: string; const delimiter: string):TStringArray;
var
i,x,d:integer;
s:string;
begin
d:=length(delimiter);
x:=0;
i:=1;
SetArrayLength(Result,1);
while(i<=length(source)) do begin
s:=Copy(source,i,d);   
if(s=delimiter) then begin
inc(i,d);
inc(x,1);
SetArrayLength(result,x+1);
end else begin       
result[x]:= result[x]+Copy(s,1,1);
inc(i,1);
end;
end;
end;

procedure RandomizeMaps(const MapList: string; const WriteName: string);
var
  i: integer;
  lines: TStringArray;
  OldString: string;
  NewString: string;
  Used: array[0..1] of boolean;
begin
  OldString:=ReadFile(MapList+'.txt');
  lines:=XSplit(OldString,chr(13)+chr(10));
  SetArrayLength(Used,GetArrayLength(lines)-1);
  for i:=0 to GetArrayLength(Used) do Used[i]:=false;
  i:=Random(0,GetArrayLength(lines)-1);
  if not Used[i] then begin
    if NewString = '' then begin
      NewString:=GetPiece(OldString,chr(13)+chr(10),i);
      Used[i]:=true;
    end else begin
      NewString:=NewString+chr(13)+chr(10)+GetPiece(OldString,chr(13)+chr(10),i);
      Used[i]:=true;
    end;
  end;
  WriteFile(WriteName+'.txt',NewString);
  Command('/loadlist '+WriteName);
  for i:=0 to GetArrayLength(lines)-1 do begin
    Used[i]:=false;
  end;
end;

function OnCommand(ID:Byte;Text:string):boolean;
begin
  if text = '/rantest' then RandomizeMaps('mapslist','mlist');
end;

Now it says:

 
  • [Error] MapRandom -> (OnCommand): Could not call proc


???
« Last Edit: December 05, 2007, 02:11:28 pm by Kavukamari »
"Be mindful of fame, show a mighty courage, watch against foes. Nor shalt thou lack what thou desirest, if with thy life thou hast comest out from that heroic task."