[Object.scar] FindObjTPAEx
I slightly shortened and sped up FindObjTPA as well as added a parameter for MaxDistance. So, using this you would be able to select a maximum distance away from you to find the object.
My version:
SCAR Code:
{*******************************************************************************
function FindObjTPAEx(var x, y: integer; color, tol, cts, ObjWidth, ObjHeight, minCount, MaxDist: Integer; UpText: tstringarray): Boolean;
By: Wizzup? and NCDS
Description: Finds object using WizzyPlugin functions.
Starts with a Spiral from x and y.
Put in the color, Tolerance and ColorToleranceSpeed.
If you don't know what colortolerancespeed to choose, put in -1.
ObjWidth and ObjHeight are the parameters TPAToATPAEx uses, thus filtering
the MS's FindColorsSpiralTolerance points in boxes defined by
ObjWidth and ObjHeigth.
minCount is the amount of colors it should at least find in a Object box.
MaxDist is the maximum distance away you want the color found.
UpText, is ofcourse the text the object should have. In the Multi variant the
UpText is a string array.
*******************************************************************************}
function FindObjTPAEx(var X, Y: Integer; Color, Tol, CTS, ObjWidth, ObjHeight, minCount, MaxDist: Integer; UpText: TStringArray): Boolean;
var
I, j, tCTS: Integer;
myPoint: TPoint;
Points: TPointArray;
aPoints: T2DPointArray;
s: string;
begin
if not LoggedIn then exit;
tCTS := GetColorToleranceSpeed;
if tCTS <> 0 then
CTS := 1;
ColorToleranceSpeed(CTS);
FindColorsSpiralTolerance(X, Y, Points, Color, MSX1, MSY1, MSX2, MSY2, Tol);
if Length(Points) = 0 then
begin
ColorToleranceSpeed(tCTS);
Exit;
end;
aPoints := TPAtoATPAEx(Points, ObjWidth, ObjHeight);
SetLength(Points, 0);
for I := 0 to High(aPoints) do
begin
if Length(aPoints[I]) < minCount then
Continue;
myPoint := MiddleTPA(aPoints[I]);
if Distance(myPoint.x, myPoint.y, MSCx, MSCy) > MaxDist then // Without
Continue; //these 2 lines it is just a somewhat shorter/faster version of FindObjTPA
MMouse(myPoint.X, myPoint.Y, 0, 0);
Wait(100 + Random(50));
s := RS_GetUpText;
for j := 0 to High(UpText) do
try
if Pos(uptext[j], s) > 0 then
begin
GetMousePos(X, Y);
Result := True;
Exit;
end;
finally
ColorToleranceSpeed(tCTS);
end;
end;
end;
Original FindObfTPA:
SCAR Code:
{*******************************************************************************
function FindObjTPA(var x, y: integer; color, tol, cts, ObjWidth, ObjHeight, minCount :Integer; UpText: tstringarray): Boolean;
By: Wizzup?
Description: Finds object using WizzyPlugin functions.
Starts with a Spiral from x and y.
Put in the color, Tolerance and ColorToleranceSpeed.
If you don't know what colortolerancespeed to choose, put in -1.
ObjWidth and ObjHeight are the parameters TPAToATPAEx uses, thus filtering
the MS's FindColorsSpiralTolerance points in boxes defined by
ObjWidth and ObjHeigth.
minCount is the amount of colors it should at least find in a Object box.
UpText, is ofcourse the text the object should have. In the Multi variant the
UpText is a string array.
*******************************************************************************}
function FindObjTPA(var X, Y: Integer; Color, Tol, CTS, ObjWidth, ObjHeight, minCount: Integer; UpText: TStringArray): Boolean;
var
I, j, tCTS: Integer;
myPoint: TPoint;
Points: TPointArray;
aPoints: T2DPointArray;
s: string;
begin
Result := False;
if not LoggedIn then exit;
tCTS := GetColorToleranceSpeed;
if CTS * 9 mod 3 <> 0 then
CTS := 1;
ColorToleranceSpeed(CTS);
FindColorsSpiralTolerance(X, Y, Points, Color, MSX1, MSY1, MSX2, MSY2, Tol);
if Length(Points) = 0 then
begin
ColorToleranceSpeed(tCTS);
Exit;
end;
ColorToleranceSpeed(1);
aPoints := TPAtoATPAEx(Points, ObjWidth, ObjHeight);
SetLength(Points, 0);
for I := 0 to High(aPoints) do
begin
if Length(aPoints[I]) < minCount then
Continue;
myPoint := MiddleTPA(aPoints[I]);
MMouse(myPoint.X, myPoint.Y, 0, 0);
Wait(100 + Random(50));
s := RS_GetUpText;
for j := 0 to High(UpText) do
if Pos(uptext[j], s) > 0 then
begin
GetMousePos(X, Y);
Result := True;
ColorToleranceSpeed(tCTS);
Exit;
end;
end;
ColorToleranceSpeed(tCTS);
end;
Hasn't been tested really but as far as I can see, it should work just fine.
Let me know your thoughts.