SRL Archive - RS3 Help

help with mouse over text.


fady

2015-02-24 11:54:45

Hello, everyone.
I've been leeching off the forums for about 3 weeks now, and I've finally found the time to start learning and making my own script. Honestly, you guys do some amazing work and I cant begin to comprehend half of what is written in most scripts.
So, I've read both of TheMayor's tutorials multiple times, and I wanted to work on a simple script that would make headless arrows from shafts+feathers.
just action bar 1, production screen 1, wait till its done, repeat. However, sometimes when I alt tab, keyboard inputs to SMART will stop working, so I wanted to add a fail safe, where if the action bar 1 click didn't open a production window, the script would click on backpack slot one to open the production window and then proceed to create shafts. Which was working good, but I couldn't figure out how to tell the script to stop when i run out of shafts, and this is where I'm at now. I thought I'd add a feature in the fail safe where it would only work if the mouse over text received was "Feather Arrow Shaft", and this is what I have in a script as a whole. It is fairly simple and all the thanks go to The Mayor's tutorials, much of mine are just bits and pieces of his tutorials patched together.
program scriptTemplate;

{$DEFINE SMART} // Always have this to load smart
{$I SRL-6/SRL.simba} // To load the SRL include files
{$I SPS/lib/SPS-RS3.Simba} // To load the SPS include files

procedure declarePlayers();
begin
setLength(players, 1);
with players[0] do
begin
loginName := 'user';
password := 'password';
isActive := true;
isMember := false;
end
currentPlayer := 0;
end;

procedure aBarKeyClick();
begin
typeSend('1', false); // keyboard Actionbar slot 1 (Shafts)

end;

procedure aBarKeyHeadless();
begin
productionScreen.clickStart(); // Click the start button

if progressScreen.isOpen(5000) then // if progressScreen is open within 5 seconds
begin
writeLn('Making headless arrows!');

repeat
wait(1000);
until (not progressScreen.isOpen()); // Repeat waiting 1 second until it's not open anymore
end;
end;

procedure mouseHeadless();
begin
tabBackPack.mouseSlot(1, MOUSE_MOVE); //Move mouse to slot 1

if isMouseOverText(['eather Arrow Shaft']) then
fastClick(MOUSE_Left); // Left click(Shafts)

if productionScreen.isOpen(1500) then // If productionScreen is open within 1.5 seconds
begin
productionScreen.clickStart(); // Click the start button

if progressScreen.isOpen(5000) then // if progressScreen is open within 5 seconds
begin
writeLn('Making headless arrows using failsafe!');

repeat
wait(1000);
until (not progressScreen.isOpen()); // Repeat waiting 1 second until it's not open anymore
end;
end;
end;
// main loop
begin
clearDebug(); // Clear the debug box
smartEnableDrawing := true; // So we can draw on SMART
setupSRL(); // Load the SRL include files
declarePlayers(); // Set up your username/pass

if not isLoggedIn() then // If player isn't logged in then
begin
players[currentPlayer].login(); // Log them in
exitTreasure(); // Exit treasure hunter
minimap.setAngle(MM_DIRECTION_NORTH); // Make compass north and angle high
mainScreen.setAngle(MS_ANGLE_HIGH);
end;

aBarKeyClick();
if not productionScreen.isOpen(1500) then // If productionScreen is not open within 1.5 seconds
begin
mouseHeadless();
end else
aBarKeyHeadless();

end.

This is the script so far. I have it click action bar 1 and wait for a production screen, if not open, use mouse to move over slot 1 and detect the mouse over text, but it always comes back as false. I havent figured out how im going to use the mouse over text response to stop my script because i only know how to repeat until false, but i haven't been able to get the mouse over text to work in the first place.
Any help would be much appreciated
Thank you

fady

2015-02-24 12:33:46

Sorry, I dont mean to double post, but i figured it out, I had it eather Arrow Shaft, not eather Arrow shaft.
Now all I need to figure out is how to make it stop when its false!.
Thanks again

Trollcrank

2015-02-24 12:54:15

From: fady
Now all I need to figure out is how to make it stop when its false!.

If you want it to end whenever there is no item in the first slot of the backpack then use this:

if (not tabBackpack.isItemInSlot(1)) then
TerminateScript;

HKbotz

2015-02-24 12:54:24

From: fady
Now all I need to figure out is how to make it stop when its false!


if isMouseOverText(['eather Arrow shaft']) then
fastClick(MOUSE_Left) // Left click(Shafts)
else
exit();// exits the procedure, could use terminateScript() if you want to stop script

the bank

2015-02-24 13:02:37

An ugly, albeit easy way to create backwards flow in your scripts is through the use of labels.

However, used improperly, they can be very dangerous. Typically, I discourage the use of them, however an instance like this is a time that it might fit.

Note that labels must be defined ABOVE any var or const variables in the script.


label checkAgain;

begin
//other script shit above
checkAgain:
//Find object here
Mouse(Point(ObjectX, ObjectY), MOUSE_MOVE);
if isMouseOverText(['eather Arrow shaft']) then
fastClick(MOUSE_Left) // Left click(Shafts)
else
goto checkAgain;
end.

HKbotz

2015-02-24 13:39:59

From: the bank
An ugly, albeit easy way to create backwards flow in your scripts is through the use of labels.

However, used improperly, they can be very dangerous. Typically, I discourage the use of them, however an instance like this is a time that it might fit.

Note that labels must be defined ABOVE any var or const variables in the script.


label checkAgain;

begin
//other script shit above
checkAgain:
//Find object here
Mouse(Point(ObjectX, ObjectY), MOUSE_MOVE);
if isMouseOverText(['eather Arrow shaft']) then
fastClick(MOUSE_Left) // Left click(Shafts)
else
goto checkAgain;
end.


Why not just use a loop?( I added a timeout as well since infinite loops are really bad too.)
var
timer: TTimeMarker;
p: TPoint;
begin
timer.start();
repeat
mouse(p);
if isMouseOverText(['eather Arrow shaft']) then
begin
fastClick(MOUSE_LEFT); // Left click(Shafts)
break;
end;
until(timer.getTime() >= 5000); //5 second timeout
end.
goto can very quickly make your code difficult to follow, and in this case isn't really necessary.

the bank

2015-02-24 13:51:07

From: HKbotz
Why not just use a loop?( I added a timeout as well since infinite loops are really bad too.)
var
timer: TTimeMarker;
p: TPoint;
begin
timer.start();
repeat
mouse(p);
if isMouseOverText(['eather Arrow shaft']) then
begin
fastClick(MOUSE_LEFT); // Left click(Shafts)
break;
end;
until(timer.getTime() >= 5000); //5 second timeout
end.
goto can very quickly make your code difficult to follow, and in this case isn't really necessary.


Hence why I said they're dangerous and ugly.

However, I would argue that loop seems random enough to reduce readability as well. It also doesn't actually refind the object again, and will therefore fail everytime if it fails the first time.

EDIT:

Ideal solution is to put the code in a function that returns true if it succeeded.

masterBB

2015-02-24 14:10:00

From: the bank
An ugly, albeit easy way to create backwards flow in your scripts is through the use of labels.

However, used improperly, they can be very dangerous. Typically, I discourage the use of them, however an instance like this is a time that it might fit.

Note that labels must be defined ABOVE any var or const variables in the script.


label checkAgain;

begin
//other script shit above
checkAgain:
//Find object here
Mouse(Point(ObjectX, ObjectY), MOUSE_MOVE);
if isMouseOverText(['eather Arrow shaft']) then
fastClick(MOUSE_Left) // Left click(Shafts)
else
goto checkAgain;
end.


This is no way meant offensive. But I think this is not a good example of a label. Using the label like this makes the unnesecary complex. For beginners using goto and labels is not recommended. Often people are jumping out or in scopes they shouldn't. Creating hard to fix errors or unexpected behavior.


function ClickFeatherShaft: Boolean;
var
timer: TTimeMarker;
x, y: Integer;
begin
timer.Start();
repeat
//Find object here
Mouse(Point(ObjectX, ObjectY), MOUSE_MOVE);
if isMouseOverText(['eather Arrow shaft']) then
begin
fastClick(MOUSE_Left); // Left click(Shafts)
Result := True;
Exit;
end;
until(timer.GetTotalTime() > 1 * 60 * 1000);
writeln('Couldn''t find object in 1 minute.');
Result := False;
end.

e: got ninja'd badly, oh well ^^

fady

2015-02-24 15:02:09

Thanks for all your responses guys, some of them were way too complicated for me understand, but hopefully I will be able to soon! :D.
I just used terminatescript() like
    tabBackPack.mouseSlot(1, MOUSE_MOVE);  //Move mouse to slot 1

if isMouseOverText(['eather Arrow shaft']) then
begin
fastClick(MOUSE_Left); // Left click(Shafts)
end else
terminateScript()

I figured that way, if the key click on the actionbar fails, and when the mouse goes to click the inventory slot and it doesnt find anything, then it means its done.
but reading through the comments, is there a possibility that the mouse over text detect will make a mistake and give me a false negative?

KeepBotting

2015-02-24 16:24:13

From: fady
Thanks for all your responses guys, some of them were way too complicated for me understand, but hopefully I will be able to soon! :D.
I just used terminatescript() like
    tabBackPack.mouseSlot(1, MOUSE_MOVE);  //Move mouse to slot 1

if isMouseOverText(['eather Arrow shaft']) then
begin
fastClick(MOUSE_Left); // Left click(Shafts)
end else
terminateScript()

I figured that way, if the key click on the actionbar fails, and when the mouse goes to click the inventory slot and it doesnt find anything, then it means its done.
but reading through the comments, is there a possibility that the mouse over text detect will make a mistake and give me a false negative?


OCR is very good. I don't think isMouseOverText() will ever mess up. If it does, it's one in a million.

You're probably safe doing this, but a DTM might possibly make for a more stable experience, plus learning them now will only help you later as you'll get to using them a lot.

fady

2015-02-24 17:01:23

Oh ok. Thank you very much, my script is functional now. I'll add some antiban to it and then repost it in the first scripts section! :D

KeepBotting

2015-02-24 17:02:42

From: fady
Oh ok. Thank you very much, my script is functional now. I'll add some antiban to it and then repost it in the first scripts section! :D

Welcome & an early gratz on the release :p