0 Members and 3 Guests are viewing this topic.
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;function RandomizeMaps(MapList: string):boolean;var newfile: string; lines: TStringArray; i, c, rnd: integer;begin if FileExists(MapList + '.txt') = false then  Result:=false else begin  Result:=true;  lines := xsplit(ReadFile(MapList + '.txt'), chr(13) + chr(10));  c := GetArrayLength(lines) - 1;  for i := 0 to GetArrayLength(lines) - 1 do begin   rnd := Random(0, c);   newfile := newfile + lines[rnd] + chr(13) + chr(10);   lines[rnd] := lines[c];   c := c - 1;  end;  i := 0;  while FileExists(MapList + IntToStr(i) + '.txt') = true do   i := i + 1;  WriteFile(MapList + IntToStr(i) + '.txt', newfile);  Command('/loadlist ' + MapList + IntToStr(i)); end;end;function RandomMap(MapList: string; Prefix: string):boolean;var lines: TStringArray; numlines: integer; map: string;begin if FileExists(MapList + '.txt') = false then  Result:=false else begin  Result:=true;  lines:=xsplit(ReadFile(MapList + '.txt'), chr(13) + chr(10));  numlines:=StrPos(lines,chr(13) + chr(10));  map:=GetPiece(lines, chr(13) + chr(10), random(1, numlines) - 1);  if (map <> CurrentMap) then   Command('/map ' + map); end;end;//procedure ActivateServer();//begin// RandomizeMaps('mapslist');// WriteConsole(0,'Maps Randomized',RGB(0,0,0));// WriteLn('Maps Randomized, File "mapslist0.txt" made.');// RandomMap('mapslist_c-s0');//end;////function OnCommand(ID:Byte;Text:string):boolean;//begin// Result:=false;// if Text = '/random' then begin//  RandomMap('mapslist_ctf');// end;//end;
function OnCommand(ID: byte; Text: string): boolean;var mapfile, newFile: string; lines: TStringArray; i, c, rnd: integer;begin if StrPos('/randomise', LowerCase(Text)) = 1 then begin mapfile := GetPiece(Text, ' ', 1); if FileExists(mapfile + '.txt') = false then begin WriteLn('The file doesn't exist. Using the default maps file: "mapslist.txt"'); mapfile := 'mapslist'; end; if FileExists(mapfile + '.txt') = false then begin WriteLn('Couldn't find the maps file.'); exit; end; lines := xsplit(ReadFile(mapfile + '.txt'), chr(13) + chr(10)); c := GetArrayLength(lines) - 1; for i := 0 to GetArrayLength(lines) - 1 do begin rnd := Random(0, c); newFile := newFile + lines[rnd] + chr(13) + chr(10); lines[rnd] := lines[c]; c := c - 1; end; // WriteFile doesn't work well overwriting files, so I do this: i := 0; while FileExists(mapfile + IntToStr(i) + '.txt') = true do i := i + 1; WriteFile(mapfile + IntToStr(i) + '.txt', newFile); // reload the list for it to actually make a difference in the game. Command('/loadlist ' + mapfile + IntToStr(i)); // with no .txt! end;end;
function RandomizeMaps(MapList: string):boolean;var newfile: string; lines: TStringArray; i, c, rnd: integer;begin if FileExists(MapList + '.txt') = false then begin  Result:=false;  exit; end; if FileExists(MapList + '.txt') then begin  Result:=true;  lines := xsplit(ReadFile(MapList + '.txt'), chr(13) + chr(10));  c := GetArrayLength(lines) - 1;  for i := 0 to GetArrayLength(lines) - 1 do begin   rnd := Random(0, c);   newfile := newfile + lines[rnd] + chr(13) + chr(10);   lines[rnd] := lines[c];   c := c - 1;  end;  i := 0;  while FileExists(MapList + IntToStr(i) + '.txt') do begin   i := i + 1;   WriteFile(MapList + IntToStr(i) + '.txt', newfile);   Command('/loadlist ' + MapList + IntToStr(i));  end; end;end;function RandomMap(MapList: string):boolean;var lines: integer; liner: string;begin if FileExists(MapList + '.txt') = false then begin  Result:=false;  exit; end; if FileExists(MapList + '.txt') then begin  Result:=true;  lines:=StrPos(ReadFile(MapList + '.txt'), chr(13) + chr(10));  liner:=GetPiece(ReadFile(MapList + '.txt'), chr(13) + chr(10), random(0, lines-1));  if (liner = CurrentMap) then exit;  if (liner = CurrentMap) = false then Command('/map '+liner); end;end;
procedure ActivateServer();begin RandomizeMaps('mapslist_dm'); WriteConsole(0,'Maps Randomized',RGB(0,0,0)); RandomMap('mapslist_dm0');end;
if FileExists(MapList + '.txt') = false then begin Result:=false; exit; end; if FileExists(MapList + '.txt') then begin
if FileExists(MapList + '.txt') = false then begin Result:=false; exit; end else begin
if (liner = CurrentMap) then exit; if (liner = CurrentMap) = false then Command('/map '+liner);
if (liner = CurrentMap) then exit else Command('/map '+liner);
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;function RandomizeMaps(MapList: string):boolean;var newfile: string; lines: TStringArray; i, c, rnd: integer;begin if FileExists(MapList + '.txt') = false then begin Result:=false; exit; end; if FileExists(MapList + '.txt') then begin Result:=true; lines := xsplit(ReadFile(MapList + '.txt'), chr(13) + chr(10)); c := GetArrayLength(lines) - 1; for i := 0 to GetArrayLength(lines) - 1 do begin rnd := Random(0, c); newfile := newfile + lines[rnd] + chr(13) + chr(10); lines[rnd] := lines[c]; c := c - 1; end; i := 0; while FileExists(MapList + IntToStr(i+1) + '.txt') = false do begin i := i + 1; WriteFile(MapList + IntToStr(i) + '.txt', newfile); Command('/loadlist ' + MapList + IntToStr(i)); end; if FileExists(MapList + IntToStr(i) + '.txt') then exit; end;end;function RandomMap(MapList: string):boolean;var lines: integer; liner: string;begin if FileExists(MapList + '.txt') = false then begin Result:=false; exit; end; if FileExists(MapList + '.txt') then begin Result:=true; lines:=StrPos(ReadFile(MapList + '.txt'), chr(13) + chr(10)); liner:=GetPiece(ReadFile(MapList + '.txt'), chr(13) + chr(10), random(0, lines-1)); if (liner = CurrentMap) then exit; if (liner = CurrentMap) = false then Command('/map '+liner); end;end;procedure ActivateServer();begin RandomizeMaps('mapslist_c-s'); WriteConsole(0,'Maps Randomized',RGB(0,0,0)); RandomMap('mapslist_c-s0');end;function OnCommand(ID:Byte;Text:string):boolean;begin Result:=false; if Text = '/rtest' then begin RandomizeMaps('mapslist_ctf'); SayToPlayer(ID,'blah'); RandomMap('mapslist_ctf0'); end;end;
function RandomizeMaps(MapList: string):boolean;var newfile: string; lines: TStringArray; i, c, rnd: integer;begin if FileExists(MapList + '.txt') = false then Result:=false else begin Result:=true; lines := xsplit(ReadFile(MapList + '.txt'), chr(13) + chr(10)); c := GetArrayLength(lines) - 1; for i := 0 to GetArrayLength(lines) - 1 do begin rnd := Random(0, c); newfile := newfile + lines[rnd] + chr(13) + chr(10); lines[rnd] := lines[c]; c := c - 1; end; i := 0; while FileExists(MapList + IntToStr(i) + '.txt') = true do i := i + 1; WriteFile(MapList + IntToStr(i) + '.txt', newfile); Command('/loadlist ' + MapList + IntToStr(i)); end;end;
function RandomMap(MapList: string):boolean;var lines: TStringArray; map: string;begin if FileExists(MapList + '.txt') = false then Result:=false else begin Result:=true; lines:=xsplit(ReadFile(MapList + '.txt'), chr(13) + chr(10)); map:=lines[random(0, GetArrayLength(lines) - 1)]; if (map <> CurrentMap) then Command('/map ' + map); end;end;
function oor(const Words: string):array of string;var numWords, i: integer;begin numWords:=StrPos(Words,' ') + 1; for i:=0 to numWords do Result:=GetPiece(Words, ' ', i);end;
if ContainsString(mapstring,oor('ctf inf htf')) then maptype:=team;
var aflag, bflag, inflag: single; PX, PY: array[1..32] of single;begin for i:=1 to 32 do if GetPlayerXY(i,PX[i],PY[i]) = oor(aflag+' '+bflag+' '+inflag) then saytoplayer(i,'WOOTFLAG!!!');end;