Coh3n
2010-09-07 14:38:23
It's weird, sometimes I get the error, other times I don't. I get the errors with WriteINI and DeleteINI. It seems that every time WriteINI works properly, DeleteINI will fail and vise versa. I've never had them both work or both fail.
Here's the whole file:
Error: Exception: Unable to create file "C:\Simba\Includes\SRL\SRL\MSI\Player.INI" at line 664
Line 664 (yes, I know it may not be the right line):
WriteINI('HowMany', 'HowMany', IntToStr(Length(MSI_Players)), PLAYER_INI_PATH);
I'm not really sure why it would error out because there are 2 other WriteINI commands before this line and they're both written to the file just fine. It seems that when the file already exists, WriteINI will work and DeleteINI fails. If the file doesn't exist, WriteINI will fail and DeleteINI will work.Here's the whole file:
{==============================================================================\
| MSI Group Scripting Include |
| Mainloop.scar |
|==============================================================================|
| For all the script Artificial Inteligence |
| |
| * function MSI_BestTool: Integer; * by Coh3n |
| * function MSI_WorstTool: Integer; * by Coh3n |
| * function MSI_SetupPlayer: Boolean; * by Coh3n |
| * function MSI_VarToIntArray(): TIntegerArray; * by Coh3n |
| * procedure MSI_CountItems: Boolean; * by Coh3n |
| * function MSI_Walk(): Boolean; * by Coh3n |
| * function MSI_AutoObjects: Boolean; * by The MSI Team |
| * function MSI_BankMaterials: Boolean; * by The MSI Team |
| * procedure MSI_HandleBreaking; * by Coh3n |
| * function MSI_TimedOut: Boolean; * by Coh3n |
| * procedure MSI_UnsetPlayer(); * by RM & Coh3n |
| * procedure MSI_SetPlayerInfo; * by Coh3n |
| * procedure MSI_SetReportInfo; * by Coh3n |
| * procedure MSI_WritePlayerINI; * by Coh3n & Shuttleu |
| * function MSI_MainLoop: Boolean; * by Coh3n |
| * procedure MSI_ScriptTerminate; * by Coh3n & Shuttleu |
\_____________________________________________________________________________}
{******************************************************************************}
{ function MSI_BestTool: Integer; }
{ By: Coh3n }
{ Date: 14 July 2010 }
{ Description: Determines the best tool for the job at hand. }
{******************************************************************************}
function MSI_BestTool: Integer;
var
currLevel, skill: Integer;
begin
if (not LoggedIn) then
Exit;
MSI_AddHeader('MSI_BestTool');
{ Get the current level of the chosen skill, and then look for the required
tool, starting with the best one for that player's skill level. }
skill := MSI_Scripts[MSI_Players[CurrentPlayer].Scripts[CurrentScript]].SkillConstant;
currLevel := GetSkillLevel(skill);
ProgressReportArray[CurrentPlayer].ScriptInfo[CurrentScript].PlayerSkillLevel := currLevel;
MSI_Debug('CurrentSkill level: ' + IntToStr(currLevel));
case skill of
SKILL_WOODCUTTING:
case (currLevel) of
REQ_RUNE..REQ_MAX_LEVEL: Result := HATCHET_RUNE;
REQ_ADAMANT..REQ_RUNE: Result := HATCHET_ADAMANT;
REQ_MITHRIL..REQ_ADAMANT: Result := HATCHET_MITHRIL;
REQ_STEEL..REQ_MITHRIL: Result := HATCHET_STEEL;
else
Result := HATCHET_IRON;
end;
SKILL_MINING:
case (currLevel) of
REQ_RUNE..REQ_MAX_LEVEL: Result := PICKAXE_RUNE;
REQ_ADAMANT..REQ_RUNE: Result := PICKAXE_ADAMANT;
REQ_MITHRIL..REQ_ADAMANT: Result := PICKAXE_MITHRIL;
REQ_STEEL..REQ_MITHRIL: Result := PICKAXE_STEEL;
else
Result := PICKAXE_IRON;
end;
else
MSI_Debug('MSI_BestTool: Invalid skill!');
end;
MSI_CloseHeader('MSI_BestTool: '+ MSI_Items[Result].Name);
end;
{******************************************************************************}
{ function MSI_WorstTool: Integer; }
{ By: Coh3n }
{ Date: 14 July 2010 }
{ Description: Determines the worst tool for the job at hand. }
{******************************************************************************}
function MSI_WorstTool: Integer;
var
skill: Integer;
begin
if (not LoggedIn) then
Exit;
skill := MSI_Scripts[MSI_Players[CurrentPlayer].Scripts[CurrentScript]].SkillConstant;
case skill of
SKILL_WOODCUTTING:
Result := HATCHET_BRONZE;
SKILL_MINING:
Result := PICKAXE_BRONZE;
else
MSI_SubDebug('MSI_WorstTool: Invalid skill!');
end;
end;
{******************************************************************************}
{ function MSI_SetupPlayer: Boolean; }
{ By: Coh3n }
{ Date: 17 July 2010 }
{ Description: Sets up the player for autoing }
{******************************************************************************}
function MSI_SetupPlayer: Boolean;
var
bestTool, worstTool, x, y, i, j , k: Integer;
gameTabs, FishingTool: TIntegerArray;
script: TScript;
begin
MSI_AddHeader('MSI_SetupPlayer');
if (not LoggedIn) then
LoginPlayer;
script := MSI_Scripts[MSI_Players[CurrentPlayer].Scripts[CurrentScript]];
Inc(Stats_CustomVars[STATS_LOGINS]);
MSI_SendStats;
SetAngle(True);
MSI_FindRandoms;
RunEnergy(20);
for i := 0 to High(script.Tools) do
case script.Tools[i] of
//first looks for the best tool depending on the player's skill level
TOOL_HATCHET, TOOL_PICKAXE:
begin
bestTool := MSI_BestTool;
worstTool := MSI_WorstTool;
gameTabs := [TAB_EQUIP, TAB_INV];
for j := 0 to High(gameTabs) do
for k := bestTool downto worstTool do
if (MSI_FindTool(k, gameTabs[j], x, y)) then
begin
Result := True;
MSI_CloseHeader('MSI_SetupPlayer: ' + BoolToStr(Result));
Exit;
end;
//if tool isn't found, will attempt to withdraw from bank
if (not Result) then
begin
if (script.BankType = NoBank) then
begin
MSI_CloseHeader('MSI_SetupPlayer: ' + BoolToStr(Result));
Exit;
end;
if (MSI_OpenBank(Script.WhichBank, MSI_Players[CurrentPlayer].Pin)) then
for k := bestTool downto worstTool do
if (MSI_Withdraw([k], [1])) then
begin
Result := True;
Break;
end else begin
CloseBank;
MSI_Debug('Couldn''t Withdraw Tool');
end
else
MSI_Debug('Unable to Open Bank');
end;
end;
TOOL_FISH:
begin
gameTabs := [TAB_EQUIP, TAB_INV];
FishingTool := MSI_FishingTools;
if (Length(FishingTool) <= 0) then Exit;
for j := 0 to High(gameTabs) do
begin
Result := MSI_FindTool(FishingTool[0], gameTabs[j], x, y);
if (Length(FishingTool) > 1) then
Result := MSI_FindTool(FishingTool[1], gameTabs[j], x, y); // There are only ever two tools.
end;
//if tool isn't found, will attempt to withdraw from bank
if (not Result) then
begin
if (script.BankType = NoBank) then
begin
MSI_CloseHeader('MSI_SetupPlayer: ' + BoolToStr(Result));
Exit;
end;
if (MSI_OpenBank(Script.WhichBank, MSI_Players[CurrentPlayer].Pin)) then
if MSI_Withdraw([FishingTool], [1]) then
begin
Result := True;
Break;
end else begin
CloseBank;
MSI_Debug('Couldn''t Withdraw Tool');
end
else
MSI_Debug('Unable to Open Bank');
end;
end;
else
MSI_Debug('Invalid tool option in script: ' + script.Name);
end;
MSI_CloseHeader('MSI_SetupPlayer: ' + BoolToStr(Result));
end;
{******************************************************************************}
{ function MSI_VarToIntArray(a: TVariantArray): TIntegerArray; }
{ By: Coh3n }
{ Date: 25 June 2010 }
{ Description: Converts the variant array to an integer array; used to convert }
{ MSI_Players.Objects and MSI_Players.Items }
{******************************************************************************}
function MSI_VarToIntArray(a: TVariantArray): TIntegerArray;
var
i: integer;
s: string;
begin
SetLength(result, Length(a));
for i := 0 to High(a) do
try
s := IntToStr(a[i]);
result[i] := Round(StrToFloat(s));
except
MSI_SubDebug('Invalid index in variant array!');
Exit;
end;
end;
{******************************************************************************}
{ procedure MSI_CountItems; }
{ By: Coh3n }
{ Date: 13 July 2010 }
{ Description: Counts the materials and calculates the experience gained }
{ from items in the inventory }
{******************************************************************************}
procedure MSI_CountItems;
var
itemCount, expCount, i, j, k: Integer;
exps: array of array of TExtendedArray;
intItems: array of array of TIntegerArray;
begin
if (not LoggedIn) then
Exit;
with MSI_Players[CurrentPlayer] do
begin
SetLength(intItems, Length(Objects));
SetLength(exps, Length(intItems));
for k := 0 to High(Objects) do
begin
SetLength(intItems[k], Length(Objects[k]));
SetLength(exps[k], Length(intItems[k]));
for i := 0 to High(Objects[k]) do
begin
SetLength(intItems[k][i], Length(Items[k][i]));
SetLength(exps[k][i], Length(intItems[k]));
intItems[k][i] := MSI_VarToIntArray(Items[k][i]);
exps[k][i] := Experiences[k][i];
for j := 0 to High(intItems[k][i]) do
begin
itemCount := CountItems('dtm', MSI_Items[intItems[k][i][j]].DTM, []);
expCount := Round(exps[k][i][j] * itemCount);
MSI_AddToProggy(PROG_ADD_EXP, -1, -1, expCount); //adds exp to script
MSI_AddToProggy(PROG_ADD_ITEMS, i, j, itemCount); //adds amount of item
MSI_SubDebug('MSI_CountItems: Found ' + IntToStr(itemCount) + ' of item '
+ MSI_Items[intItems[k][i][j]].Name);
end;
end;
end;
end;
end;
{******************************************************************************}
{ function MSI_Walk(ToLoc: Boolean): Boolean; }
{ By: Coh3n }
{ Date: 21 August 2010 }
{ Description: Walks a script path depending on the ToLoc parameter }
{******************************************************************************}
function MSI_Walk(ToLoc: Boolean): Boolean;
var
Script: TScript;
begin
if (not LoggedIn) then
Exit;
MSI_AddHeader('MSI_Walk');
with MSI_Players[CurrentPlayer] do
begin
MSI_Debug('Player''s Location = '+MSI_Locations[Location].Name);
Script := MSI_Scripts[Scripts[CurrentScript]];
if (ToLoc) then
Result := (Location = Script.PathInfo.EndLoc)
else
Result := (Location = Script.PathInfo.StartLoc);
if (not Result) then
if (ToLoc) then
begin
if (Location = Script.PathInfo.StartLoc) then
Result := MSI_PerformWalk(Script.PathInfo.StartLoc, Script.PathInfo.EndLoc);
end else
if (Location = Script.PathInfo.EndLoc) then
Result := MSI_PerformWalk(Script.PathInfo.EndLoc, Script.PathInfo.StartLoc);
end;
MSI_CloseHeader('MSI_Walk: ' + BoolToStr(Result));
end;
{******************************************************************************}
{ function MSI_AutoObjects: Boolean; }
{ By: The MSI Team }
{ Date: 04 August 2010 }
{ Description: Performs the specified skill }
{******************************************************************************}
function MSI_AutoObjects: Boolean;
var
objects: TIntegerArray;
scriptConst: Integer;
begin
if (not LoggedIn) then
Exit;
MSI_AddHeader('MSI_AutoObjects');
MakeCompass(MSI_Scripts[MSI_Players[CurrentPlayer].Scripts[CurrentScript]].CompassAng);
scriptConst := MSI_Players[CurrentPlayer].Scripts[CurrentScript];
objects := MSI_VarToIntArray(MSI_Players[CurrentPlayer].Objects[CurrentScript]);
Result := MSI_Scripts[scriptConst].AutoObjects(objects);
if (MSI_Scripts[scriptConst].BankType = NoBank) then //drop the items if not banking
begin
MSI_CountItems;
MSI_DropAll;
MSI_AddToProggy(PROG_ADD_LOADS, -1, -1, -1);
Result := True;
end;
MSI_CloseHeader('MSI_AutoObjects: ' + BoolToStr(Result));
end;
{******************************************************************************}
{ function MSI_BankMaterials: Boolean; }
{ By: The MSI Team }
{ Date: 04 August 2010 }
{ Description: Banks the specified materials }
{******************************************************************************}
function MSI_BankMaterials: Boolean;
var
intItems: TIntegerArray;
itemsDeposited: TBooleanArray;
i: Integer;
depAll: Boolean;
Script: TScript;
begin
if (not LoggedIn) then
Exit;
MSI_AddHeader('MSI_BankMaterials');
Script := MSI_Scripts[MSI_Players[CurrentPlayer].Scripts[CurrentScript]];
MSI_CountItems;
if (MSI_Players[CurrentPlayer].Location = Script.PathInfo.StartLoc) then
if (not MSI_OpenBank(Script.WhichBank, MSI_Players[CurrentPlayer].Pin)) then
begin
ProgressReportArray[CurrentPlayer].FalseReason := 'Failed to open bank: '+IntToStr(Script.WhichBank);
Exit;
end;
with MSI_Players[CurrentPlayer] do
begin
SetLength(itemsDeposited, Length(Items[CurrentScript]));
for i := 0 to High(Items[CurrentScript]) do
begin
intItems := MSI_VarToIntArray(Items[CurrentScript][i]);
itemsDeposited[i] := MSI_Deposit(intItems, [], depAll);
if (depAll) then
Break;
end;
end;
if (not depAll) then
for i := 0 to High(itemsDeposited) do
if (not itemsDeposited[i]) then
begin
Result := False;
ProgressReportArray[CurrentPlayer].FalseReason := 'Failed to deposit items';
MSI_CloseHeader('MSI_BankMaterials: ' + BoolToStr(Result));
Exit;
end;
MSI_AddToProggy(PROG_ADD_LOADS, -1, -1, -1);
Inc(Stats_CustomVars[STATS_BANKS]);
MSI_SendStats;
Result := True;
CloseBank;
MSI_CloseHeader('MSI_BankMaterials: ' + BoolToStr(Result));
end;
{******************************************************************************}
{ procedure MSI_HandleBreaking; }
{ By: Coh3n Edited by NCDS }
{ Date: 20 July 2010 }
{ Description: Simple procedure for breaking }
{******************************************************************************}
procedure MSI_HandleBreaking;
var
t: Integer;
begin
if (not LoggedIn) then
Exit;
if (BankScreen) then
CloseBank;
MSI_AddHeader('MSI_HandleBreaking');
if (HowManyPlayers = 1) or (PlayersActive = 1) then
begin
MSI_Debug('Taking a short break');
if InRange(Random(10), 2, 9) then
ExitToLobby;
t := (GetSystemTime + ((BreakTime * 60000) + RandomRange(-300000, 300000)));
while GetSystemTime < t do
begin
Status('BreakTime remaining: '+MsToTime(t - GetSystemTime, Time_Formal)+';');
Wait(RandomRange(2000, 25000));
if LoggedIn then
FindNormalRandoms;
end;
MSI_Debug('Break over, continuing to play');
if (LobbyScreen) then
MouseBox(80, 450, 560, 470, 1);
end else
begin
MSI_Debug('Switching players');
NextPlayer(True);
end;
Inc(Stats_CustomVars[STATS_LOGINS]);
MSI_SendStats;
MSI_CloseHeader('MSI_HandleBreaking: Done');
end;
{******************************************************************************}
{ function MSI_TimedOut: Boolean; }
{ By: Coh3n }
{ Date: 10 June 2010 }
{ Description: Handles connection losses }
{******************************************************************************}
function MSI_TimedOut: Boolean;
var
t: Integer;
begin
Result := False;
t := GetSystemTime + 10000;
while (GetSystemTime < t) do
if (LobbyScreen) or (not LoggedIn) then
begin
MSI_SubDebug('MSI_TimedOut: Suspicion of connection loss');
if (LobbyScreen) then
MouseBox(80, 450, 560, 470, 1)
else
if (not LoggedIn) then
LoginPlayer;
Result := True;
Break;
end;
if (Result) then
WaitFunc(@LoggedIn, 500, 10000);
end;
{******************************************************************************}
{ procedure MSI_UnsetPlayer(func, reason: String; setReason: Boolean); }
{ By: RM and Coh3n }
{ Date: 03 July 2010 }
{ Description: Sets the player to false if something fails }
{******************************************************************************}
procedure MSI_UnsetPlayer(func, reason: String; setReason: Boolean);
begin
MSI_AddHeader('MSI_UnsetPlayer');
if (BankScreen) then
CloseBank;
MSI_Debug(reason);
MSI_Players[CurrentPlayer].Active := False;
Players[CurrentPlayer].Active := False;
if (setReason) then
ProgressReportArray[CurrentPlayer].FalseReason := reason;
MSI_ProgressReport;
if (not AllPlayersInactive) then //To avoid infinite loop in NextPlayer
begin
NextPlayer(False);
Inc(Stats_CustomVars[STATS_LOGINS]);
MSI_SendStats;
end;
MSI_CloseHeader('MSI_UnsetPlayer: Done');
end;
{******************************************************************************}
{ procedure MSI_SetPlayerInfo; }
{ By: Coh3n }
{ Date: 03 July 2010 }
{ Description: Sets the necessary player information (called at the beginning }
{ of MSI_MainLoop) }
{******************************************************************************}
procedure MSI_SetPlayerInfo;
var
i, j, k, l: Integer;
script: TScript;
intObjects: array of TIntegerArray;
intItems: array of array of TIntegerArray;
useDefaults: TBooleanArray;
begin
SetLength(useDefaults, Length(MSI_Players));
for i := 0 to High(MSI_Players) do
with MSI_Players[i] do
begin
Players[i].BoxRewards := ['amp', 'mote', 'ostume', 'oins', 'unes', 'ems'];
SetLength(intObjects, Length(Objects));
SetLength(intItems, Length(Objects));
SetLength(Items, Length(Objects));
SetLength(ItemNames, Length(Items));
SetLength(Experiences, Length(Items));
for j := 0 to High(MSI_Players[i].Scripts) do
begin
script := MSI_Scripts[Scripts[j]];
if (Length(Objects[j]) = 0) then
begin
useDefaults[i] := True;
Objects[j] := script.Objects; //set to default
end;
intObjects[j] := MSI_VarToIntArray(Objects[j]);
SetLength(intItems[j], Length(Objects[j]));
SetLength(Items[j], Length(Objects[j]));
SetLength(ItemNames[j], Length(Items[j]));
SetLength(Experiences[j], Length(Items[j]));
for k := 0 to High(Objects[j]) do
begin
if (useDefaults[i]) then
begin
SetLength(Items[j][k], Length(script.Items));
Items[j][k] := script.Items[k];
end else begin
SetLength(Items[j][k], Length(MSI_Objects[intObjects[j][k]].AssociatedItems));
Items[j][k] := MSI_Objects[intObjects[j][k]].AssociatedItems; //set the associated items with the proper objects
end;
SetLength(ItemNames[j][k], Length(Items[j][k]));
SetLength(Experiences[j][k], Length(Items[j][k]));
intItems[j][k] := MSI_VarToIntArray(Items[j][k]);
ItemNames[j][k] := MSI_GetItemNames(intItems[j][k]);
Experiences[j][k] := MSI_GetItemExperiences(script.SkillConstant, intItems[j][k]);
for l := 0 to High(Experiences[j][k]) do
MSI_Debug('Player['+IntToStr(i)+'].Scripts['+IntToStr(j)+'].Objects['+IntToStr(k)+'] Experience = '+FloatToStr(Experiences[j][k][l]));
end;
end;
end;
end;
{******************************************************************************}
{ procedure MSI_SetReportInfo; }
{ By: Coh3n }
{ Date: 03 July 2010 }
{ Description: Sets all the necessary progress report information that is }
{ constant throughout runtime }
{******************************************************************************}
procedure MSI_SetReportInfo;
var
i, j, k: Integer;
script: TScript;
begin
for i := 0 to High(ProgressReportArray) do
with ProgressReportArray[i] do
begin
SetLength(ScriptInfo, Length(MSI_Players[i].Scripts));
PlayerName := MSI_Players[i].Name;
PlayerStatus := MSI_Players[i].Active;
PlayerLoc := MSI_Players[i].Location;
if (not MSI_Players[i].Active) then
FalseReason := 'User set to false';
for j := 0 to High(ScriptInfo) do
begin
script := MSI_Scripts[MSI_Players[i].Scripts[j]];
ScriptInfo[j].Name := script.Name;
ScriptInfo[j].SkillName := script.SkillName;
SetLength(ScriptInfo[j].PlayerItemAmounts, Length(MSI_Players[i].Items[CurrentScript]));
for k := 0 to High(ScriptInfo[j].PlayerItemAmounts) do
SetLength(ScriptInfo[j].PlayerItemAmounts[k], Length(MSI_Players[i].Items[CurrentScript][k]));
end;
end;
end;
procedure MSI_DeleteINI;
var
i: Integer;
begin
if (not RemoteEnabled) then
Exit;
try
DeleteINI('Changed', 'Changed', PLAYER_INI_PATH);
DeleteINI('HowMany', 'HowMany', PLAYER_INI_PATH);
for i := 0 to High(MSI_Players) do
begin
DeleteINI(IntToStr(i), 'Active', PLAYER_INI_PATH);
DeleteINI(IntToStr(i), 'Location', PLAYER_INI_PATH);
end;
except
MSI_Debug('MSI_DeleteINI: Error!');
end;
end;
procedure MSI_WriteINI;
var
i: Integer;
begin
if (not RemoteEnabled) then
Exit;
//try
MSI_DeleteINI;
WriteINI('Changed', 'Changed', 'False', PLAYER_INI_PATH);
WriteINI('HowMany', 'HowMany', IntToStr(Length(MSI_Players)), PLAYER_INI_PATH);
for i := 0 to High(MSI_Players) do
begin
WriteINI(IntToStr(i), 'Active', BoolToStr(MSI_Players[i].Active), PLAYER_INI_PATH);
WriteINI(IntToStr(i), 'Location', IntToStr(MSI_Players[i].Location), PLAYER_INI_PATH);
end;
//except
//MSI_Debug('MSI_WriteINI: Error! Retrying...');
//end;
end;
procedure MSI_ResetINI;
var
i: Integer;
begin
if (not RemoteEnabled) then
Exit;
try
if (StrToBool(ReadINI('Changed', 'Changed', PLAYER_INI_PATH))) then
for i := 0 to High(MSI_Players) do
begin
MSI_Players[i].Active:= StrToBool(ReadINI(IntToStr(i), 'Active', PLAYER_INI_PATH));
MSI_Players[i].Location:= StrToInt(ReadINI(IntToStr(i), 'Location', PLAYER_INI_PATH));
Players[i].Active := MSI_Players[i].Active;
end;
except
MSI_Debug('MSI_ResetINI: Error!');
end;
end;
{******************************************************************************}
{ procedure MSI_MainLoop; }
{ By: Coh3n }
{ Date: 24 July 2010 }
{ Description: The MainLoop - performs all actions of the script }
{******************************************************************************}
procedure MSI_MainLoop;
var
tmpLoads, time: Integer;
begin
MSI_SetPlayerInfo;
MSI_SetReportInfo;
MSI_WriteINI;
ScriptStart := TheDate(DATE_DAY) + ' at ' + TheTime;
ScriptStart := Replace(scriptStart, ':', ' ');
MSI_SetRev;
// To gain access
if (SaveDebug) then
begin
MSI_Debug('Created Debug file');
MSI_Debug('Gathering report info, please wait...');
MSI_ProgressReport;
end;
if DEBUG_SMART then
SmartSetDebug(True);
repeat
MSI_ResetINI;
tmpLoads := 0;
// Setup player
if (not MSI_SetupPlayer) then
begin
if (MSI_TimedOut) then
Continue;
MSI_UnsetPlayer('MSI_MainLoop', 'Failed to setup player', True);
Continue;
end;
repeat
MarkTime(time);
// Walk to location if using a bankable script
if (not (MSI_Scripts[MSI_Players[CurrentPlayer].Scripts[CurrentScript]].BankType = NoBank)) then
if (not MSI_Walk(True)) then
begin
if (MSI_TimedOut) then
Break;
MSI_UnsetPlayer('MSI_MainLoop', 'Failed to walk to location', False);
Break;
end;
// Perform the skill
if (not MSI_AutoObjects) then
begin
if (MSI_TimedOut) then
Break;
MSI_UnsetPlayer('MSI_MainLoop', 'Failed to use script: ' + IntToStr(CurrentScript), True);
Break;
end;
if (not (MSI_Scripts[MSI_Players[CurrentPlayer].Scripts[CurrentScript]].BankType = NoBank)) then
begin
if (not MSI_Walk(False)) then // Walk to the bank
begin
if (MSI_TimedOut) then
Break;
MSI_UnsetPlayer('MSI_MainLoop', 'Failed to walk to bank', False);
Break;
end;
if (not MSI_BankMaterials) then // Bank the materials
begin
if (MSI_TimedOut) then
Break;
MSI_UnsetPlayer('MSI_MainLoop', 'Failed to bank materials', False);
Break;
end;
end;
// Set the progress report times
with ProgressReportArray[CurrentPlayer] do
begin
IncEx(PlayerTime, TimeFromMark(time));
IncEx(ScriptInfo[CurrentScript].Runtime, TimeFromMark(time));
end;
MSI_ProgressReport;
MSI_ResetINI;
with ProgressReportArray[CurrentPlayer] do
if (LoadsDone >= (MSI_Players[CurrentPlayer].Loads[L_TOTAL] + RandomRange(-10, 10))) then
begin
MSI_UnsetPlayer('MSI_MainLoop', 'Finished total loads!', True);
Break;
end;
Inc(tmpLoads);
if (tmpLoads >= (MSI_Players[CurrentPlayer].Loads[L_BREAK] + RandomRange(-2, 2))) then
begin
MSI_HandleBreaking;
MSI_FindRandoms;
Break;
end;
until(not MSI_Players[CurrentPlayer].Active);
until(AllPlayersInactive);
if (AllPlayersInactive) then
begin
MSI_CloseHeader('All players inactive, terminating script!');
Logout;
MSI_ProgressReport;
TerminateScript;
end;
end;
{******************************************************************************}
{ procedure MSI_ScriptTerminate; }
{ By: Coh3n & Shuttleu }
{ Date: 03 August 2010 }
{ Description: Called upon termination of the script }
{******************************************************************************}
procedure MSI_ScriptTerminate;
begin
MSI_ProgressReport;
Writeln('Thank-you for using MSI Phoenix scripts!');
MSI_DeleteINI;
FreeSRL;
MSI_FreeAllItems;
end;