SRL Archive - SRL Suggestions

ChooseTabbedOptionMulti


Flight

2011-08-03 07:29:51

[Updated 9-30-12]

function ChooseTabbedOptionMulti(OptionsA, OptionsB: TStringArray): Boolean;

Parameters
  • OptionsA: First set of options to look for in the Options Menu.
  • OptionsB: Second (and final) set of options to search for & choose.

Usage
This is used in the instance the right-click option you're trying to choose isn't visible, rather it's in one of the sub-menus (tab menu). For example, if you're trying to open a bank chest using the option 'Use' but it wasn't visible, you could use this instead: "ChooseTabbedOptionMulti(['Bank','Chest'], ['Use']);". Initially it will check if any of OptionsB are already visible and if so, click them. If not, the function will search for & move to any visible options of OptionsA and then choose the visible OptionsB (if found).

First, throw this procedure in mouse.simba, anywhere under the WindMouse procedure:

{*******************************************************************************
procedure AccurateMMouse(eX, eY, ranX, ranY: Integer);
By: Flight
Description: Same as MMouse but uses a much straighter path; required
for choosing tabbed options.
*******************************************************************************}
Procedure AccurateMMouse(eX, eY, ranX, ranY: Integer);
var
randSpeed: extended;
X,Y,MS: integer;
begin
MS := MouseSpeed;
randSpeed := (random(MouseSpeed) / 2.0 + MouseSpeed) / 10.0;
GetMousePos(X, Y);
WindMouse(X, Y, RandomRange(eX-ranX, eX+ranX), RandomRange(eY-ranY,eY+ranY), 14, 3, 10.0/randSpeed, 15.0/randSpeed, 10.0*randSpeed, 10.0*randSpeed);
MouseSpeed := MS;
end;

This is required choosing a tabbed option.

Now go into text.simba and under the "GetChooseOptions" function add this:

{*******************************************************************************
Function GetTabbedOptions(BigBox: TBox; TextType: string): Array of TOptions;
By: Flight
Description: Grabs all the options of the right-click tab menu, if visible.
*******************************************************************************}
Function GetTabbedOptions(BigBox: TBox; TextType: string): Array of TOptions;
var
B, BB, sB, TabBox: TBox;
FilteredTPA, TPA, TPA1, TPA2: TPointArray;
ATPA, tempatpa: T2DPointArray;
I, L, target, bmp,w,h, cts: Integer;
BoxColors: TIntegerArray;
begin
target := GetImageTarget;
GetClientDimensions(B.X2, B.Y2);
B := IntToBox(0, 0, B.X2-1, B.Y2-1);

//Start tab box
cts := GetColorToleranceSpeed;
ColorToleranceSpeed(1);

BoxColors := [131843, 3682593, 3552822];
SetLength(ATPA, Length(BoxColors));
for i := 0 to High(BoxColors) do
FindColorsTolerance(ATPA[i], BoxColors[i], B.X1, B.Y1, B.X2, B.Y2, 0);

TPA := MergeATPA(ATPA);
//Remove the initial bigbox
ClearTPAFromTPAWrap(TPA,TPAFromBox(BigBox),FilteredTPA);
If Length(FilteredTPA) < 100 Then
begin
ColorToleranceSpeed(cts);
Exit;
end;

ATPA := SplitTPA(FilteredTPA, 4);
For i := 0 to High(ATPA) do
begin
B := GetTPABounds(ATPA[i]);
if ((B.x2-B.x1) > 90) and ((B.y2-B.y1) > 18) then
Break
else
B := IntToBox(0, 0, 0, 0);
end;

If (B.x2 = 0) then
begin
ColorToleranceSpeed(cts);
Exit;
end;

TabBox := B;

SetColorToleranceSpeed(3);
FindColorsTolerance(TPA1, 4996381, B.X1, B.Y1, B.X2, B.Y2, 18);
sB := GetTPABounds(TPA1);
ReturnPointsNotInTPAWrap(TPA1, sB, TPA);
FindColorsTolerance(TPA2, 460291, B.X1, B.Y1, B.X2, B.Y2, 6);
SetColorToleranceSpeed(cts);

bmp := CreateBitmap(B.X2-B.X1+2, B.Y2-B.Y1+2);
OffsetTPA(TPA, Point(-B.X1, -B.Y1));
OffsetTPA(TPA2, Point(-B.X1, -B.Y1));
FastDrawClear(bmp, 0);
DrawTPABitmap(bmp, TPA, clRed);
DrawTPABitmap(bmp, TPA2, clPurple);
ocr_FilterUpTextByCharacteristics(GetMufasaBitmap(bmp));
GetbitmapSize(bmp,w,h);
SetTargetBitmap(bmp);
SetLength(ATPA, H div 16);
for i := 0 to High(ATPA) do
FindColorsTolerance(ATPA[i], clRed, 0, 2+i*16, W-1, 18+i*16, 0);
L := High(ATPA);
SortATPAFromFirstPointY(ATPA, Point(w div 2,0));

SetArrayLength(Result, Length(ATPA));
Result[0].BigBox := TabBox;
for i := 0 to high(ATPA) do
begin
TPA := ATPA[i];
tempatpa := SplitTPAEx(TPA, 1, 10);
SortATPAFromFirstPointX(tempatpa, Point(0, 0));
Result[i].Str := GetTextATPA(tempatpa, 5, 'UpCharsEx');
BB := GetTPABounds(ATPA[i]);
Result[i].Bounds := IntToBox(BB.X1+B.X1, BB.Y1+B.Y1, BB.X2+B.X1, BB.Y2+B.Y1);
setlength(tempatpa,0);
setlength(TPA,0);
end;
ColorToleranceSpeed(cts);
SetImageTarget(target);
FreeBitmap(bmp);
end;

And finally underneath the "OptionsExist" function add this bit:

function ChooseTabbedOptionMulti(OptionsA, OptionsB: TStringArray): Boolean;
var
T: TPoint;
B,BigBox,TabBox: TBox;
i, H, ii, L, x: Integer;
Options,TOptions: array of TOptions;
begin
Result := False;
Options := GetChooseOptions('All');
if (Length(Options) < 1) then
Exit;
BigBox := Options[0].BigBox;

//Initially check TextsB
if OptionsExist(OptionsB, False) then
begin
Result := ChooseOptionMulti(OptionsB);
Exit;
end;

//Mouse first set of text options
H := High(Options);
L := High(OptionsA);
for i := 0 To L do
begin
for ii := 0 to H do
If Pos(OptionsA[i], Options[ii].Str) > 0 Then
begin
Result := True;
B := Options[ii].Bounds;
GetMousePos(T.x, T.y);
if (not PointInBox(T, B)) then
MouseBoxEx(B.x1 + 5, B.Y1, B.x2 - 5, B.Y1 + 5,5, mouse_move);
end;
end;

//Secondary options
TOptions := GetTabbedOptions(BigBox,'All');
if (Length(TOptions) < 1) then
Exit;
L := High(OptionsB);
H := High(TOptions);
for i := 0 To L do
begin
for ii := 0 to H do
If Pos(OptionsB[i], TOptions[ii].Str) > 0 Then
begin
Result := True;
TabBox := TOptions[0].BigBox;
GetMousePos(T.x, T.y);
AccurateMMouse(RandomRange(TabBox.X1, TabBox.X2), T.Y, 0, 3);
Wait(200 + Random(100));
B := TOptions[ii].Bounds;
GetMousePos(T.x, T.y);
if PointInBox(T, B) then
ClickMouse2(Mouse_left)
else
MouseBoxEx(B.x1 + 5, B.Y1, B.x2 - 5, B.Y1 + 5,5,mouse_left);
Exit;
end;
end;
B := TOptions[0].BigBox;
x := Max(B.X1 - 52, 0);
if x = 0 then
x := B.X2+10;
MMouse(x, Max(B.Y1 - 50, 0), 40, B.Y2-B.Y1);
Wait(200 + Random(100));
end;

If you added everything in the correct locations it should compile right up. I'll also attach mouse.simba & text.simba for you lazy ones.

[YOUTUBE]eZTAtZi-JgU[/YOUTUBE]
~
[YOUTUBE]xk1K5APmj_8[/YOUTUBE]

P.S. This is indeed compatible with Lape.

Coh3n

2012-04-13 21:38:32

I can't seem to get this to work. I think it's because of the way ChooseOptionMultiEx works. It finds the background color from the mouse position, so the "sub-menu" location wouldn't be detected properly.


(*
ChooseOptionTabbed
~~~~~~~~~~~~~~~~~~

.. code-block:: pascal

function ChooseOptionTabbed(Txt1, Txt2: TStringArray): Boolean;

By passes the "sub-menus" that appear in option menus in a crowded area. 'Txt1'
are the hover options, and Txt2 are the final options. If Txt2 alread exists
without hovering, it will click it. This function should eventually replace
ChooseOption.

.. note::

by Flight
Last Updated: April 13th, 2012 by Coh3n

Example:

.. code-block:: pascal

Mouse(bank.x, bank.y, 5, 5, mouse_Right);
Result := ChooseOptionTabbed(['Banker'], ['Bank']);
*)
function ChooseOptionTabbed(Txt1, Txt2: TStringArray): Boolean;
begin
Result := False;

if (OptionsExist(Txt2, False)) then
Result := WaitOptionMultiEx(Txt2, 'All', ClickLeft, 300)
else
if (ChooseOptionMultiEx(Txt1, 'All', Move)) then
Result := WaitOptionMultiEx(Txt2, 'All', ClickLeft, 300);
end;

Flight

2012-04-13 22:28:10

From: Coh3n
I can't seem to get this to work. I think it's because of the way ChooseOptionMultiEx works. It finds the background color from the mouse position, so the "sub-menu" location wouldn't be detected properly.


So then the version you posted did work for you? It's been so long since I posted this. :o

Coh3n

2012-04-13 22:29:51

No, it doesn't work. And I know it's been a while, I was just looking at unresolved suggestions and I think something like this needs to be added.

Flight

2012-04-13 22:37:19

It's not easy to produce a tabbed menu right when I need it for testing but if you give me some time today I can try and work on this.

Coh3n

2012-04-13 22:45:23

I was having trouble with that as well. Take as much time as you need. :)

Yago

2012-04-15 12:13:18

I used to get a lot of tabbed menus at w1 lumby bank… just make sure you angle your camera in a way where alot of people get chosen…

Flight

2012-09-29 04:38:58

Well Coh3n I finally have this working correctly, but it requires a couple other functions to work. I gotta say, it took me a bit of time this morning just to make this. :/

I have it working smooth in AeroLib; implanting this into SRL will require, like I said, extra functions. I guess it depends on if you want this in the include or not. Let me know what you think.

[YOUTUBE]eZTAtZi-JgU[/YOUTUBE]
~
[YOUTUBE]xk1K5APmj_8[/YOUTUBE]

Benny

2012-09-29 04:41:42

From: Flight
Well Coh3n I finally have this working correctly, but it requires a couple other functions to work. I gotta say, it took me a bit of time this morning just to make this. :/

I have it working smooth in AeroLib; implanting this into SRL will require, like I said, extra functions. I guess it depends on if you want this in the include or not. Let me know what you think.

[YOUTUBE]eZTAtZi-JgU[/YOUTUBE]
~
[YOUTUBE]xk1K5APmj_8[/YOUTUBE]


Nice work. This looks very slick.. How long exactly did it take to do that?

(sorry for newbie questions)
what method of locating did you use, uptext?

Flight

2012-09-29 04:52:31

I believe under two hours of hit-and-miss. I had to go through multiple attempts to find one that worked accurately.

It basically works the same way as our current method of grabbing right-click options (TOptions).

Benny

2012-09-29 07:46:01

From: Flight
I believe under two hours of hit-and-miss. I had to go through multiple attempts to find one that worked accurately.

It basically works the same way as our current method of grabbing right-click options (TOptions).

Oh okay brilliant!
Wow that's impressive, I still struggle with the basics.
Ok so would we implement this as an additional method of making us look more human or not?
I mean after watching the videos it looked so nifty

Ashaman88

2012-09-29 09:12:33

This is great for the large stacks of people! Is there a way to detect if the second option box is needed and just choose the normal chooseoption if it's not needed (ie can detect if no tabs present)?

Flight

2012-09-29 10:10:37

From: Ashaman88
This is great for the large stacks of people! Is there a way to detect if the second option box is needed and just choose the normal chooseoption if it's not needed (ie can detect if no tabs present)?


Yes, here's the parameters:

function AL_ChooseTabbedOptionMulti(TextA, TextB: TStringArray): Boolean;

TextA is your (first) array of text that you search for incase TextB isn't visible in the initial Options Menu, and obvious TextB is what you will ultimately be choosing. If any of TextB is already visible in the Options Menu then it will be chosen first and return result True.

@-Benny:
I can make this for SRL if Coh3n (or others) would like me to. IMO we should have already had it as a basic core function as it's not just another add-on or antiban, this is really required in some instances.

It will obviously be included in AeroLib whenever I finish(…) it.

Ashaman88

2012-09-29 10:14:17

From: Flight
Yes, here's the parameters:

function AL_ChooseTabbedOptionMulti(TextA, TextB: TStringArray): Boolean;

TextA is your (first) array of text that you search for incase TextB isn't visible in the initial Options Menu, and obvious TextB is what you will ultimately be choosing. If any of TextB is already visible in the Options Menu then it will be chosen first and return result True.

@-Benny:
I can make this for SRL if Coh3n (or others) would like me to. IMO we should have already had it as a basic core function as it's not just another add-on or antiban, this is really required in some instances.

It will obviously be included in AeroLib whenever I finish(…) it.


That's awesome and I totally agree it should be in the include

NCDS

2012-09-29 10:24:31

Indeed nice work Flight. If you can get this working in SRL, then by all means please do. This would be some nice new functionality for srl6. ;)

Flight

2012-09-30 04:40:45

There ya go. :)

Edit:
Could a moderator also change this thread title to "ChooseTabbedOptionMulti"? Please & thank you.

Coh3n

2012-09-30 10:29:42

Honestly, this should just be the standard ChooseOption for SRL-6. Nice work, Flight. :)

NKN

2012-09-30 12:23:01

Beautiful work as always Flight. :)



Question for Coh3n:
Whens that SRL-6 come out, maybe a behind the scenes? ;)

Coh3n

2012-09-30 19:29:53

From: NKN
Question for Coh3n:
Whens that SRL-6 come out, maybe a behind the scenes? ;)
It's too early to know an actual release date, but I wouldn't expect it to be soon.