All pastes #781357 Raw Edit

Untitled

public text v1 · immutable
·published 2007-11-18 20:58 UTC
rendered paste body
const
  COORDSFILE = '_coords.txt';

var
  coords: array of coord;
  count: byte;
  broadcast: boolean;


procedure saveToFile(map: string);
var
  i: byte;
  temp: string;
begin
  temp := '';
    
  for i := 0 to count do begin
    if (coords[i].lable = '///DELETED///') or (coords[i].lable = nil) then 
      continue;
      
    temp := temp + floatToStr(coords[i].x) + '///' + floatToStr(coords[i].y) + '///' + coords[i].lable + '///'+#10;
  end;
  
  writeFile(map+COORDSFILE, temp);
  writeln('[Teleport] Saved to '+map+COORDSFILE)
end;
    
procedure loadCoords(mapname: string);
var
  fileContents, name: string;
  parts: tStringArray;
  x, y: single;
  i: byte;
begin
  if not fileExists(mapname+COORDSFILE) then begin
    writeFile(mapname+COORDSFILE, ' ');
  end;
  
  fileContents := readFile(mapname+COORDSFILE);
  parts := xSplit(fileContents, #10);
  count := 0;
  
  for i := 0 to getArrayLength(coords) - 1 do begin
    if maskCheck(parts[i], '*///*///*///*') then begin
      x := strToFloat(getPiece(parts[i], '///', 0));
      y := strToFloat(getPiece(parts[i], '///', 1));
      name := getPiece(parts[i], '///', 2);
    
      coords[count].lable := name;
      coords[count].x     := x;
      coords[count].y     := y;    
    
      count := count + 1;
      setArrayLength(coords, count+1);

    end;
  end;
    
  writeln('[Teleport] Loaded ' + intToStr(count) + ' coordinates from ' + mapname+COORDSFILE);
end;

procedure ActivateServer();
begin
  setArrayLength(coords, 1);
  broadcast := false;
  
  writeln('[Teleport] Looking for ' + COORDSFILE + '...');
  if fileExists(COORDSFILE) then begin
    writeln('[Teleport] Loading coordinates...');
  
    if currentMap = nil then begin
      loadCoords('init');
    end else begin
      loadCoords(currentMap);
    end;
    
    writeln('[Teleport] Loading complete.');
  end else begin
    writeln('[Teleport] Failed loading ' + COORDSFILE + ': File does not exist Creating...!');
    if currentMap = nil then begin
      writeFile('init'+COORDSFILE, ' ');
    end else begin
      writeFile(currentMap+COORDSFILE, ' ');
    end;  
    
  end;
end;