SRL Archive - SRL Archives

FindColorArea (My first usefull function)


JAD

2007-04-13 19:26:36

Edit: Fixed it so that the 9 boxes are now on the main screen. I accidentally made all the coords before with the inventory and the chat…etc. and the whole other RS screen. Now its divided up 9 boxes over the main screen, and this should give it more of a reason to be used. Enjoy! :D


Well, this is a very long function, but it is very useful :) I just tested it for clicking a willow tree, and it worked GREAT! here was the problem I was having before using this function, which inspired me to make this.

Now, heres a problem I have seen in chicken killers and other things. The script finds the color of the wall or something and its looking for the chicken. It moves the mouse to the wall, and it doesn't find the text up ttack and hicken…etc. But the thing is, it keeps looking for the color from the same point because it checks top left corner or spirals out from same point…etc., making it repeatedly move the mouse onto that color not finding the text, and not looking at a new part of the runescape screen for the chicken. Now this was a problem, but not anymore! (hopefully :P)

In this function, I have divided up the runescape screen into 9/9 equally, and the script checks your specified box(s), and if it doesn't find the text once it moves the mouse to the color in the first box, it moves it on to the second box, then third…etc. until it finds it (and if you made it look in those other boxes..etc.) This may sound confusing, but heres in short what it does.

Looks for color in specified boxes going down the list in order (b1 b2..etc)

If it finds the color, it moves the mouse to it and looks for the text you specified, and if its there, it results true, clicks if told to and exits.
if the color is not up where it found the color, it goes on to looking in the next box.

Goes through the list of boxes, and if it doesn't find the color/text in any of them it Exits.. Because most likely the color isn't on the screen.

Here it is, the ultimate function! :D

note: The reason this isn't in my script yet is because I haven't had time today to put it in, and I just started making this function 3 hours ago, and finished now :)

//0, 338 top to bottom
//113 = 1/3 the distance top to bottom
//0,516 all the way left to all the way right.
//167 = 1/3 the distance left to right

program New;
{.include SRL/SRL.scar}

{***************************************************************************************************
function FindColorArea(Color, b1, b2, b3, b4, b5, b6, b7, b8, b9: Integer; Text: String; Click: Boolean;): Boolean;

Descriprion: Finds color in specified boxes on MS. there are 9 boxes on the WHOLE runescape screen. each being 1/9 of the screen.
Searches boxes in order, until it finds the text + color in the box, then exits and stops searching.
Text is the text you are looking for if we find the color in a box,
it will move the mouse to the color and then look for the text, and result true if found. if not found,
it moves on to looking in next box. Also clicks if text is up if told too.

Boxes names are 1, 2, 3, 4, 5, 6, 7, 8, 9. Heres where they are in order:
top left, top middle, top right, middle left, middle middle, middle right, bottom left, bottom middle
bottom right, 0 to not check a box.
***************************************************************************************************}

function FindColorArea(Color, Tol, b1, b2, b3, b4, b5, b6, b7, b8, b9: Integer; Text: String; Click: Boolean): Boolean;
var
JADX1, JADY1, JADX2, JADY2: Integer;

begin

case b1 of

1: if(b1 = 1)then
begin
JADX1:=0;
JADY1:=0;
JADX2:=167;
JADY2:=113;
end;

2: if(b1 = 2)then
begin
JADX1:=167;
JADY1:=0;
JADX2:=334;
JADY2:=113;
end;

3: if(b1 = 3)then
begin
JADX1:=334;
JADY1:=0;
JADX2:=501;
JADY2:=113;
end;

4: if(b1 = 4)then
begin
JADX1:=0;
JADY1:=113;
JADX2:=167;
JADY2:=226;
end;

5: if(b1 = 5)then
begin
JADX1:=167;
JADY1:=113;
JADX2:=334;
JADY2:=226;
end;

6: if(b1 = 6)then
begin
JADX1:=334;
JADY1:=113;
JADX2:=501;
JADY2:=226;
end;

7: if(b1 = 7)then
begin
JADX1:=0;
JADY1:=226;
JADX2:=167;
JADY2:=339;
end;

8: if(b1 = 8)then
begin
JADX1:=167;
JADY1:=226;
JADX2:=334;
JADY2:=339;
end;

9: if(b1 = 9)then
begin
JADX1:=334;
JADY1:=226;
JADX2:=501;
JADY2:=339;
end;


end;

if(not(b1=0))then
begin
if(FindColorTolerance(x,y, Color, JADX1, JADY1, JADX2, JADY2, Tol))then
begin
MMouse(x,y,2,2);
if(IsUpText(Text))then
begin
Result:=True;
if(Click=true)then
begin
Mouse(x,y,2,2,true);
end;
Exit;
end;
end;
end;

case b2 of

1: if(b2 = 1)then
begin
JADX1:=0;
JADY1:=0;
JADX2:=167;
JADY2:=113;
end;

2: if(b2 = 2)then
begin
JADX1:=167;
JADY1:=0;
JADX2:=334;
JADY2:=113;
end;

3: if(b2 = 3)then
begin
JADX1:=334;
JADY1:=0;
JADX2:=501;
JADY2:=113;
end;

4: if(b2 = 4)then
begin
JADX1:=0;
JADY1:=113;
JADX2:=167;
JADY2:=226;
end;

5: if(b2 = 5)then
begin
JADX1:=167;
JADY1:=113;
JADX2:=334;
JADY2:=226;
end;

6: if(b2 = 6)then
begin
JADX1:=334;
JADY1:=113;
JADX2:=501;
JADY2:=226;
end;

7: if(b2 = 7)then
begin
JADX1:=0;
JADY1:=226;
JADX2:=167;
JADY2:=339;
end;

8: if(b2 = 8)then
begin
JADX1:=167;
JADY1:=226;
JADX2:=334;
JADY2:=339;
end;

9: if(b2 = 9)then
begin
JADX1:=334;
JADY1:=226;
JADX2:=501;
JADY2:=339;
end;


end;

if(not(b2=0))then
begin
if(FindColorTolerance(x,y, Color, JADX1, JADY1, JADX2, JADY2, Tol))then
begin
MMouse(x,y,2,2);
if(IsUpText(Text))then
begin
Result:=True;
if(Click=true)then
begin
Mouse(x,y,2,2,true);
end;
Exit;
end;
end;
end;

case b3 of

1: if(b3 = 1)then
begin
JADX1:=0;
JADY1:=0;
JADX2:=167;
JADY2:=113;
end;

2: if(b3 = 2)then
begin
JADX1:=167;
JADY1:=0;
JADX2:=334;
JADY2:=113;
end;

3: if(b3 = 3)then
begin
JADX1:=334;
JADY1:=0;
JADX2:=501;
JADY2:=113;
end;

4: if(b3 = 4)then
begin
JADX1:=0;
JADY1:=113;
JADX2:=167;
JADY2:=226;
end;

5: if(b3 = 5)then
begin
JADX1:=167;
JADY1:=113;
JADX2:=334;
JADY2:=226;
end;

6: if(b3 = 6)then
begin
JADX1:=334;
JADY1:=113;
JADX2:=501;
JADY2:=226;
end;

7: if(b3 = 7)then
begin
JADX1:=0;
JADY1:=226;
JADX2:=167;
JADY2:=339;
end;

8: if(b3 = 8)then
begin
JADX1:=167;
JADY1:=226;
JADX2:=334;
JADY2:=339;
end;

9: if(b3 = 9)then
begin
JADX1:=334;
JADY1:=226;
JADX2:=501;
JADY2:=339;
end;


end;

if(not(b3=0))then
begin
if(FindColorTolerance(x,y, Color, JADX1, JADY1, JADX2, JADY2, Tol))then
begin
MMouse(x,y,2,2);
if(IsUpText(Text))then
begin
Result:=True;
if(Click=true)then
begin
Mouse(x,y,2,2,true);
end;
Exit;
end;
end;
end;

case b4 of

1: if(b4 = 1)then
begin
JADX1:=0;
JADY1:=0;
JADX2:=167;
JADY2:=113;
end;

2: if(b4 = 2)then
begin
JADX1:=167;
JADY1:=0;
JADX2:=334;
JADY2:=113;
end;

3: if(b4 = 3)then
begin
JADX1:=334;
JADY1:=0;
JADX2:=501;
JADY2:=113;
end;

4: if(b4 = 4)then
begin
JADX1:=0;
JADY1:=113;
JADX2:=167;
JADY2:=226;
end;

5: if(b4 = 5)then
begin
JADX1:=167;
JADY1:=113;
JADX2:=334;
JADY2:=226;
end;

6: if(b4 = 6)then
begin
JADX1:=334;
JADY1:=113;
JADX2:=501;
JADY2:=226;
end;

7: if(b4 = 7)then
begin
JADX1:=0;
JADY1:=226;
JADX2:=167;
JADY2:=339;
end;

8: if(b4 = 8)then
begin
JADX1:=167;
JADY1:=226;
JADX2:=334;
JADY2:=339;
end;

9: if(b4 = 9)then
begin
JADX1:=334;
JADY1:=226;
JADX2:=501;
JADY2:=339;
end;


end;

if(not(b4=0))then
begin
if(FindColorTolerance(x,y, Color, JADX1, JADY1, JADX2, JADY2, Tol))then
begin
MMouse(x,y,2,2);
if(IsUpText(Text))then
begin
Result:=True;
if(Click=true)then
begin
Mouse(x,y,2,2,true);
end;
Exit;
end;
end;
end;

case b5 of

1: if(b5 = 1)then
begin
JADX1:=0;
JADY1:=0;
JADX2:=167;
JADY2:=113;
end;

2: if(b5 = 2)then
begin
JADX1:=167;
JADY1:=0;
JADX2:=334;
JADY2:=113;
end;

3: if(b5 = 3)then
begin
JADX1:=334;
JADY1:=0;
JADX2:=501;
JADY2:=113;
end;

4: if(b5 = 4)then
begin
JADX1:=0;
JADY1:=113;
JADX2:=167;
JADY2:=226;
end;

5: if(b5 = 5)then
begin
JADX1:=167;
JADY1:=113;
JADX2:=334;
JADY2:=226;
end;

6: if(b5 = 6)then
begin
JADX1:=334;
JADY1:=113;
JADX2:=501;
JADY2:=226;
end;

7: if(b5 = 7)then
begin
JADX1:=0;
JADY1:=226;
JADX2:=167;
JADY2:=339;
end;

8: if(b5 = 8)then
begin
JADX1:=167;
JADY1:=226;
JADX2:=334;
JADY2:=339;
end;

9: if(b5 = 9)then
begin
JADX1:=334;
JADY1:=226;
JADX2:=501;
JADY2:=339;
end;


end;

if(not(b5=0))then
begin
if(FindColorTolerance(x,y, Color, JADX1, JADY1, JADX2, JADY2, Tol))then
begin
MMouse(x,y,2,2);
if(IsUpText(Text))then
begin
Result:=True;
if(Click=true)then
begin
Mouse(x,y,2,2,true);
end;
Exit;
end;
end;
end;

case b6 of

1: if(b6 = 1)then
begin
JADX1:=0;
JADY1:=0;
JADX2:=167;
JADY2:=113;
end;

2: if(b6 = 2)then
begin
JADX1:=167;
JADY1:=0;
JADX2:=334;
JADY2:=113;
end;

3: if(b6 = 3)then
begin
JADX1:=334;
JADY1:=0;
JADX2:=501;
JADY2:=113;
end;

4: if(b6 = 4)then
begin
JADX1:=0;
JADY1:=113;
JADX2:=167;
JADY2:=226;
end;

5: if(b6 = 5)then
begin
JADX1:=167;
JADY1:=113;
JADX2:=334;
JADY2:=226;
end;

6: if(b6 = 6)then
begin
JADX1:=334;
JADY1:=113;
JADX2:=501;
JADY2:=226;
end;

7: if(b6 = 7)then
begin
JADX1:=0;
JADY1:=226;
JADX2:=167;
JADY2:=339;
end;

8: if(b6 = 8)then
begin
JADX1:=167;
JADY1:=226;
JADX2:=334;
JADY2:=339;
end;

9: if(b6 = 9)then
begin
JADX1:=334;
JADY1:=226;
JADX2:=501;
JADY2:=339;
end;


end;

if(not(b6=0))then
begin
if(FindColorTolerance(x,y, Color, JADX1, JADY1, JADX2, JADY2, Tol))then
begin
MMouse(x,y,2,2);
if(IsUpText(Text))then
begin
Result:=True;
if(Click=true)then
begin
Mouse(x,y,2,2,true);
end;
Exit;
end;
end;
end;

case b7 of

1: if(b7 = 1)then
begin
JADX1:=0;
JADY1:=0;
JADX2:=167;
JADY2:=113;
end;

2: if(b7 = 2)then
begin
JADX1:=167;
JADY1:=0;
JADX2:=334;
JADY2:=113;
end;

3: if(b7 = 3)then
begin
JADX1:=334;
JADY1:=0;
JADX2:=501;
JADY2:=113;
end;

4: if(b7 = 4)then
begin
JADX1:=0;
JADY1:=113;
JADX2:=167;
JADY2:=226;
end;

5: if(b7 = 5)then
begin
JADX1:=167;
JADY1:=113;
JADX2:=334;
JADY2:=226;
end;

6: if(b7 = 6)then
begin
JADX1:=334;
JADY1:=113;
JADX2:=501;
JADY2:=226;
end;

7: if(b7 = 7)then
begin
JADX1:=0;
JADY1:=226;
JADX2:=167;
JADY2:=339;
end;

8: if(b7 = 8)then
begin
JADX1:=167;
JADY1:=226;
JADX2:=334;
JADY2:=339;
end;

9: if(b7 = 9)then
begin
JADX1:=334;
JADY1:=226;
JADX2:=501;
JADY2:=339;
end;


end;

if(not(b7=0))then
begin
if(FindColorTolerance(x,y, Color, JADX1, JADY1, JADX2, JADY2, Tol))then
begin
MMouse(x,y,2,2);
if(IsUpText(Text))then
begin
Result:=True;
if(Click=true)then
begin
Mouse(x,y,2,2,true);
end;
Exit;
end;
end;
end;

case b8 of

1: if(b8 = 1)then
begin
JADX1:=0;
JADY1:=0;
JADX2:=167;
JADY2:=113;
end;

2: if(b8 = 2)then
begin
JADX1:=167;
JADY1:=0;
JADX2:=334;
JADY2:=113;
end;

3: if(b8 = 3)then
begin
JADX1:=334;
JADY1:=0;
JADX2:=501;
JADY2:=113;
end;

4: if(b8 = 4)then
begin
JADX1:=0;
JADY1:=113;
JADX2:=167;
JADY2:=226;
end;

5: if(b8 = 5)then
begin
JADX1:=167;
JADY1:=113;
JADX2:=334;
JADY2:=226;
end;

6: if(b8 = 6)then
begin
JADX1:=334;
JADY1:=113;
JADX2:=501;
JADY2:=226;
end;

7: if(b8 = 7)then
begin
JADX1:=0;
JADY1:=226;
JADX2:=167;
JADY2:=339;
end;

8: if(b8 = 8)then
begin
JADX1:=167;
JADY1:=226;
JADX2:=334;
JADY2:=339;
end;

9: if(b8 = 9)then
begin
JADX1:=334;
JADY1:=226;
JADX2:=501;
JADY2:=339;
end;


end;

if(not(b8=0))then
begin
if(FindColorTolerance(x,y, Color, JADX1, JADY1, JADX2, JADY2, Tol))then
begin
MMouse(x,y,2,2);
if(IsUpText(Text))then
begin
Result:=True;
if(Click=true)then
begin
Mouse(x,y,2,2,true);
end;
Exit;
end;
end;
end;

case b9 of

1: if(b9 = 1)then
begin
JADX1:=0;
JADY1:=0;
JADX2:=167;
JADY2:=113;
end;

2: if(b9 = 2)then
begin
JADX1:=167;
JADY1:=0;
JADX2:=334;
JADY2:=113;
end;

3: if(b9 = 3)then
begin
JADX1:=334;
JADY1:=0;
JADX2:=501;
JADY2:=113;
end;

4: if(b9 = 4)then
begin
JADX1:=0;
JADY1:=113;
JADX2:=167;
JADY2:=226;
end;

5: if(b9 = 5)then
begin
JADX1:=167;
JADY1:=113;
JADX2:=334;
JADY2:=226;
end;

6: if(b9 = 6)then
begin
JADX1:=334;
JADY1:=113;
JADX2:=501;
JADY2:=226;
end;

7: if(b9 = 7)then
begin
JADX1:=0;
JADY1:=226;
JADX2:=167;
JADY2:=339;
end;

8: if(b9 = 8)then
begin
JADX1:=167;
JADY1:=226;
JADX2:=334;
JADY2:=339;
end;

9: if(b9 = 9)then
begin
JADX1:=334;
JADY1:=226;
JADX2:=501;
JADY2:=339;
end;
end;

if(not(b9=0))then
begin
if(FindColorTolerance(x,y, Color, JADX1, JADY1, JADX2, JADY2, Tol))then
begin
MMouse(x,y,2,2);
if(IsUpText(Text))then
begin
Result:=True;
if(Click=true)then
begin
Mouse(x,y,2,2,true);
end;
Exit;
end;
end;
end;
if(not(Result))then
Writeln('Did not find color in any of specified boxes :(');
end;


begin
end.

tarajunky

2007-04-13 21:35:30

Not bad. I used a similar strategy to find ducks in LAME.


repeat;
FindFastRandoms;
n:=n+1;
case n of
1: begin
x1:=MSCX-5;y1:=MSY1;x2:=MSCX+5;y2:=MSY1+10;
end;
2: begin
x1:=MSX2-10;y1:=MSCY-5;x2:=MSX2;y2:=MSCY+5;
end;
3: begin
x1:=MSCX-5;y1:=MSY2-10;x2:=MSCX+5;y2:=MSY2;
end;
4: begin
x1:=MSX1;y1:=MSCY-5;x2:=MSX1+10;y2:=MSCY+5;
end;
5: begin
x1:=MSX1;y1:=MSY1;x2:=MSX1+10;y2:=MSY1+10;
end;
6: begin
x1:=MSX2-10;y1:=MSY1;x2:=MSX2;y2:=MSY1+10;
end;
7: begin
x1:=MSX2-10;y1:=MSY2-10;x2:=MSX2;y2:=MSY2;
end;
8: begin
x1:=MSX1;y1:=MSY2-10;x2:=MSX1+10;y2:=MSY2;
end;
9: begin
x1:=MSCX-5;y1:=MSCY-5;x2:=MSCX+5;y2:=MSCY+5;
end;
end;
if not(LoggedIn) then break;
FFlag(0);
dx:=(x2-((x2-x1)div(2)));
dy:=(y2-((y2-y1)div(2)));
if FindColorSpiralTolerance(dx,dy,WakeColor,MSX1,MSY1,MSX2,MSY,10) then

etc.

I guess the difference is that in mine I simply move the starting point of the search around and let it find the closest color while searching the entire screen. Yours restricts the search area. Good work.

JAD

2007-04-13 21:43:15

TYVM! Was hoping to get some positive feed back :) When I used a few auto fighters I got that problem with the chickens though, because theres so many colors that look almost exactly the same to the chickens at falador now you know?

SKy Scripter

2007-04-13 21:58:54

i would rather just use FindObj :)
but good job any way!!! ;)

Boreas

2007-04-13 22:44:10

program New;
{.include srl/srl.scar}

var i,x1,y1,x2,y2:integer;
begin
for i:= 1 to 9 do
begin
x1:=msx1+( ( ( (i+2) mod 3) +1-1)* (round(msx2/3)));
y1:=msy1+( ( ( (i-1) /3)+ 1-1)*round(msy2/3));
x2:=x1+round(msx2/3);
y2:=y1+round(msy2/3);
writeln(inttostr(i)+' '+inttostr(x1)+' '+inttostr(y1)+' '+inttostr(x2)+' '+inttostr(y2));
clickmouse(x1,y1,true); clickmouse(x2,y1,true);
clickmouse(x1,y2,true); clickmouse(x2,y2,true);
//holdmouse(x1,y1,true);
//movemouse(x2,y2);
//releasemouse(x2,y2,true);
end;
end.
run on screen shot of rs

Bobarkinator

2007-04-13 23:21:32

Would you mind releasing similar one for minimap because I have been having this exact same trouble in my Eye of Newt Buyer. If it doesn't find Betty it will move the mouse to one of the white dots on the minimap but it will just keep going to the same point.

tarajunky

2007-04-13 23:37:52

From: SKy Scripter
i would rather just use FindObj :)
but good job any way!!! ;)


The problem with FindObj is that you look for ONE color, then move the mouse.

What if you want to look for 3 colors, or 4 colors first to make sure you're finding the right object?

As was mentioned before, you have brown chickens and brown dirt and brown walls and brown doors. If you just FindObj for brown, your mouse will go crazy trying to find the chicken. I personally HATE that, and I think it's very detectable.

If you do this type of search, you can then branch off and do subsequent searches for other colors that should be on that object BEFORE ever moving the mouse.

Watch LAME attack ducks. It searches for the wake color, then the head color, then the body color, then the bill color on the ducks. If it doesn't find all those colors together, it skips it and checks the next matching color. End result? ONE mouse movement, directly to the duck. No crazy mouse flying around the screen. By the time the mouse is moved, the script already KNOWS it's a duck.

Findobj is a nice function, but it's very noobish if you ask me. :stirthepot:

JAD

2007-04-14 00:47:19

From: bobarkinator
Would you mind releasing similar one for minimap because I have been having this exact same trouble in my Eye of Newt Buyer. If it doesn't find Betty it will move the mouse to one of the white dots on the minimap but it will just keep going to the same point.


Ooh, good Idea bob! I'll make a whole one for the mini map :) I'll release it once its done.

Boreas

2007-04-14 05:37:27

    x1:=msx1+( (         ( (i+3-1) mod 3) +1-1)* (round(msx2/3)));
y1:=msy1+( ( ( (i-1) /3)+ 1-1)*round(msy2/3));
x2:=x1+round(msx2/3);
y2:=y1+round(msy2/3);

Replace ms with mm and 3 with the number of columns/rows :)

n3ss3s

2007-04-17 12:49:48

Wow , that last piece of code boreas sent made he look like a pro :D
Can u tell where you get guides for those "mod" and those "div" like things?

Boreas

2007-04-17 16:52:57

Well I first learned them for excel.

program New;

begin
writeln(inttostr(8 mod 3));
writeln(inttostr(9 mod 3));
writeln(inttostr(10 mod 3));
writeln(inttostr(11 mod 3));
writeln(inttostr(12 mod 3));
writeln(' ');
writeln(inttostr(8 div 3));
writeln(inttostr(9 div 3));
writeln(inttostr(10 div 3));
writeln(inttostr(11 div 3));
writeln(inttostr(12 div 3));
end.

Run that.

10 div 3 is 10/3 rounded down, how many whole 3's can fit into 10, which is 3.

10 mod 3 is is like 10-((10 div 3)*3). It's what's left over when you divide. Another example is divisibility; in A mod B, if A is divisible by B, there will be no remainder, so the answer will be 0. So if (num mod 2)=0 then NumIsEven

row:=((i-1)/8)+1;
column:=((i+8-1)mod 8)+1;
That's how I get row and column numbers for BankSlots, the 8 is the number of columns, and the i is the slot number.

omgh4x0rz

2007-04-17 16:56:33

Mod is just a mathematical operation in pascal. In the C classes and Java it is %, and returns the remainder of whatever is being divided. Div just means divide i think?

Edit: oops, didn't see that boreas had already posted. Read what he said, not mine.

n3ss3s

2007-04-22 13:25:40

well isnt the div same as for example 10/3? If the type isnt Extended, is integer then doesnt it return just 3? In java it does..

Boreas

2007-04-22 13:49:21

Correct.

program New;
{.include SRL/SRL.scar}
var iter,ax,bx:integer;
begin
SetupSRL;
repeat
iter:=iter+1;
Status(inttostr(iter));
x:=random(100)+1;
y:=random(100)+1;
ax:=(x/y);
bx:=(x div y);
if not(ax=bx) then
writeln(inttostr(x)+' '+inttostr(y));
until isfkeydown(12);
end.

JAD

2007-04-28 18:51:51

Huge update.. Should be a lot more useful now that I made the boxes for the main screen instead of the whole runescape screen. Enjoy! :D