0 Members and 1 Guest are viewing this topic.
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;
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;
function xsplit(const source: string; const delimiter: string):TStringArray;vari,x,d:integer;s:string;begind:=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;