SRL Archive - SRL Suggestions

text.scar - ChooseOption Related


any_one

2011-05-02 21:55:07

I was rather surprised to find that there was no function that took an array of strings and chose an option that contains ALL of those on the same line. I suggest adding such a function:

{*******************************************************************************
function ChooseOptionSameLine(Text : TStringArray) : Boolean;
By: any_one, makers of ChooseOptionMultiEx
Description: Finds and clicks option that contains all strings in Text on the same line.
*******************************************************************************}
function ChooseOptionSameLine(Text : TStringArray) : Boolean;
var
B : TBox;
TPA1, TPA2, TPA : TPointArray;
ATPA, TextTPA : T2DPointArray;
Colors, height : TIntegerArray;
i, j, c : Integer;
begin
Result := False;
GetClientDimensions(B.X2, B.Y2);
B.X1 := 0;
B.Y1 := 0;
Dec(B.X2);
Dec(B.Y2);
FindColorsTolerance(TPA1, 4343893, B.X1, B.Y1, B.X2, B.Y2, 0);
FindColorsTolerance(TPA2, 3950929, B.X1, B.Y1, B.X2, B.Y2, 0);
TPA := CombineTPA(TPA1, TPA2);
If Length(TPA) < 10 Then
Exit;
B.X2 := 0;
B.Y2 := 0;
aTPA := SplitTPAEx(TPA, 20, 20);
SortATPASize(aTPA, True);
B := GetTPABounds(aTPA[0]);
Colors := [13034990, 4231423, 2070783, 65535, 16776960, 9812166, 16777215];
SetArrayLength(aTPA, Length(colors));
for i := 0 to high(colors) do
FindColorsTolerance(aTPA[i], Colors[i], B.X1, B.Y1, B.X2, B.Y2, 3);
TPA := MergeATPA(aTPA);
aTPA := SplitTPAEx(TPA, 15, 1);
SortATPAFromFirstPoint(ATPA, Point(B.X1, B.y1));

SetArrayLength(TextTPA, Length(Text));
SetArrayLength(height, Length(Text));
for i := 0 to High(Text) do
TextTPA[i] := LoadTextTPA(Text[i], UpChars, height[i]);

for i := 0 to High(aTPA) do
begin
c := 0;
for j := 0 to High(Text) do
begin
if FindTextTPAInTPA(height[j], TextTPA[j], aTPA[i], TPA) then
begin
Inc(c);
if (c > High(Text)) then
begin
Result := True;
MouseBoxEx(B.x1 + 5, TPA[0].Y, B.x2 - 5, TPA[0].Y + 5,5, 1);
Exit;
end;
end;
end;
end;

MMouse(B.X1 - 50, B.Y1 - 50, 40, B.Y2 - B.Y1);
Wait(200 + Random(100));
//Mostly copied from chooseoptionMultiEx - this function could be much shorter if
//chooseoptionmultiEx returned x, y coordinates of options
end;

This would be useful for eg. picking up items, which have both Examine and Take options. You could use ChooseOptionSameLine(['ake', itemname]). The function I wrote is just a quick hack based on ChooseOptionMultiEx, but unfortunately there were no option functions that actually returned the position of the option, so it was the only way to do it. If I've missed/duplicated something that is already in the include then please advise me + close thread :)

i luffs yeww

2011-05-02 21:59:13

ChooseOptionMulti? I must be confused about this..

any_one

2011-05-02 22:00:35

ChooseOptionMulti chooses ONE of the strings from its input array, this function is only true when ALL the strings in the array are found in the same line.

i luffs yeww

2011-05-02 22:05:57

Ah. Well I don't know if this is entirely necessary, since there's never an instance where it could mess up with proper coding (the "take/examine X" phenomenon"), but I do like that you made something to fit what you needed, and made it general enough to be a function in SRL. :) Good work.

And by the way, you could just call ChooseOption('ake' + ItemName); and it would only work if that whole thing was found.

any_one

2011-05-02 22:20:28

It won't if you don't know the exact item that it will take. Eg. if my script picks up say runes, I can just search for ['ake', 'rune' ] and it will get all the different types :) And yeah it is specific to something I needed but I thought there would already be something in SRL as it was a fairly general thing.

About it never messing up, in theory it would never mess up with just ChooseOption('rune') since Take is always above Examine, but I observed several times where my script repeatedly clicked Examine rather than Take for whatever reason. This way is 1. more flexible than ChooseOption('ake' + name) and 2. more reliable than ChooseOption(name) :) However I can just include it in my script if it doesn't fit in SRL.