PDA

View Full Version : FindColorSprial3



Tootoot222
01-15-2008, 11:20 AM
well i was trying to make my ServantPlanker, and I encountered the problem of trying to find a color that has the uptext of the name of the servant, but if i tried to use FindColorSprial in a repeat loop it would never find a color that is to the left of the previous color that was found, so i made this, but it has to have the "CMouse" in it for the click.

{************************************************* ******************************
procedure CMouse(Left: Boolean);
By: Mutant Squirrle modded by Tootoot222
Description: Clicks mouse at current position.
Notes: Mutant Squirrle made this, and i just took out the "mouse" procedure
************************************************** *****************************}

procedure CMouse(Left:Boolean);
var
a,b,c: Integer;
begin
Wait(60 + Random(30));
GetMousePos(b, c);
HoldMouse(b + 1, c, left);
repeat
Wait(20 + Random(30));
a := a + 1;
until (a > 4);
GetMousePos(b, c);
ReleaseMouse(b, c, left);
Wait(100 + Random(100));
end;

{************************************************* ******************************
function FindColorSprial3(var x,y: Integer; Color,Sx,Sy,Ex,Ey,Tol,Rx,Ry: Integer; Click,Left,UsePhrase: Boolean; Phrase: String; IFrom: Integer):Boolean;
By: Tootoot222
Description: Stores the x,y coords for Color in Sx,Sy,Ex,Ey and if usePhrase = true then it checks the uptext to see if it matches Phrase, and if Click = true then it click at that point.
Use: Use like: FindColorSprial3(x,y,255,0,0,500,500,5,2,2,True,Tr ue,True,'Walk here',1);
************************************************** *****************************}
Function FindColorSprial3(var x,y: Integer; Color,Sx,Sy,Ex,Ey,Tol,Rx,Ry: Integer; Click,Left,UsePhrase: Boolean; Phrase: String; IFrom: Integer):Boolean;
var
z,t,q,w,i,TimesLooked,TimesFound: Integer;
begin
z:= Sx;
t:= Sy;
if(FindColorTolerance(q,w,Color,Sx,Sy,Ex,Ey,Tol)) then
begin
Writeln('Color is in the area spesified');
Z:= Q;
T:= W;
end else
begin
Writeln('Color is NOT in the area spesified');
GetApplication.BringToFront;
Result:= False;
Exit;
end;
repeat
repeat
Writeln('Looked for color '+IntToStr(TimesLooked)+' times, and found the color '+IntToStr(TimesFound)+'Times');
Writeln('Serching for color '+IntToStr(Color)+' At '+IntToStr(z)+','+IntToStr(t));
TimesLooked:= TimesLooked+1;
if(FindColorTolerance(q,w,Color,z,t,z,t,Tol)) then
begin
TimesFound:= TimesFound+1;
Writeln('found color at '+IntToStr(z)+','+IntToStr(t));
MMouse(q,w,Rx,Ry);
i:= 0;
repeat
Wait(165+Random(47));
i:= i+1;
until(i>=4);
if(UsePhrase) then
begin
Writeln('UpText = '+Lowercase(Copy(GetUpText,IFrom,Length(phrase)))) ;
if(Lowercase(Copy(GetUpText,IFrom,Length(phrase))) =LowerCase(Phrase)) then
begin
Result:= True;
x:= q;
y:= w;
if(Click) then
begin
CMouse(Left);
end;
Exit;
end;
end else
begin
Result:= True;
x:= q;
y:= w;
if(Click) then
begin
CMouse(Left);
end;
Exit;
end;
end else
begin
if(FindColorTolerance(q,w,Color,z+1,t,Ex,t,Tol)) then
begin
z:= q;
end else
begin
if(FindColorTolerance(q,w,Color,Sx,t+1,Ex,Ey,Tol)) then
begin
z:= q;
t:= w;
end else
begin
Writeln('Color is NOT within the area of '+IntToStr(z)+','+IntToStr(t)+' to '+IntToStr(Ex)+','+IntToStr(Ey));
Result:= False;
Exit;
end;
end;
end;
z:= z+2;
until(z>= EX);
t:= t+6;
z:= Sx;
until(Y>= Ey+1);
end;

ZephyrsFury
01-15-2008, 11:38 AM
Wouldn't that lag quite a lot? Have you tried use FindObj?

n3ss3s
01-15-2008, 01:24 PM
and if you want to still do the same as FindColorSpiral... Why not use FindColorSpiral? :p Gj though

Tootoot222
01-15-2008, 04:18 PM
@ZephyrsFury, no, it doesn't lag at all
@n3ss3s, FindColorSprial wouldn't find a color that is to the left of the color found last, so i the color i wanted is at 200,200 and there is another color at 300,100, it would find the 300,100 one first then return false for finding the other color

ShowerThoughts
01-15-2008, 04:32 PM
Gj, still don't get it why you don't use findobject

even he is better in that stuff then me :(

Tootoot222
01-15-2008, 04:54 PM
how does FindObject work?

tarajunky
01-15-2008, 05:01 PM
how does FindObject work?

It uses FindColorsSpiralTolerance, which finds every matching color on the screen and returns it as an array of TPoints of the positions of each one (x and y). Then it moves the mouse to each of these points, one at a time, and checks for the uptext.

FindColorsSpiralTolerance is great. It speeds up this kind of searching a whole lot, since it does one big search and collects all the points at the same time. There is quite a bit of computational overhead involved in doing sequential FindColor searches like you're doing here.

n3ss3s
01-15-2008, 05:16 PM
@Tara:

Everything you say in the internet, can, and will be used against you in some amusing way:


function FindObj(var cx, cy: Integer; Text: string; color, tolerance: Integer): Boolean;
var
a, c, i, x1, y1, x2, y2: Integer;
begin
x1 := 245;
y1 := 165;
x2 := 277;
y2 := 185;
repeat
if (not (Loggedin)) then
Break;
a := a + 1;
if (a = 1) or (a = 3) then
c := c + 1;
for i := 1 to c do
begin
if (a = 1) then
begin
x1 := x1 + 30;
x2 := x2 + 30;
end else
if (a = 2) then
begin
y1 := y1 - 20;
y2 := y2 - 20;
end else
if (a = 3) then
begin
x1 := x1 - 30;
x2 := x2 - 30;
end else
if (a = 4) then
begin
y1 := y1 + 20;
y2 := y2 + 20;
end;
if (x1 = 485) and (x2 = 517) then
x2 := x2 - 2;
if (y1 = 325) and (y2 = 345) then
y2 := y2 - 7;
if (x2 > 515) then
Break;
if (FindColorTolerance(cx, cy, color, x1, y1, x2, y2, tolerance)) then
begin
MMouse(cx, cy, 0, 0)
Wait(50+Random(50));
if (IsUpText(Text)) then
begin
Result := True;
Break;
end;
end;
end;
if (a = 4) then
a := 0;
until (x2 > 515) or (Result = True);
end;


No FindColorsSpiralTolerance, though should be =/

tarajunky
01-15-2008, 05:51 PM
LOL, must be another one of the variants, then. FindObjEx is the closest, I guess, but it has all those annoying variables to fill out.

I think the old one got removed. There used to be a FindObj2 and FindObj3 at one time, one of which must have used FindColorsSpiralTolerance, since that's where I learned it from.

n3ss3s
01-15-2008, 05:57 PM
I think the old one got removed. There used to be a FindObj2 and FindObj3 at one time, one of which must have used FindColorsSpiralTolerance, since that's where I learned it from.

Sure... *keeps nodding while the people from hospital wrap tara in the white shirt that ties your arms*

Any chance of FindObj changing to FindColors?