Thomas
2015-04-08 13:44:27
Hey,
I mainly need help with the banking functions, at the moment I have a bunch of duplicate code. And was wondering how to condense it all, removing unneeded code.
Besides that I'm unsure if my modified failsafes are any good.
Script should retrieve vials of water from portable well @barb assault bank.
Mainly used ashamans scripts as guidance, copied most from him actually.
Also I have a feeling the colors on the portable well change when you relog, or my colors got messed up somehow.
Besides I think the script looks messy, and I should be able to get it cleaner on a complete rewrite perhaps?
I mainly need help with the banking functions, at the moment I have a bunch of duplicate code. And was wondering how to condense it all, removing unneeded code.
Besides that I'm unsure if my modified failsafes are any good.
Script should retrieve vials of water from portable well @barb assault bank.
Mainly used ashamans scripts as guidance, copied most from him actually.
Also I have a feeling the colors on the portable well change when you relog, or my colors got messed up somehow.
Besides I think the script looks messy, and I should be able to get it cleaner on a complete rewrite perhaps?
program Herblore;
{$DEFINE SMART}
{$I SRL-6/SRL.Simba}
{$i srl-6/lib/misc/srlplayerform.simba}
var
vialCount, itemsPH: integer;
timeout: TTimeMarker;
procedure declareplayers();
var
i, j: integer;
begin
players.setup(playerForm.playerNames, playerForm.playerFile);
currentPlayer := 0;
for i := 0 to high(players) do
with players[i] do
begin
World := strToInt(playerForm.players[i].settings[0]);
ismember := true;
booleans[0] := strToBool(playerForm.players[i].settings[1]);
end;
end;
procedure initPlayerForm();
begin
with playerForm do
begin
name := 'Vials';
editBoxLabels := ['World'];
editBoxDefaults := ['124'];
checkBoxLabels := ['Placewell'];
checkBoxDefaults := ['True'];
end;
end;
procedure findNormalrandoms;
begin
exitSquealOfFortune;
ClaimSpinTicket;
closePollWindow();
end;
procedure antiban;
var
i: integer;
begin
i := random(600);
case i of
1..7:
begin
hoverRandomSkill();
wait(gaussRangeInt(600, 1200));
end;
8..50: mouseMovingObject;
51..280: sleepAndMoveMouse(randomRange(100, 1900));
291..310:
begin
mouseOffClient(4);
wait(randomRange(700, 1850));
end;
311..600: wait(randomRange(300, 800));
end;
wait(gaussRangeInt(250, 1500));
end;
procedure progressReport;
var
ttb: integer;
method: string;
begin
itemsPH := round((vialCount * (3600.0 / (getTimeRunning / 1000.0))));
writeln(padR('Running For: ' + timeRunning, 60));
writeln(padR('Vials: ' + groupDigits(vialCount, ','), 37) + padR('Vials/H: ' + groupDigits(itemsPH, ','), 23));
writeln('_________________________________________________________');
end;
function banking: boolean;
var
t: TTimeMarker;
time, failsafe: integer;
begin
if not isLoggedIn then
exit;
t.start;
Inc(failSafe);
if (failSafe > 5) then
begin
writeln('Failed to bank 5 times, terminating script..');
TerminateScript();
end;
SRL_Events[EVENT_ANTIBAN] := nil;
time := gaussRangeInt(12500, 25000);
begin
repeat
wait(gaussRangeInt(100, 200));
if bankscreen.open(14) then
break
else
minimap.clickCompass;
if (t.getTime > time) or (not isLoggedIn) then
exit;
until (bankScreen.isOpen or pinscreen.isOpen);
end;
SRL_Events[EVENT_ANTIBAN] := @ antiban;
pinScreen.Enter(players[currentPlayer].bankPin);
begin
t.start;
time := gaussRangeInt(7500, 9500);
repeat
if bankScreen.clickButton(BANK_BUTTON_PRESET_1) then
break;
wait(gaussRangeInt(100, 500));
if (t.getTime > time) or (not isLoggedIn) then
exit;
until (not bankScreen.isOpen);
end;
wait(gaussRangeInt(50, 150));
t.start;
repeat
if (tabBackpack.isEmpty) then
break;
wait(200);
if (t.getTime > 45000) then
begin
writeln('Failed withdrawing, shutting down');
players[currentPlayer].logout;
terminateScript;
end;
if not isLoggedIn then
exit;
until (tabBackpack.isEmpty);
result := true;
end;
function banking2: boolean;
var
t: TTimeMarker;
time, failsafe: integer;
begin
if not isLoggedIn then
exit;
t.start;
Inc(failSafe);
if (failSafe > 5) then
begin
writeln('Failed to bank 5 times, terminating script..');
TerminateScript();
end;
SRL_Events[EVENT_ANTIBAN] := nil;
time := gaussRangeInt(12500, 25000);
begin
repeat
wait(gaussRangeInt(100, 200));
if bankscreen.open(14) then
break
else
minimap.clickCompass;
if (t.getTime > time) or (not isLoggedIn) then
exit;
until (bankScreen.isOpen or pinscreen.isOpen);
end;
SRL_Events[EVENT_ANTIBAN] := @ antiban;
pinScreen.Enter(players[currentPlayer].bankPin);
begin
t.start;
time := gaussRangeInt(7500, 9500);
repeat
if bankScreen.clickButton(BANK_BUTTON_PRESET_2) then
break;
wait(gaussRangeInt(100, 500));
if (t.getTime > time) or (not isLoggedIn) then
exit;
until (not bankScreen.isOpen);
end;
wait(gaussRangeInt(50, 150));
t.start;
repeat
if (tabBackpack.isEmpty) then
break;
wait(200);
if (t.getTime > 45000) then
begin
writeln('Failed withdrawing, shutting down');
players[currentPlayer].logout;
terminateScript;
end;
if not isLoggedIn then
exit;
until (tabBackpack.isItemInSlot(1));
result := true;
end;
function renewPortable: boolean;
var
x, y: integer;
begin
if banking2 then
begin
sendKeys('w', 200, 40);
if conversationBox.isOpen(3000) then
begin
conversationBox.selectOption(1);
wait(gaussRangeInt(5500, 8800));
end;
if mainscreen.findObject(x, y, 2899841, 14, colorSetting(2, 0.19, 1.05), mainscreen.playerPoint, 40, 40, 30, ['well', 'ortab'], MOUSE_NONE) then
result := true;
end;
end;
function getVials: boolean;
var
time, x, y, amount: integer;
T: TTimeMarker;
begin
if not isLoggedIn then
exit;
tabBackpack.Open;
t.start;
amount := gaussRangeInt(28, 50);
time := gaussRangeInt(6500, 9500);
if tabBackpack.isEmpty then
begin
if mainscreen.findObject(x, y, 2899841, 14, colorSetting(2, 0.19, 1.05), mainscreen.playerPoint, 40, 40, 30, ['well', 'ortab'], MOUSE_RIGHT) then
begin
if (chooseOption.isOpen(2500)) then
chooseOption.select(['ake vials', 'vials', 'vial'], 2000);
repeat
wait(gaussRangeInt(50, 150));
if (not isLoggedIn) or (t.getTime > time) then
exit;
until bankScreen._enterAmount(50, 5000);
end
else
renewPortable;
repeat
wait(gaussRangeInt(50, 150));
if (not isLoggedIn) or (t.getTime > time) then
exit;
until (tabBackpack.isFull);
vialCount := vialCount + 28
end;
result := true;
end;
procedure setup;
begin
disableSRLLog := true;
initPlayerForm();
runPlayerForm();
if (not playerForm.isScriptReady) then
terminatescript;
declareplayers();
smartShowConsole := false;
disableSRLDebug := true;
smartEnableDrawing := true;
SRL_Events[EVENT_ANTIBAN] := @ antiban;
setupSRL;
if not isLoggedIn then
begin
if not players[currentPlayer].login then
terminateScript;
writeln('Just loggedin, waiting a bit');
wait(randomRange(7000, 8000));
end;
minimap.clickCompass;
findNormalrandoms;
timeout.start;
tabBackpack.Open;
end;
procedure mainloop;
var
i: integer;
begin
if not isLoggedIn then
begin
wait(7000);
writeln('Attempting to log back in');
repeat
try
players[currentPlayer].login;
inc(i);
except
end;
if (i = 7) then
begin
i := 0;
players.next(false);
end;
until isLoggedIn;
minimap.clickCompass;
timeout.start;
end;
if banking and tabBackpack.isEmpty then
begin
findNormalrandoms;
if getVials and tabBackpack.isFull then
begin
findNormalrandoms;
end;
end;
if timeout.getTime > 200000 then
begin
writeln('nothing has happened for too long, shutting down');
players[currentPlayer].logout;
terminateScript;
end;
end;
begin
setup;
while (players.getActive() > 0) do
mainloop;
end.