SRL Archive - SRL Suggestions

checkToolBeltFor


Kyle Undefined

2011-12-27 02:13:44

I have been wanting to do something like this ever since it was released, and I didn't see anyone attempt to do this. Here's my take on the ToolBelt. The functions find if an item is in your ToolBelt or not. It works rather well, I was surprised at how simple it was to make this. I'm sure the code can be cleaned up a bit.


function toolBeltScreen() : Boolean;
begin
Result := (CountColorTolerance(1158880, 192, 18, 264, 33, 9) > 120);
end;

function itemSlotFilled() : Boolean;
var
TPA : TPointArray;
tmpCTS : Integer;
begin
tmpCTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(1.86, 0.06);

FindColorsSpiralTolerance(MSCX, MSCY, TPA, 5855064, 211, 199, 298, 273, 9);

ColorToleranceSpeed(tmpCTS);
SetColorSpeed2Modifiers(0.2, 0.2);

Result := Length(TPA) > 0;
end;

procedure openToolBelt();
begin
MouseBox(691, 413, 732, 453, 1);
Wait(RandomRange(250, 750));
end;

procedure setCategory(Category : string);
var
catBox : TBox;
TPA : TPointArray;
tmpCTS : Integer;
begin
case(LowerCase(Category))of
'general' : catBox := IntToBox(161, 86, 188, 107);
'fishing' : catBox := IntToBox(219, 86, 246, 104);
'crafting' : catBox := IntToBox(275, 87, 305, 104);
'farming' : catBox := IntToBox(332, 88, 359, 105);
end;

tmpCTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.34, 0.80);

FindColorsSpiralTolerance(MSCX, MSCY, TPA, 1810641, catBox.X1, catBox.Y1, catBox.X2, catBox.Y2, 9);

ColorToleranceSpeed(tmpCTS);
SetColorSpeed2Modifiers(0.2, 0.2);

if(not(Length(TPA) > 0))then
MouseBox(catBox.X1, catBox.Y1, catBox.X2, catBox.Y2, 1);
end;

function checkToolBeltFor(Category, Tool : string) : Boolean;
var
I, catCount : Integer;
begin
if(not(toolBeltScreen()))then
openToolBelt();
setCategory(Category);

case(LowerCase(Category))of
'general', 'crafting' : catCount := 13;
'fishing' : catCount := 8;
'farming' : catCount := 5;
end;

for I := 1 to catCount do
begin
if(not(FindTextTpa(1158880, 9, 167, 146, 352, 161, Tool, SmallChars, Nothing)))then
begin
Mouse((375 + 397) / 2, (147 + 163) / 2, 1, 1, True);
Wait(RandomRange(250, 750))
end else
Break;
end;

Result := itemSlotFilled;
end;

Here's a test script I used while building it.

program toolBelt;
{$I SRL/SRL.scar}

function toolBeltScreen() : Boolean;
begin
Result := (CountColorTolerance(1158880, 192, 18, 264, 33, 9) > 120);
end;

function itemSlotFilled() : Boolean;
var
TPA : TPointArray;
tmpCTS : Integer;
begin
tmpCTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(1.86, 0.06);

FindColorsSpiralTolerance(MSCX, MSCY, TPA, 5855064, 211, 199, 298, 273, 9);

ColorToleranceSpeed(tmpCTS);
SetColorSpeed2Modifiers(0.2, 0.2);

Result := Length(TPA) > 0;
end;

procedure openToolBelt();
begin
MouseBox(691, 413, 732, 453, 1);
Wait(RandomRange(250, 750));
end;

procedure setCategory(Category : string);
var
catBox : TBox;
TPA : TPointArray;
tmpCTS : Integer;
begin
case(LowerCase(Category))of
'general' : catBox := IntToBox(161, 86, 188, 107);
'fishing' : catBox := IntToBox(219, 86, 246, 104);
'crafting' : catBox := IntToBox(275, 87, 305, 104);
'farming' : catBox := IntToBox(332, 88, 359, 105);
end;

tmpCTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.34, 0.80);

FindColorsSpiralTolerance(MSCX, MSCY, TPA, 1810641, catBox.X1, catBox.Y1, catBox.X2, catBox.Y2, 9);

ColorToleranceSpeed(tmpCTS);
SetColorSpeed2Modifiers(0.2, 0.2);

if(not(Length(TPA) > 0))then
MouseBox(catBox.X1, catBox.Y1, catBox.X2, catBox.Y2, 1);
end;

function checkToolBeltFor(Category, Tool : string) : Boolean;
var
I, catCount : Integer;
begin
if(not(toolBeltScreen()))then
openToolBelt();
setCategory(Category);

case(LowerCase(Category))of
'general', 'crafting' : catCount := 13;
'fishing' : catCount := 8;
'farming' : catCount := 5;
end;

for I := 1 to catCount do
begin
if(not(FindTextTpa(1158880, 9, 167, 146, 352, 161, Tool, SmallChars, Nothing)))then
begin
Mouse((375 + 397) / 2, (147 + 163) / 2, 1, 1, True);
Wait(RandomRange(250, 750))
end else
Break;
end;

Result := itemSlotFilled;
end;

begin
SetupSRL();
ClearDebug();
if(GameTab(tab_Equip))then
GameTab(tab_Equip);
Wait(RandomRange(250, 750));
if(checkToolBeltFor('Fishing', 'Small'))then
WriteLn('Item is in Toolbelt!')
else
WriteLn('Item is NOT in Toolbelt!');
end.

Hope you enjoy! :)

Flight

2011-12-27 03:59:52

This will be handy. Nicely done, Kyle. ;)

NCDS

2011-12-27 08:32:45

That toolBeltScreen function doesn't throw false positives? Sees odd that the color appears nowhere else in RS. Although, I'm not sure which color it is either.

Kyle Undefined

2011-12-27 09:21:26

NCDS, I tested multiple colors from the toolbelt screen and that one isn't the only one that threw false positives for me. I tried it in several banks, as that's where you'd check the toolbelt to begin with most likely.

I tried the gold color of the text, and that threw false positives as well.

Here's an image of what color is being used:

Flight

2011-12-27 10:03:47

If needed you could always do a text search to tell if we're in the menu. I do that for all of my menus.

Kyle Undefined

2011-12-27 10:13:52

True, I could check for "Toolbelt" I guess. I'll change it in a bit. Thanks for that Flight :D

NCDS

2011-12-27 17:24:04

From: Kyle Undefined
True, I could check for "Toolbelt" I guess. I'll change it in a bit. Thanks for that Flight :D


That's what I would do, but I would take a color count of the word instead of actually reading the text, for speed reasons. Assuming that text is always there and the same when the screen is opened.

Kyle Undefined

2011-12-27 20:56:44

I've updated this to have a better detection of the toolBeltScreen. Thanks to Flights and NCDS' suggestions! :D

Coh3n

2011-12-30 22:35:47

Send in a pull request to SRL5. ;)

Kyle Undefined

2011-12-31 00:35:22

Where would this go, exactly?

Coh3n

2011-12-31 02:53:00

Gametab. As if it couldn't get more cluttered. >.<

Kyle Undefined

2011-12-31 02:55:31

Ahh ok, will do. Thanks!

Coh3n

2012-01-03 23:34:46

Merged the pull request, will be pushed to main soon.