SRL Archive - Jr. Member General Help and Discussion

Need help with money making script


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?
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.

Taric

2015-04-08 13:55:04

You should take a look at t-boxes:
You know that the bank chest isn't going to move.
You know that the vial station can only be in 3 fixed locations.

TBOXES ARE LOVE, TBOXES ARE LIFE.

Thomas

2015-04-08 14:15:25

From: Taric
You should take a look at t-boxes:
You know that the bank chest isn't going to move.
You know that the vial station can only be in 3 fixed locations.

TBOXES ARE LOVE, TBOXES ARE LIFE.



Why wouldnt I use the bankscreen.open function?
For finding the portable well ye perhaps I could use tbox, but currently it seems to work just fine with cts2 colors?

Taric

2015-04-08 14:19:00

From: lovebotter
Why wouldnt I use the bankscreen.open function?
For finding the portable well ye perhaps I could use tbox, but currently it seems to work just fine with cts2 colors?


From: lovebotter
or my colors got messed up somehow.


Thought you had color issues.

You can use the bank opening function. If you can use tboxes for the bank chest though, it will click any part of the bank chest, instead of the colors hard coded into the bankscreen.Open function.

I LOVE TBOXES, so if I can use them over color, I do XD.

Thomas

2015-04-08 14:22:24

From: Taric
Thought you had color issues.

You can use the bank opening function. If you can use tboxes for the bank chest though, it will click any part of the bank chest, instead of the colors hard coded into the bankscreen.Open function.

I LOVE TBOXES, so if I can use them over color, I do XD.

TBoxes around the bank colors? Or static pixels so I have to keep camera angled a certain way?

Taric

2015-04-08 14:24:38

From: lovebotter
TBoxes around the bank colors? Or static pixels so I have to keep camera angled a certain way?


Keeping the camera angled at a certain way. From experience, not even actual players move their cameras whenever they are using portables.

Thomas

2015-04-08 14:27:27

From: Taric
Keeping the camera angled at a certain way. From experience, not even actual players move their cameras whenever they are using portables.


I know, but lets not focus on the Tboxes for now.
If I cant seem to find proper colors for the portable well I'll edit them into Tboxes later!

The banking2 function is so much duplicaten code its just stupid.

theholyone

2015-04-08 16:10:00

I hate to be a duplicate poster but TBoxes are by far the best thing to use if you have fixed locations.

else you can also try to make a DTM of the well, i don't actually know what it looks like in game, but that would also be better than color finding

just a little suggestion for the banking part

I've been using these two very simple functions, and they have yet to let me down



procedure UseBank();
begin
if Bankscreen.isOpen(3000) or Pinscreen.isOpen(2999) then
begin
bankScreen.clickButton(BANK_BUTTON_PRESET_1);
wait(gaussrangeint(500,1000));
/// I have a bunch of other stuff here for personal use //
end;
end;


edited the parts you would possibly use


procedure OpenBank;
var
timer : TTimeMarker;
///bankbox :TBox;
begin
if not isLoggedIn() then
exit;
/// bankbox := intToBox( x1,y1, x2,y2);

timer.start();
repeat

/// mousebox(bankbox,mouse_right);
/// chooseOption.select(['ank']);
bankScreen.open(BANK_NPC_DRAYNOR);
until (Bankscreen.isOpen(5000)) or (Pinscreen.isOpen(5000)) or (not isLoggedIn()) or (timer.getTime() > 20000);
end;



my motto is: simple is best :)

Thomas

2015-04-08 17:47:14

program Herblore;
{$DEFINE SMART}
{$I SRL-6/SRL.Simba}
{$i srl-6/lib/misc/srlplayerform.simba}

var
vialCount, vialsPH: integer;
timer: TTimeMarker;

const
timeOut = 16500;

procedure declareplayers();
var
i: 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(1100);
case i of
1..3:
begin
hoverRandomSkill();
wait(gaussRangeInt(100, 1100));
end;
4..40: mouseMovingObject;
41..60: sleepAndMoveMouse(randomRange(100, 1100));
61..120:
begin
mouseOffClient(4);
wait(randomRange(1100, 2200));
end;
121..140: wait(randomRange(100, 200));
end;
end;

procedure progressReport;
begin
vialsPH := round((vialCount * (3600.0 / (getTimeRunning / 1000.0))));
writeln(padR('Running For: ' + timeRunning, 60));
writeln(padR('Vials: ' + groupDigits(vialCount, ','), 37) + padR('Vials/H: ' + groupDigits(vialsPH, ','), 23));
end;

procedure setCamera;
begin
minimap.clickCompass;
wait(gaussRangeInt(1100, 2200));
mainScreen.setAngle(MS_ANGLE_HIGH);
wait(gaussRangeInt(1100, 2200));
mainscreen.setZoom(true);
end;

function banking(preset: integer): boolean;
var
button: integer;
backpack: boolean;
begin
if not isLoggedIn then
exit;
timer.start;
if preset = 1 then
begin
backpack := tabBackpack.isEmpty;
button := BANK_BUTTON_PRESET_1;
end;
if preset = 2 then
begin
backpack := tabBackpack.isItemInSlot(1);
button := BANK_BUTTON_PRESET_2;
end;
begin
repeat
if bankscreen.open(14) then
break
else
setCamera;
if (timer.getTime > timeOut) or (not isLoggedIn) then
exit;
until (bankScreen.isOpen or pinscreen.isOpen);
pinScreen.Enter(players[currentPlayer].bankPin);
repeat
wait(gaussRangeInt(100, 500));
if bankScreen.clickButton(button) then
break;
if (timer.getTime > timeOut) or (not isLoggedIn) then
exit;
until (not bankScreen.isOpen);
end;
repeat
wait(gaussRangeInt(100, 500));
if (backpack) then
break;
if (timer.getTime > timeOut) then
begin
writeln('Failed withdrawing, shutting down');
players[currentPlayer].logout;
terminateScript;
end;
if not isLoggedIn then
exit;
until (backpack);
result := true;
end;

function findPortable: boolean;
var
i, x, y: integer;
portTPA: TPointArray;
portATPA: T2DPointArray;
begin
if not isLoggedIn() then
exit;
findColorsSpiralTolerance(x, y, portTPA, 5644066, mainScreen.getBounds(), 10, colorSetting(2, 0.10, 1.02));
if length(portTPA) < 1 then
begin
result := false;
writeln('No portTPA found');
exit;
end;
portATPA := portTPA.toATPA(30, 30);
portATPA.sortFromMidPoint(mainscreen.playerPoint);
smartImage.debugATPA(portATPA);
for i := 0 to high(portATPA) do
begin
mouse(middleTPA(portATPA[i]), MOUSE_MOVE);
if isMouseOverText(['well', 'ortab'], 2500) then
begin
result := true;
break;
end
else
result := false;
end;
end;

function renewPortable: boolean;
var
x, y: integer;
begin
writeln('Renewing Portable');
if banking(2) then
begin
wait(gaussRangeInt(4400, 6600));
sendKeys('w', 200, 40);
if conversationBox.isOpen(5500) then
begin
conversationBox.selectOption(1);
wait(gaussRangeInt(5500, 8800));
end;
if findPortable then
result := true;
end;
end;

function getVials: boolean;
var
time, x, y, amount: integer;
begin
if not isLoggedIn then
exit;
tabBackpack.Open;
timer.start;
amount := gaussRangeInt(28, 49);
if tabBackpack.isEmpty then
begin
if findPortable then
begin
if isMouseOverText(['well', 'ortab'], 3300) then
fastClick(MOUSE_RIGHT);
if (chooseOption.isOpen(2500)) then
chooseOption.select(['ake vials', 'vials', 'vial'], 2200);
repeat
wait(gaussRangeInt(50, 150));
if (not isLoggedIn) or (timer.getTime > timeOut) then
exit;
until bankScreen._enterAmount(amount, 5500);
end
else if players[currentPlayer].booleans[0] then
renewPortable;
repeat
wait(gaussRangeInt(50, 150));
if (not isLoggedIn) or (timer.getTime > timeOut) then
exit;
until (tabBackpack.isFull);
vialCount := vialCount + 28
end;
if (tabBackpack.isFull) then
result := true;
end;

procedure setup;
begin
disableSRLLog := true;
initPlayerForm();
runPlayerForm();
if (not playerForm.isScriptReady) then
terminatescript;
declareplayers();
smartShowConsole := false;
disableSRLDebug := true;
smartEnableDrawing := true;
setupSRL;
if not isLoggedIn then
begin
if not players[currentPlayer].login then
terminateScript;
writeln('Just loggedin, waiting a bit');
wait(randomRange(7700, 8800));
end;
setCamera;
findNormalrandoms;
timer.start;
tabBackpack.Open;
end;

procedure mainloop;
var
i: integer;
begin
if not isLoggedIn then
begin
wait(randomRange(7700, 8800));
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;
setCamera;
timer.start;
end;
if banking(1) then
begin
findNormalrandoms;
if getVials then
begin
findNormalrandoms;
progressReport;
antiban;
end;
end;
if timer.getTime > 187600 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.
Has some duplicate code I don't know how to solve it (last few lines in banking function).
Other then that I think code looks quite a bit cleaner now?