SCAR Code:
{*******************************************************************************
Procedure LoadUs;
By: Yakman
Description: Loads players from the char file into the player array.
*******************************************************************************}
procedure LoadUs;
var
f, CharsFile: Integer;
CharsFileString: string;
begin
if (FileName = '') then filename := 'chars';
CharsFile := OpenFile(AppPath + filename + '.dat', False);
if (CharsFile < 0) then
begin
SaveUs;
CharsFile := OpenFile(AppPath + filename + '.dat', False);
if (CharsFile < 0) then
begin
WriteLn('Error Loading Chars');
Exit;
end
end
ReadFileString(CharsFile, CharsFileString, FileSize(CharsFile));
CloseFile(CharsFile);
SetArrayLength(Players, CountPlayers(CharsFileString));
HowManyPlayers := GetArrayLength(players);
for f := 0 to GetArrayLength(players) - 1 do
begin
players[f].Name := Between('name' + IntToStr(f) + '=', chr(13), CharsFileString);
players[f].Pass := Between('pass' + IntToStr(f) + '=', chr(13), CharsFileString);
players[f].Nick := Between('nick' + IntToStr(f) + '=', chr(13), CharsFileString);
players[f].Active := StrToBool(Between('active' + IntToStr(f) + '=', chr(13), CharsFileString));
players[f].Loc := Between('loc' + IntToStr(f) + '=', chr(13), CharsFileString);
players[f].Skill := Between('skill' + IntToStr(f) + '=', chr(13), CharsFileString);
try
players[f].WaitTime := StrToInt(Between('waittime' + IntToStr(f) + '=', chr(13), CharsFileString));
except
end
try
players[f].Fight := StrToBool(Between('fight' + IntToStr(f) + '=', chr(13), CharsFileString));
except
end
try
players[f].Boolean1 := StrToBool(Between('boolean1' + IntToStr(f) + '=', chr(13), CharsFileString));
except
end
try
players[f].Boolean2 := StrToBool(Between('boolean2' + IntToStr(f) + '=', chr(13), CharsFileString));
except
end
try
players[f].Boolean3 := StrToBool(Between('boolean3' + IntToStr(f) + '=', chr(13), CharsFileString));
except
end
try
players[f].Integer1 := StrToInt(Between('integer1' + IntToStr(f) + '=', chr(13), CharsFileString));
except
end
try
players[f].Integer2 := StrToInt(Between('integer2' + IntToStr(f) + '=', chr(13), CharsFileString));
except
end
try
players[f].Integer3 := StrToInt(Between('integer3' + IntToStr(f) + '=', chr(13), CharsFileString));
except
end
try
players[f].Integer4 := StrToInt(Between('integer4' + IntToStr(f) + '=', chr(13), CharsFileString));
except
end
players[f].String1 := Between('string1' + IntToStr(f) + '=', chr(13), CharsFileString);
players[f].String2 := Between('string2' + IntToStr(f) + '=', chr(13), CharsFileString);
players[f].String3 := Between('string3' + IntToStr(f) + '=', chr(13), CharsFileString);
try
players[f].Extended1 := StrToFloat(Between('extended1' + IntToStr(f) + '=', chr(13), CharsFileString));
except
end
try
players[f].Extended2 := StrToFloat(Between('extended2' + IntToStr(f) + '=', chr(13), CharsFileString));
except
end
try
players[f].Extended3 := StrToFloat(Between('extended3' + IntToStr(f) + '=', chr(13), CharsFileString));
except
end
end
CloseFile(CharsFile);
end;
{*******************************************************************************
procedure SaveUs;
By: Yakman
Description: Saves users from the player array into the chars file
*******************************************************************************}
procedure SaveUs;
var
f, CharsFile: Integer;
begin
if (FileName = '') then FileName := 'Chars';
CharsFile := RewriteFile(AppPath + FileName + '.dat', False);
for f := 0 to GetArrayLength(players) - 1 do
begin
WriteFileString(charsfile, 'name' + IntToStr(f) + '=' + players[f].name +
Chr(13));
WriteFileString(charsfile, 'pass' + IntToStr(f) + '=' + players[f].pass
+ Chr(13));
WriteFileString(charsfile, 'nick' + IntToStr(f) + '=' + players[f].nick
+ Chr(13));
WriteFileString(charsfile, 'active' + IntToStr(f) + '=' +
BoolToStr(players[f].active) + Chr(13));
if (FormOption[0]) then
WriteFileString(charsfile, 'loc' + IntToStr(f) + '=' +
players[currentplayer].loc + Chr(13));
if (FormOption[1]) then
WriteFileString(charsfile, 'skill' + IntToStr(f) + '=' +
players[currentplayer].skill + Chr(13));
if (FormOption[2]) then
WriteFileString(charsfile, 'waittime' + IntToStr(f) + '=' +
IntToStr(players[currentplayer].waittime) + Chr(13));
if (FormOption[3]) then
WriteFileString(charsfile, 'fight' + IntToStr(f) + '=' +
BoolToStr(players[currentplayer].fight) + Chr(13));
if (FormOption[4]) then
WriteFileString(charsfile, 'boolean1' + IntToStr(f) + '=' +
BoolToStr(players[currentplayer].boolean1) + Chr(13));
if (FormOption[5]) then
WriteFileString(charsfile, 'boolean2' + IntToStr(f) + '=' +
BoolToStr(players[currentplayer].boolean2) + Chr(13));
if (FormOption[6]) then
WriteFileString(charsfile, 'boolean3' + IntToStr(f) + '=' +
BoolToStr(players[currentplayer].boolean3) + Chr(13));
if (FormOption[7]) then
WriteFileString(charsfile, 'integer1' + IntToStr(f) + '='
+ IntToStr(players[currentplayer].integer1) + Chr(13));
if (FormOption[8]) then
WriteFileString(charsfile, 'integer2' + IntToStr(f) + '='
+ IntToStr(players[currentplayer].integer2) + Chr(13));
if (FormOption[9]) then
WriteFileString(charsfile, 'integer3' + IntToStr(f) +
'=' + IntToStr(players[currentplayer].integer3) +
Chr(13));
if (FormOption[10]) then
WriteFileString(charsfile, 'integer4' + IntToStr(f)
+
'=' + IntToStr(players[currentplayer].integer4) +
Chr(13));
if (FormOption[11]) then
WriteFileString(charsfile, 'string1' + IntToStr(f)
+ '=' + players[currentplayer].string1 + Chr(13));
if (FormOption[12]) then
WriteFileString(charsfile, 'string2' +
IntToStr(f) + '=' +
players[currentplayer].string2 + Chr(13));
if (FormOption[13]) then
WriteFileString(charsfile, 'string3' +
IntToStr(f) + '=' +
players[currentplayer].string3 + Chr(13));
if (FormOption[14]) then
WriteFileString(charsfile, 'extended1' +
IntToStr(f) + '=' +
FloatToStr(players[currentplayer].extended1)
+ Chr(13));
if (FormOption[15]) then
WriteFileString(charsfile, 'extended2' +
IntToStr(f) + '=' +
FloatToStr(players[currentplayer].extended2) + Chr(13));
if (FormOption[16]) then
WriteFileString(charsfile, 'extended3' +
IntToStr(f) + '=' +
FloatToStr(players[currentplayer].extended3) + Chr(13))
WriteFileString(charsfile, Chr(13));
end;
CloseFile(CharsFile);
end;