Nice, good job with t3h script :) Isn't this about 2m/h? There are many places where this could potentially fail (1 lag spike could screw it up as it only does things once). I have added some comments:
program AstralCrafter;
{$DEFINE SMART}
{$I SRL-6/SRL.simba}
{$I sps/lib/sps-rs3.simba}
{
vwxz's Astral Crafter
Development Pre-release
Use at your own risk!
}
{
Set up instructions:
1. Standard SRL graphics and interfaces settings
2. Face north, highest camera angle, zoomed fully out
3. Pure essence in top right of bank
4. Pouches in first inventory slots 1 through 4, largest to smallest
5. Wield an earth staff or equivalent
6. Excess supply of laws, astrals, airs, and cosmics in inventory
7. Moonclan teleport in action bar slot 2; NPC contact in slot 2
}
const
ColorAltar = 8550528; // good practive to keep constants CAPITAL
ColorTolAltar = 10; // so they are easily recognisable
ColorDecayedPouch = 3751490;
ColorTolDecayedPouch = 5;
ColorCountDecayedPouch = 20;
ColorAbyssMage = 1381655;
ColorTolAbyssMage = 10;
BitmapTolPureEss = 10;
var
PosBank: TPoint;
PathBankToAltar: TPointArray;
StatsScriptStart: TTimeMarker;
BitmapPureEss: Integer;
StatsNumIterations, StatsNumRepairs, StatsEssCrafted: Integer;
procedure WaitRandom(MsecToWait: Integer) // declare players?
begin
Wait(MsecToWait + Random(Round(MsecToWait / 4.0)));
end;
procedure LoadResources
begin
PosBank := Point(138, 190);
PathBankToAltar := [Point(146, 206), Point(188, 206), Point(198, 267), Point(194, 318), Point(229, 351), Point(253, 367), Point(269, 386), Point(275, 424), Point(325, 415), Point(358, 412)];
BitmapPureEss := BitmapFromString(18, 8, 'meJx10X0LgjAYBPAPaJiZjDGmtczX1EyziL58B0djOIT798fdw6NTk53ysymQS15diwYpy1td9217R7ruMQwzMo7LNL3n52d5fZXKdGr03wLSAvqWEEpKDUgL6FtCKAtRJ4RCtqy/liqORZJIQtrV4NVa1EFF0ZHQty6kpcJdYXgAtHYLIqzDSKhgt0doXeieyb+gzqofNxenLw==');
end;
procedure SetUp
begin
SmartEnableDrawing := True;
SetUpSrl;
LoadResources;
Sps.Setup('0_0MOONCLAN', RUNESCAPE_SURFACE);
StatsScriptStart.Start;
StatsNumIterations := 0;
StatsNumRepairs := 0;
StatsEssCrafted := 0;
end;
procedure TeleToMoonclan
begin
ActionBar.ClickSlot(1); // put this in a loop incase of fail
WaitRandom(3500); // maybe until find bank symbol? (and add a timer too)
end;
procedure WalkToBank
begin
Sps.WalkToPos(PosBank);
WaitRandom(500);
end;
procedure WithdrawEss
begin
BankScreen.Withdraw(10, WITHDRAW_AMOUNT_ALL, ['']); //All of this withdrawl stuff should be put in a loop
WaitRandom(800); // until bankscreen.isPackFull
end;
procedure FillPouches1
begin
Mouse(BankScreen.GetPackSlotBox(1).GetMiddle, MOUSE_RIGHT);
WaitRandom(500);
ChooseOption.Select(['Fill Giant pouch'], 0.70); // until bankscreen.getPackCount = xx
WaitRandom(500);
end;
procedure FillPouches2
begin
Mouse(BankScreen.GetPackSlotBox(2).GetMiddle, MOUSE_RIGHT);
WaitRandom(500);
ChooseOption.Select(['Fill Large pouch'], 0.80); // same again
WaitRandom(500);
Mouse(BankScreen.GetPackSlotBox(3).GetMiddle, MOUSE_RIGHT);
WaitRandom(500);
ChooseOption.Select(['Fill Medium pouch'], 0.80);
WaitRandom(500);
Mouse(BankScreen.GetPackSlotBox(4).GetMiddle, MOUSE_RIGHT);
WaitRandom(500);
ChooseOption.Select(['Fill Small pouch'], 0.80);
WaitRandom(800);
end;
procedure OpenBank
var
I: Integer;
begin
for I := 1 to 5 do begin
if BankScreen.IsOpen then begin
Break; // no need for begin and end here
end else begin
BankScreen.Open(BANK_BOOTH);
WaitRandom(1000);
end; // maybe if > 5 tries then walkToBank again?
end;
end;
procedure BankStep
begin
OpenBank;
WaitRandom(1000);
WithdrawEss;
FillPouches1;
WithdrawEss;
FillPouches2;
WithdrawEss;
WaitRandom(1000);
BankScreen.Close;
WaitRandom(1000);
end;
procedure EmptyPouches1
begin
TabBackpack.MouseSlot(1, MOUSE_LEFT); // again, good to put a check you actually clicked
WaitRandom(1000);
end;
procedure EmptyPouches2
begin
TabBackpack.MouseSlot(2, MOUSE_LEFT);
WaitRandom(1000);
TabBackpack.MouseSlot(3, MOUSE_LEFT);
WaitRandom(1000);
TabBackpack.MouseSlot(4, MOUSE_LEFT);
WaitRandom(1000);
end;
procedure WalkToAltar
begin
Sps.WalkPath(PathBankToAltar);
WaitRandom(500);
end;
procedure RecordEssCrafted
begin
StatsEssCrafted := StatsEssCrafted + TabBackpack.CountBitmap(BitmapPureEss, BitmapTolPureEss);
end;
procedure CraftRunes(WaitLonger: Boolean);
var
ColorsFound: TPointArray;
MidPoint: TPoint;
begin
RecordEssCrafted;
if FindColorsTolerance(ColorsFound, ColorAltar, MainScreen.GetBounds, ColorTolAltar) then begin
MidPoint := MedianTpa(ColorsFound);
Mouse(MidPoint, MOUSE_LEFT);
end else begin
// whats this for?
end;
MiniMap.WaitFlag;
if (WaitLonger) then begin // no need for begin/end here
WaitRandom(2000);
end;
WaitRandom(2000);
end;
procedure CraftStep
begin
CraftRunes(True);
EmptyPouches1;
CraftRunes(False);
EmptyPouches2;
CraftRunes(False);
ClaimSpinTicket;
end;
function HavePouchesDecayed: Boolean
var
SlotNum: Integer;
begin
Result := False;
for SlotNum := 1 to 4 do begin
if CountColorTolerance(ColorDecayedPouch, TabBackpack.GetSlotBox(SlotNum), ColorTolDecayedPouch) > ColorCountDecayedPouch then begin
Result := True;
Break;
end;
end;
end;
procedure CastNpcContact
begin
ActionBar.ClickSlot(2); // until conversationbox.isOpen?
WaitRandom(1000);
end;
procedure SelectAbyssMage
var
TpaAbyssMage: TPointArray;
AtpaAbyssMage: T2DPointArray;
begin
MouseScroll(MainScreen.GetBounds.GetMiddle, 4);
WaitRandom(500);
if FindColorsTolerance(TpaAbyssMage, ColorAbyssMage, MainScreen.GetBounds, ColorTolAbyssMage) then begin // begins go on next line
AtpaAbyssMage := TpaAbyssMage.ToAtpa(20);
SortAtpaSize(AtpaAbyssMage, True);
TpaAbyssMage := AtpaAbyssMage[Low(AtpaAbyssMage)];
Mouse(MedianTpa(TpaAbyssMage), MOUSE_LEFT);
WaitRandom(6000);
end else begin
// why this?
end;
end;
procedure ChatWithAbyssMage
var
IX: Integer;
begin
for IX := 1 to 6 do begin
ConversationBox.Continue(True, True);
WaitRandom(1000);
end;
ConversationBox.SelectOption(2);
WaitRandom(1000);
for IX := 1 to 2 do begin
ConversationBox.Continue(True, True);
WaitRandom(1000);
end;
end;
procedure RepairPouches
begin
CastNpcContact;
SelectAbyssMage;
ChatWithAbyssMage;
StatsNumRepairs := StatsNumRepairs + 1; // cound just inc(StatsNumRepairs)
end;
procedure RepairPouchesIfNeeded
begin
if HavePouchesDecayed then begin
RepairPouches; // couldnt you just put this into above?
end;
end;
procedure PrintStatsReport
var
StatsHours: Extended;
begin
StatsHours := StatsScriptStart.GetTime / (1000.0 * 60.0 * 60.0);
Print('----------------------------------');
Print('----------------------------------');
Print('----- vwxz''s Astral Crafter -----');
Print('Ran for ' + MsToTime(StatsScriptStart.GetTime, TIME_FORMAL) + ' (' + FloatToStr(StatsHours) + ' hours)');
Print('Completed ' + IntToStr(StatsNumIterations) + ' iterations (' + FloatToStr(StatsNumIterations/StatsHours) + ' per hour)');
Print('Crafted (estimated) ' + IntToStr(StatsNumIterations*50) + ' ess (' + FloatToStr(StatsNumIterations*50.0/StatsHours) + ' per hour)');
Print('Crafted (counted) ' + IntToStr(StatsEssCrafted) + ' ess (' + FloatToStr(StatsEssCrafted/StatsHours) + ' per hour)');
Print('Repaired pouches ' + IntToStr(StatsNumRepairs) + ' times');
Print('----- vwxz''s Astral Crafter -----');
Print('----------------------------------');
Print('----------------------------------');
end;
procedure MainLoopIteration
begin
WaitRandom(1000); // maybe in mainloop put:
TeleToMoonclan; // if not isLoggedIn then
WalkToBank; // players[currentPlayer].login()
BankStep;
RepairPouchesIfNeeded; // and in each of your func/procs put if not isLoggedIn then exit
WalkToAltar; // so if it logs out it will exit everything and until it hits the login bit above.
CraftStep;
StatsNumIterations := StatsNumIterations + 1;
PrintStatsReport;
end;
begin
SetUp;
repeat
MainLoopIteration;
until False;
end.