SRL Archive - SRL Archives

FindObjectATPA


Macro_FTW

2009-06-19 04:44:41

FindObjectATPA is kind of like FindObjTPA, but it uses ATPAs. I have also added a version that takes a TIntegerArray of colors.

{*******************************************************************************
function FindObjectATPA(var x, y: Integer; Color, Tol: Integer; Area: (MS, MI, MM); Radius: Integer; UpText: TStringArray): Boolean;
By: Macro_FTW
Description: Attempts to find an object with UpText using the color given and
ATPAs. Uses Tolerance and Spiral colorfinding. Returns true if found, false if
not.
x, y: Where the object is
Color: Color to search for
Tol: Tolerance of that color
Area: MS for Main Screen, MI for Inventory, MM for Minimap
Radius: The 'Radius' parameter for ATPAs
UpText: The uptext the object should have.
*******************************************************************************}
function FindObjectATPA(var x, y: Integer; Color, Tol: Integer; Area: (MS, MI, MM); Radius: Integer; UpText: TStringArray): Boolean;
var
CPoint: TPoint;
InitTPA: TPointArray;
InitATPA: T2DPointArray;
SArea: TBox;
i, MaxIndex, OldCTS: Integer;
begin
OldCTS := GetColorToleranceSpeed;
ColorToleranceSpeed(1); //Not sure if I should do 2 because I'm using RGB tolerance as an arg.
case Area of
MS: begin
SArea.x1 := MSx1;
SArea.y1 := MSy1;
SArea.x2 := MSx2;
SArea.y2 := MSy2;
end;
MI: begin
SArea.x1 := MIx1;
SArea.y1 := MIy1;
SArea.x2 := MIx2;
SArea.y2 := MIy2;
end;
MM: begin
SArea.x1 := MMx1;
SArea.y1 := MMy1;
SArea.x2 := MMx2;
SArea.y2 := MMy2;
end;
end;
FindColorsSpiralTolerance(x, y, InitTPA, Color, SArea.x1, SArea.y1, SArea.x2, SArea.y2, Tol);
InitATPA := TPAtoATPA(InitTPA, Radius);
MaxIndex := High(InitATPA);
for i:=0 to MaxIndex do
begin
CPoint := MiddleTPA(InitATPA[i]);
MMouse(x, y, 5, 5);
wait(100+random(300));
if(IsUpTextMultiCustom(UpText))then
begin
Result := True;
Exit;
end;
end;
ColorToleranceSpeed(OldCTS);
Result := False;
end;

With its variant, which takes an array of colors, as opposed to a single color.
{*******************************************************************************
function FindObjectATPAMC(var x, y: Integer; Colors: TIntegerArray; Tol: Integer; Area: (MS, MI, MM); Radius: Integer; UpText: TStringArray): Boolean;
By: Macro_FTW
Description: Attempts to find an object with UpText using the colors given and
ATPAs. Uses Tolerance and Spiral colorfinding. Returns true if found, false if
not.
x, y: Where the object is post-search
Colors: Colors to search for
Tol: Tolerance of that color
Area: MS for Main Screen, MI for Inventory, MM for Minimap
Radius: The 'Radius' parameter for ATPAs
UpText: The uptext the object should have.
*******************************************************************************}
function FindObjectATPAMC(var x, y: Integer; Colors: TIntegerArray; Tol: Integer; Area: (MS, MI, MM); Radius: Integer; UpText: TStringArray): Boolean;
var
CPoint: TPoint;
InitTPA, ConcatTPA: TPointArray;
InitATPA: T2DPointArray;
SArea: TBox;
i, MaxIndex, OldCTS: Integer;
begin
OldCTS := GetColorToleranceSpeed;
ColorToleranceSpeed(1);
case Area of
MS: begin
SArea.x1 := MSx1;
SArea.y1 := MSy1;
SArea.x2 := MSx2;
SArea.y2 := MSy2;
end;
MI: begin
SArea.x1 := MIx1;
SArea.y1 := MIy1;
SArea.x2 := MIx2;
SArea.y2 := MIy2;
end;
MM: begin
SArea.x1 := MMx1;
SArea.y1 := MMy1;
SArea.x2 := MMx2;
SArea.y2 := MMy2;
end;
end;
MaxIndex := High(Colors);
for i:=0 to MaxIndex do
begin
FindColorsSpiralTolerance(x, y, InitTPA, Colors[i], SArea.x1, SArea.y1, SArea.x2, SArea.y2, Tol);
ConcatTPA := CombineTPA(ConcatTPA, InitTPA);
end;
InitATPA := TPAtoATPA(ConcatTPA, Radius);
MaxIndex := High(InitATPA);
for i:=0 to MaxIndex do
begin
CPoint := MiddleTPA(InitATPA[i]);
MMouse(x, y, 5, 5);
wait(100+random(300));
if(IsUpTextMultiCustom(UpText))then
begin
Result := True;
ColorToleranceSpeed(OldCTS);
Exit;
end;
end;
ColorToleranceSpeed(OldCTS);
Result := False;
end;

Comments, questions, suggestions, criticism, etc. please feel free to post. :)
~Macro

MylesMadness

2009-06-19 04:58:17

I <3 how you did the Area. I never knew you could do that.

Cazax

2009-06-19 05:07:53

FindObjTPA uses ATPA's(TPAToATPAEx). Good job anyway :)

Macro_FTW

2009-06-19 05:14:22

From: MylesMadness
I <3 how you did the Area. I never knew you could do that.


Thanks. :D

From: Cazax
FindObjTPA uses ATPA's(TPAToATPAEx). Good job anyway :)


It does? I need to look in to other functions more. XD. Thanks! :)

marpis

2009-06-19 13:02:09

how can you look for objects with uptext in MM?
also you should add CTS

Macro_FTW

2009-06-19 17:39:25

From: marpis
how can you look for objects with uptext in MM?
also you should add CTS


'Walk here' I believe is the option you have to look for. I know, it's hardly effective, but meh. :rolleyes:

Alright. I will. Thanks. :)


*Updated with CTS mods* Used 1 instead of 2 because, if I recall, 2 only uses HST tol whereas 1 uses RGB tol.