SRL Archive - Research & Development Lounge

obj finder


Waddo

2008-05-15 14:58:31

here it is my object finder

function ThingFinder(cx,cy,PColor:integer; SColor:tIntegerarray;  Text:TStringArray; Tolerance,Precision,scolors:Integer):Boolean;
var px1,px2,py1,py2,Trys,t,ms:Integer;
begin
ms:=mousespeed;
mousespeed:=50;
Repeat
t:=random(scolors);
wait(1000);
writeln(inttostr(trys));
if FindColorspiraltolerance(x,y,PColor,MSx1,MSy1,MSx2,MSy2,2) then
begin
px1 := x-Precision;
px2 := x+Precision;
py1 := y-Precision;
py2 := y+Precision;
if FindColorspiraltolerance(x,y,scolor[t],px1,py1,px2,py2,Tolerance) then
begin
MMouse(x,y,2,2);
if isuptextmulticustom(Text) then result:=true;
end;
end;
trys:=trys+1;
until ((Result=True) or(Trys>=5));
if Result=True then Writeln('Thing Found');
if Result=False then Writeln('Couldnt Find Thing');
Trys:=0;
mousespeed:=ms;
end;

howto declare it

ThingFinder(x,y,7833746,[2702921,3295831,2573652],['ooth','Bank'],10,10,3);

ThingFinder(x,y,a color that is rare ,[secondary colours],[uptext],tolerance,the area around the primary color to look for secondary colors,number of secondary colours)

please test it out and tell me if you have any improvements

Killerdou

2008-05-15 15:41:33

instead of scolors, try Length(SColor) in the script :) and the repeat won't work, it will find the same pixel every time, since it starts looking at x,y so after the first time, it will start looking at the pixel it found the color, so it won't change anything.
honestly it isn't brilliant or anything, but if you make a couple more functions of the same quality and integrate them in a script, you might make it to members:) oh and a hint on object finding: TPA

Waddo

2008-05-15 15:43:58

yes mixster has mentioned tpa but im still learning tpas

but then i will use them

mixster

2008-05-17 08:04:39

function FindObjectWaddo(var x, y: Integer; primCol: Integer; secCols: TIntegerArray; Tol, Precision: Integer; UpText: TStringArray): Boolean;
var
tries, i, ii, iii: Integer;
pPts, sPts, mPts: TPointArray;
sPtsA: array of TPointArray;
begin
Result := False;
while tries <= 5 do
begin
Inc(tries);

// Reset all TPA's just to make sure there aren't old points in it
SetArrayLength(pPts, 0);
SetArrayLength(sPts, 0);
SetArrayLength(mPts, 0);
SetArrayLength(sPtsA, High(SecCols) + 1);
for i := 0 to High(sPtsA) do
SetArrayLength(sPtsA[i], 0);

// Find primary colour matching points into pPts
if not FindColorsTolerance(pPts, primCol, MSX1, MSY1, MSX2, MSY2, Tol) then
Continue;

// Find all secondary colour mathing points into sPtsA[]
for i := 0 to High(secCols) do
begin
FindColorsTolerance(sPtsA[i], secCols[i], MSX1, MSY1, MSX2, MSY2, Tol);
IncEx(ii, High(sPtsA[i]) + 1); // Increase length counter
end;

if ii = 0 then
Continue;
SetArrayLength(sPts, ii); // Set sPts to the same length as all of sPtsA

// Put all points from sPtsA into sPts
for i := 0 to High(sPtsA) do
for ii := 0 to High(sPtsA[i]) do
begin
if High(sPtsA[ii]) = 0 then
Continue;
sPts[iii] := sPtsA[i][ii];
Inc(iii);
end;

// Check all points to see if they are in precision range of a main point and secondary point
for i := 0 to High(pPts) do
for ii := 0 to High(sPts) do
if (InRange(pPts[i].x, sPts[ii].x - Precision, sPts[ii].x + Precision) and (InRange(pPts[i].y, sPts[ii].y - Precision, sPts[ii].y + Precision)))then
begin
SetArrayLength(mPts, High(mPts) + 2);
mPts[High(mPts)].x := pPts[i].x;
mPts[High(mPts)].y := pPts[i].y;
end;

if High(mPts) < 0 then
Continue;

// Check all matching points for UpText matches
for i := 0 to High(mPts) do
begin
MMouse(mPts[i].x, mPts[i].y, 1, 1);
if not IsUpTextMultiCustom(UpText) then
Continue;
x := mPts[i].x;
y := mPts[i].y;
Result := True;
Exit;
end;
end;
end;

Basic TPA version based off Waddo's function with commenting on what the sections do for easy improving if anyone wants to :)
P.S. I know it's pretty unreliable and can end up with 500 same points if you put in a few similar secondary colours and I haven't tested it (except for compile) so it may not even work, but it should atleast run without hitting errors and hopefully work fairly well ;)
Edit: I also use FindColorsTolerance rather than SpiralTolerance as for some reason it kept giving me type mismatches for the last variable even when I put in an integer rather than a variable…