SRL Archive - SRL Archives

MouseColorUptext & WaitFindColorSpiral


Rich

2009-07-04 19:23:39

What they do:

MouseColorUptext:

If it find colour Col at X, Y, it moves the mouse there with Rx, Ry randomness. If the uptext Uptxt is found, it performs Action, and returns true. The correct choices for Action are:
- 0 = Nothing
- 1 = Left click
- 2 = Right click

WaitFindColorSpiral:

Exactly like WaitFindColor except that it uses FindColorSpiralTolerance instead of FindColorTolerance.

Comments?

{*******************************************************************************
function MouseColorUptext(X, Y, Rx, Ry : Integer; Cx1, Cy1, Cx2, Cy2, Col, Tol, MaxTime, Action : Integer; UpTxt : string) : Boolean;
By: R1ch
Description: Waits for a color at X, Y with tolerance Tol, then checks for uptext.
If uptext is found, then performs Action. 0 = Nothing
1 = Left click
2 = Right click
Returns true if Action is performed
*******************************************************************************}

function MouseColorUptext(X, Y, Rx, Ry : Integer; Cx1, Cy1, Cx2, Cy2, Col, Tol, MaxTime, Action : Integer; UpTxt : string) : Boolean;
begin
if not InRange(Action, 0, 2) then
begin
SRL_Warn('MouseColorUptext', 'Incorrect action: ' + IntToStr(Action), warn_AllVersions);
Exit;
end;
if WaitFindColor(X, Y, Cx1, Cy1, Cx2, Cy2, Col, Tol, MaxTime) then
begin
MMouse(X, Y, Rx, Ry);
if WaitUptext(Uptext, MaxTime) then
begin
GetMousePos(X, Y);
if Action > 0 then
1, 2 : Mouse(X, Y, 0, 0, Action = 1);
Result := True;
end;
end;
end;





{*******************************************************************************
function WaitFindColorSpiral(X1, Y1, X2, Y2, Col, Tol, MaxTime: Integer) : Boolean;
By: R1ch
Description: Waits for a color spiraling with tolerance Tol, returns true if found
*******************************************************************************}
function WaitFindColorSpiral(X1, Y1, X2, Y2, Col, Tol, MaxTime: Integer) : Boolean;
var
Time: Integer;
begin
Time := GetSystemTime + MaxTime;
while GetSystemTime < Time do
Begin
Result := FindColorSpiralTolerance(MSCX, MSCY, Col, X1, Y1, X2, Y2, Tol);
If Result then Exit;
end;
end;

EDIT: Some credits to Richard for improving and shortening.

Awkwardsaw

2009-07-04 19:28:23

lookin good :) i like the first one, i would use it a lot

Rich

2009-07-04 19:31:12

Ooh, thanks! What about the second one?

Also, congratulations on the cup! I can see you worked hard for that. You really deserve it.

Richard.

Awkwardsaw

2009-07-04 19:36:49

the second one, its not bad, but a good addition to the little collection of "wait" procedures, and can be usefull :P

and as for the cup, to be honest, i got it by solving my boredness at night when i couldnt sleep, i acutally didnt know you got it by helping with srl, but on the plus side, i can has avvy :D

Rich

2009-07-04 21:42:19

Are there any suggestions you have to improve either of them?

Richard.

Awkwardsaw

2009-07-04 21:44:10

hmm, nope. its better than what i would do tbh ;)

hopefully some one else would post feed back

Rich

2009-07-04 21:51:40

Lol, yeah, that's what I'm hoping for to be honest, and thanks for the great feedback. Meh, might as well rep+ you for your functions, and feedback.

Awkwardsaw

2009-07-04 21:57:39

then i might as well do the same, for the same reasons =P

Richard

2009-07-05 14:44:13

function MouseColorUptext(X, Y, Rx, Ry : Integer; Cx1, Cy1, Cx2, Cy2, Col, Tol, MaxTime, Action : Integer; UpTxt : string) : Boolean;
begin
if not InRange(Action, 0, 2) then
begin
SRL_Warn('MouseColorUptext', 'Incorrect action: ' + IntToStr(Action), warn_AllVersions);
Exit;
end;
if WaitFindColor(X, Y, Cx1, Cy1, Cx2, Cy2, Col, Tol, MaxTime) then
begin
MMouse(X, Y, Rx, Ry);
if WaitUptext(Uptext, MaxTime) then
begin
GetMousePos(X, Y);
if Action > 0 then
1, 2 : Mouse(X, Y, 0, 0, Action = 1);
Result := True;
end;
end;
end;

Got rid of the "end else Exit", as it was at the end so would be useless, got rid of "Result := False" as all booleans are false by default.

Where you had the case, you had " 0: Exit;" which meant that the function would never reach the point to result true, so I changed it all to:

if Action > 0 then
1, 2 : Mouse(X, Y, 0, 0, Action = 1);


function WaitFindColorSpiral(X1, Y1, X2, Y2, Col, Tol, MaxTime: Integer) : Boolean;
var
Time: Integer;
begin
Time := GetSystemTime + MaxTime;
while GetSystemTime < Time do
Begin
Result := FindColorSpiralTolerance(MSCX, MSCY, Col, X1, Y1, X2, Y2, Tol);
If Result then Exit;
end;
end;

Just a few small shortenings on that one.

Rich

2009-07-05 16:00:44

Thanks Richard. I'll change them in the first post.

ZephyrsFury

2009-07-05 16:03:01

I'll add the second function although you can't give yourself full credit for adding one word to it. The first one, I don't think I'll add, its more or less just a combination of two Timing.scar functions and only works for colours anyway. Thanks. :)

Da 0wner

2009-07-05 16:06:31

What about MousePointUpText :D?

Rich

2009-07-05 16:16:01

Ok, thanks Zephy.