SRL Archive - First Scripts

ArtisanSmelter (Rough Script)


kozak94

2014-12-11 21:26:39

Hey guys, I put together a very rough script to get some smithing levels up. I would like to add anti-ban and add more control in terms of choosing the Iron i/ii/iii ingot bars. Any tips, or references to guides available? I keep getting an error that I did not receive before and I was wondering what has changed. Thank you for your help =)

Error: print('TRSProductionScreen.getType(): result = ' + toStr(result), TDebug.SUB);

Error: Unknown declaration "TRSInterface" at line 31
Compiling failed.
Error: Operator expected at line 340
Compiling failed.
Error: Operator expected at line 340
Compiling failed.
Error: Operator expected at line 340
Compiling failed.

program ArtisanSmelter;
{$DEFINE SMART}
{$I SRL-6/SRL.Simba}


procedure withDraw();
var
draw: TBox; //declare TBox variable
begin
draw := intToBox(273, 149, 303, 170); //top left, bottom right points
mouseBox(draw, MOUSE_LEFT); //left click
wait(randomRange(3500, 4441));
end;
procedure waiiit();
begin wait(randomRange(3500, 4441));
end;

procedure acceptButton();
var
x, y: integer;
begin
wait(randomRange(1113,2546));
while not productionScreen.isOpen() do wait(1);
KeyDown(VK_SPACE);
wait(randomRange(123,936));
KeyUp(VK_SPACE);
sleepAndMoveMouse(1000 + random(2000));
mouseOffClient(OFF_CLIENT_RANDOM);
wait(randomRange(168325, 198512));
end;

procedure anvil();

var
settingsButton: TBox; //declare TBox variable
begin
settingsButton := intToBox(455, 193, 463, 210); //top left, bottom right points
mouseBox(settingsButton, MOUSE_LEFT); //left click
wait(randomRange(3500, 4441));
end;

procedure waitSmith();
begin
wait(randomRange(126000, 130000));
end;


procedure waitSmithtwo();
begin
wait(randomRange(136000, 140000));
end;

procedure deposit();

var
settingsButton: TBox; //declare TBox variable
begin
settingsButton := intToBox(248, 149, 268, 168); //top left, bottom right points
mouseBox(settingsButton, MOUSE_LEFT); //left click
wait(randomRange(3500, 4441));
end;


procedure walk();

var
settingsButton: TBox; //declare TBox variable
begin
settingsButton := intToBox(163, 183, 177, 197); //top left, bottom right points
mouseBox(settingsButton, MOUSE_LEFT); //left click
wait(randomRange(3500, 4441));
end;

procedure antiban;
var
i: integer;
begin

i := random(2000);
case i of
1..3: randomRClickItem();
4..5: sleepAndMoveMouse(randomrange(1000, 1500));
6..7: wait(randomrange(8000, 12000));
8..10: randomCameraAngle(MS_ANGLE_HIGH);
11..15: smallRandomMouse();
16..18: mouseOffClient(OFF_CLIENT_TOP);
19..21: mouseOffClient(OFF_CLIENT_RANDOM);
end;
end;

begin
clearDebug();
setupSRL();

repeat // these 3 procedures will repeat forever
withDraw();
acceptButton();
anvil();
waiiit();
acceptButton();
waitSmith();
antiban();
waitSmithtwo();
deposit();
walk();
Withdraw();
until false;

end

KeepBotting

2014-12-11 21:30:35

The fix for that error is in the Github repo but for some reason hasn't made its way to the auto updater yet

Quick fix: replace your production.simba with this (right-click and save link as) http://puu.sh/dr1lc.simba

Also it's a good idea to put your code in Simba tags like so

program ArtisanSmelter;
{$DEFINE SMART}
{$I SRL-6/SRL.Simba}


procedure withDraw();
var
draw: TBox; //declare TBox variable
begin
draw := intToBox(273, 149, 303, 170); //top left, bottom right points
mouseBox(draw, MOUSE_LEFT); //left click
wait(randomRange(3500, 4441));
end;
procedure waiiit();
begin wait(randomRange(3500, 4441));
end;

procedure acceptButton();
var
x, y: integer;
begin
wait(randomRange(1113,2546));
while not productionScreen.isOpen() do wait(1);
KeyDown(VK_SPACE);
wait(randomRange(123,936));
KeyUp(VK_SPACE);
sleepAndMoveMouse(1000 + random(2000));
mouseOffClient(OFF_CLIENT_RANDOM);
wait(randomRange(168325, 198512));
end;

procedure anvil();

var
settingsButton: TBox; //declare TBox variable
begin
settingsButton := intToBox(455, 193, 463, 210); //top left, bottom right points
mouseBox(settingsButton, MOUSE_LEFT); //left click
wait(randomRange(3500, 4441));
end;

procedure waitSmith();
begin
wait(randomRange(126000, 130000));
end;


procedure waitSmithtwo();
begin
wait(randomRange(136000, 140000));
end;

procedure deposit();

var
settingsButton: TBox; //declare TBox variable
begin
settingsButton := intToBox(248, 149, 268, 168); //top left, bottom right points
mouseBox(settingsButton, MOUSE_LEFT); //left click
wait(randomRange(3500, 4441));
end;


procedure walk();

var
settingsButton: TBox; //declare TBox variable
begin
settingsButton := intToBox(163, 183, 177, 197); //top left, bottom right points
mouseBox(settingsButton, MOUSE_LEFT); //left click
wait(randomRange(3500, 4441));
end;

procedure antiban;
var
i: integer;
begin

i := random(2000);
case i of
1..3: randomRClickItem();
4..5: sleepAndMoveMouse(randomrange(1000, 1500));
6..7: wait(randomrange(8000, 12000));
8..10: randomCameraAngle(MS_ANGLE_HIGH);
11..15: smallRandomMouse();
16..18: mouseOffClient(OFF_CLIENT_TOP);
19..21: mouseOffClient(OFF_CLIENT_RANDOM);
end;
end;

begin
clearDebug();
setupSRL();

repeat // these 3 procedures will repeat forever
withDraw();
acceptButton();
anvil();
waiiit();
acceptButton();
waitSmith();
antiban();
waitSmithtwo();
deposit();
walk();
Withdraw();
until false;

end

Congrats on the release :)

***

As far as critique, the main things I see are your use of Mouseboxes and waits, and your lack of use of mouseovertext.

withDraw(), anvil(), deposit(), walk(), are all procedures that use mouseboxes when they could be using other things.

1. For withDraw(), I'm not quite sure what you're clicking, but a DTM or BMP would work more effectively than a mousebox. Even if you were to just use some sort of verification that the interface (or whatever) is opened before clicking blindly. Does the button display text when you mouse over it? If so, you may want to look into isMouseOverText().

2. anvil() clicks an anvil, I assume? Mouseboxes are very bad for clicking game objects, since some of them move around, and the camera angle isn't always constant. Look into mainScreen.findObject()

3. deposit() - I hope this isn't interacting with the bank. I don't know much about the artisan workshop but I'm pretty sure you have to deposit ores into it to receive xp. so I'll assume that's what this does. Again, a DTM or BMP along with mouseovertext checks if possible would make this work like a dream.

4. walk() - Uh-oh. Blind clicking to walk places is a big no-no. Does this click the minimap or the mainscreen? Both are less than ideal. Look into SPS (SRL Positioning system), it's the best solution for walking.

Now for waits. waiiit(), waitSmith(), and waitSmithTwo() all use randomRange wait times. Randomrange is good, but still pretty static. You could mix it up a bit with something called a conditional wait.

It'd go a bit like this:

procedure waitProgressScreen();
var
t:TTimeMarker;
begin
t.start();
repeat
wait(500);
if (not progressScreen.isOpen()) then
exit;
until (t.getTime() > 50000); //50 second timeout - set it higher if you need
end; //basically a failsafe so we don't get stuck in a loop

Don't hesitate to contact me with any question :)

rsplayer

2014-12-11 22:20:25

Thanks for the help. It worked for me.

rj

2014-12-11 22:30:46

Might want to look into SPS :) aimless clicking the mininmap is a dangerous game sir

kozak94

2014-12-12 09:44:38

Thank you very much guys! I wrote this in my limited spare time due to finals and exams. I will look through guides to start using the DTM or BMP. I appreciate how detailed KeepBotting was to my script and I thank you. I thank you again and I'll hopefully have a chance to implement these recommendations once some time frees up.

kozak94

2014-12-12 18:45:48

I made some changes to the script, added some right-clicking options, implemented the timer suggested by KeepBotting. I tried using findobject and findcolor and TPA. However, I could not find a good color match. The color of the room, is the same as the anvils.

-The same problem occurred when I was trying to find a good color match for the deposit bin. It has strains of black/gray which also match the environment.

-Is there another way that I can find the anvil?


program ArtisanSmelter;
{$DEFINE SMART}
{$I SRL-6/SRL.Simba}

procedure withDraw();
var
draw: TBox;
begin
draw := intToBox(273, 149, 303, 170); //top left, bottom right points
mouseBox(draw, MOUSE_RIGHT); //right clicks
chooseOption.select(['ithdraw-ingots']); //chooses ingots option
wait(randomRange(2500, 3441)); //random wait accounts for server lag
end;

procedure waitProgressScreen();
var
t:TTimeMarker;
begin
t.start();
repeat
wait(500);
if (not progressScreen.isOpen()) then
exit;
until (t.getTime() > 250000); //250 second timeout
writeln('Time Elapsed');
end;

procedure delay();
begin
wait(randomRange(3500, 4441));
end;

procedure acceptButton2();
var
x, y: integer;
begin
wait(randomRange(1113,2546));
while not productionScreen.isOpen() do wait(1);
KeyDown(VK_SPACE);
wait(randomRange(123,936));
KeyUp(VK_SPACE);
sleepAndMoveMouse(1000 + random(2000));
mouseOffClient(OFF_CLIENT_RANDOM);
end;

procedure acceptButton1();
var
x, y: integer;
begin
wait(randomRange(1113,2546));
while not productionScreen.isOpen() do wait(1);
KeyDown(VK_SPACE);
wait(randomRange(123,936));
KeyUp(VK_SPACE);
sleepAndMoveMouse(1000 + random(2000));
end;

procedure anvil();

var
settingsButton: TBox; //declare TBox variable
begin
repeat
settingsButton := intToBox(455, 193, 463, 210); //top left, bottom right points
mouseBox(settingsButton, MOUSE_RIGHT); //rightt click
until
chooseOption.select(['mith']); //chooses smith option
wait(randomRange(3500, 4441));
end;

procedure deposit();

var
settingsButton: TBox; //declare TBox variable
begin
settingsButton := intToBox(248, 149, 268, 168); //deposit chute coordinates
mouseBox(settingsButton, MOUSE_RIGHT); //right click
chooseOption.select(['eposit']); //chooses smith option
wait(randomRange(3500, 4441));
end;


procedure walk(); //uses box to walk to a 1-square-meter area
var //right next to the smelter
settingsButton: TBox;
begin
settingsButton := intToBox(163, 183, 177, 197); //top left, bottom right points
mouseBox(settingsButton, MOUSE_LEFT); //left click
wait(randomRange(3500, 4441));
end;

procedure antiban;
var
i: integer;
begin

i := random(2000);
case i of
1..3: randomRClickItem();
4..5: sleepAndMoveMouse(randomrange(1000, 1500));
6..7: wait(randomrange(8000, 12000));
8..10: randomCameraAngle(MS_ANGLE_HIGH);
11..15: smallRandomMouse();
16..18: mouseOffClient(OFF_CLIENT_TOP);
19..21: mouseOffClient(OFF_CLIENT_RANDOM);
end;
end;

begin
clearDebug();
setupSRL();


repeat // these procedures will repeat forever
withDraw();
acceptButton1();
anvil();
delay();
acceptButton2();
waitProgressScreen();
antiban();
deposit();
walk();
Withdraw();
until false;

end

KeepBotting

2014-12-12 19:30:34

From: kozak94
I made some changes to the script, added some right-clicking options, implemented the timer suggested by KeepBotting. I tried using findobject and findcolor and TPA. However, I could not find a good color match. The color of the room, is the same as the anvils.

-The same problem occurred when I was trying to find a good color match for the deposit bin. It has strains of black/gray which also match the environment.

-Is there another way that I can find the anvil?


Simba tags, please. It makes stuff a billion times easier to read


program ArtisanSmelter;
{$DEFINE SMART}
{$I SRL-6/SRL.Simba}

procedure withDraw();
var
draw: TBox;
begin
draw := intToBox(273, 149, 303, 170); //top left, bottom right points
mouseBox(draw, MOUSE_RIGHT); //right clicks
chooseOption.select(['ithdraw-ingots']); //chooses ingots option
wait(randomRange(2500, 3441)); //random wait accounts for server lag
end;

procedure waitProgressScreen();
var
t:TTimeMarker;
begin
t.start();
repeat
wait(500);
if (not progressScreen.isOpen()) then
exit;
until (t.getTime() > 250000); //250 second timeout
writeln('Time Elapsed');
end;

procedure delay();
begin
wait(randomRange(3500, 4441));
end;

procedure acceptButton2();
var
x, y: integer;
begin
wait(randomRange(1113,2546));
while not productionScreen.isOpen() do wait(1);
KeyDown(VK_SPACE);
wait(randomRange(123,936));
KeyUp(VK_SPACE);
sleepAndMoveMouse(1000 + random(2000));
mouseOffClient(OFF_CLIENT_RANDOM);
end;

procedure acceptButton1();
var
x, y: integer;
begin
wait(randomRange(1113,2546));
while not productionScreen.isOpen() do wait(1);
KeyDown(VK_SPACE);
wait(randomRange(123,936));
KeyUp(VK_SPACE);
sleepAndMoveMouse(1000 + random(2000));
end;

procedure anvil();

var
settingsButton: TBox; //declare TBox variable
begin
repeat
settingsButton := intToBox(455, 193, 463, 210); //top left, bottom right points
mouseBox(settingsButton, MOUSE_RIGHT); //rightt click
until
chooseOption.select(['mith']); //chooses smith option
wait(randomRange(3500, 4441));
end;

procedure deposit();

var
settingsButton: TBox; //declare TBox variable
begin
settingsButton := intToBox(248, 149, 268, 168); //deposit chute coordinates
mouseBox(settingsButton, MOUSE_RIGHT); //right click
chooseOption.select(['eposit']); //chooses smith option
wait(randomRange(3500, 4441));
end;


procedure walk(); //uses box to walk to a 1-square-meter area
var //right next to the smelter
settingsButton: TBox;
begin
settingsButton := intToBox(163, 183, 177, 197); //top left, bottom right points
mouseBox(settingsButton, MOUSE_LEFT); //left click
wait(randomRange(3500, 4441));
end;

procedure antiban;
var
i: integer;
begin

i := random(2000);
case i of
1..3: randomRClickItem();
4..5: sleepAndMoveMouse(randomrange(1000, 1500));
6..7: wait(randomrange(8000, 12000));
8..10: randomCameraAngle(MS_ANGLE_HIGH);
11..15: smallRandomMouse();
16..18: mouseOffClient(OFF_CLIENT_TOP);
19..21: mouseOffClient(OFF_CLIENT_RANDOM);
end;
end;

begin
clearDebug();
setupSRL();


repeat // these procedures will repeat forever
withDraw();
acceptButton1();
anvil();
delay();
acceptButton2();
waitProgressScreen();
antiban();
deposit();
walk();
Withdraw();
until false;

end

If you can't find good enough colors, there are a few things you can do

  • Pick colors while zoomed in - it'll allow for more colors to be seen, and you might get lucky and find one that's unique
  • Jack your CTS2 tolerance down manually - subtract the tolerance by one and keep testing it. See if lower tolerance solves anything
  • Limit your search radius. Declare a TBox and fill it with bounds that are small enough to suit your needs. Use it in conjunction with mainScreen.findObject() to produce more favorable results
  • A similiar take on the previous item, sort your TPA from a point like mainScreen.playerPoint or .centerPoint - or sort it from somewhere else, if you know the general location of your object. There are lots of ways to sort TPAs and ATPAS (documentation) - pick the one that suits you.
  • you could potentially just zoom in until the other matching colors are out of sight. Cheap fix, but viable.
  • Use a DTM. DTM object finding is kind of advanced and can be pretty finicky if you don't know what you're doing, but it's possible.

Those are just a few I could think of from the top of my head, I'm sure others will have more to add.

As far as the new code you posted, let's review it a bit.


1) withDraw() is using .select() which is good, but you're still clicking blindly inside a mousebox. Add some mouseovertext or DTM checks

2) delay() is only used once - consider removing it and just calling wait(randomRange())

3) acceptButton2() is still using weird random wait()s - randomRange doesn't cut the mustard. It's random, but it's not conditional, and conditionality is good. Try to apply the conditional wait technique I taught you to this procedure as well.
3.5) acceptButton2() also uses a very aggressively small looped wait() - only one millisecond! Coupled with the fact that a bitmap-finder function is also being called, this procedure has the potential to eat huge amounts of resources during its runtime. Consider making your wait() a bit more tolerant :D

4) anvil() - same as withDraw(), it's using .select() but not much else. Consider improving it using previously discussed methods

5) walk() - So much no. I'm sorry but this is frightening. I can't stress enough how BAD of an idea it is to blind-click for walking. Massive potential for script failure. Please, look into SPS. I promise it will make your life easier in the long run.

In general, the main problem is failsafes - you have none anywhere :( if you run into a bad bit of server lag or a time-lapse during a loss of connection, the script will be completely thrown off because it's just looping actions blindly.


In closing, please don't take all this criticism as negative or let it discourage you. This is just what is necessary to create a script that works well.
It's all very simple once you get the hang of it - and I will help you with anything, ANYTHING along the way so don't hesitate for a moment if you have questions regarding how to go about doing anything I've discussed.

:)