PDA

View Full Version : Finding objects



nielsie95
05-07-2007, 11:49 AM
Hello, and welcome to the tutorial about:


Finding objects


Chapters:


SRL-functions
Deformed Bitmaps
Doors



SRL-functions

The easiest way to find your object is to use the functions that are implented in SRL. All SRL functions use colors and uptext. I made a list for you:

FindObj --> The most simple way. Enter uptext, color and tolerance.

FindObj(var cx, cy: Integer; Text: String; color, tolerance: Integer): Boolean;

if FindObj(x, y, 'Tree', 123, 10) then Mouse(x, y, 0, 0, True);


FindObjMulti --> The same as FindObj, but supports more colors. Enter uptext, color1, color2, color3, tolerance. NOTE: This doesn't return the position of the object. If you want the place use GetMouse(x, y) after the function!


FindObjMulti(Text: String; color1, color2, color3, tolerance: Integer): Boolean;

if FindObjMulti('Tree', 123, 456, 789, 10) then
begin
GetMousePos(x, y); //Don't forget this!!!
Mouse(x, y, 0, 0, True);
end;


FindObjMultiText --> The same as FindObj, but now it supports more uptext. Enter uptext1, uptext2, uptext3, color, tolerance.


FindObjMultiText(var cx, cy: Integer; Ut1, UT2, UT3: String; color, tolerance: Integer): Boolean;

if FindObjMultiText(x, y, 'Tree', 'ree', 'Chop down Tree', 123, 10) then Mouse(x, y, 0, 0, True);


FindObjEx --> Uses a special way to find objects. If it sorts out all the found colors by distance (MinXDist and MinYDist). Usefull if the color is found a lot on the mainscreen. Example of how it works:



*** ** * * * ** * * * *
** * * ******** ****
*** **** *** *
Imagine that the * above are the colors you are looking for. If you set MinXDist to 5, there has to be at least 5 pixels (spaces) between the colors that will be checked. So it will check only:



* * * * * * *
* * * * *
* * * *
As you can see there are a lot of colors filtered out. But you can specify it even more: you can do the same thing with MinYDist. If we set MinYDist at 2, there has to be at least 2 pixels (spaces) between each color:



* * * * * * *
* * *
* *

This way you can check the screen very quickly if there are a lot of the same colors on the mainscreen.


FindObjEx(var x, y: Integer; ObjText: String; x1, y1, x2, y2, Color, Tol, MinXDist, MinYDist, WaitPerCheck: Integer; Spiral: Boolean): Boolean;

//WaitPerCheck is the time in milliseconds it will wait between each move.
//With spiral you can let it find colors from center out. If you set it false, it will start at the upperleft corner.

if FindObjEx(x, y, 'Tree', MSX1, MSY1, MSX2, MSY2, 123, 10, 5, 2, 50, True) then Mouse(x, y, 0, 0, True);



FindObj3 --> Uses FindObjEx with some preset values. Now you only need to set the text, color and tolerance.


function FindObj3(var cx, cy: Integer; Text: string; color, tol: Integer):
Boolean;

if FindObj3(x, y, 'Tree', 123, 10) then Mouse(x, y, 0, 0, True);



FindObjectMulti --> Works just like FindObj, but now you can set 3 colors and 3 uptexts, the number of turns it should check and if you would like it to check multitext and multitimes.


FindObjectMulti(var cx, cy: Integer; Text1, Text2, Text3: String; color1, color2, color3, tolerance, Turns: Integer; MultiText, MultiTimes: Boolean): Boolean;

if FindObjectMulti(x, y, 'Tree', 'ree', 'Chop down Tree', 123, 456, 789, 10, 5, True, True) then Mouse(x, y, 0, 0, True);


FindObjOre --> To use this FindObj you need to include the mining skill in your script. This is basicly a FindObj made to find ores. MinCount is the minimal number of similar colors found in the near area (4 - normal ores, 1 - rimmington ores).


function FindObjOre(var cx, cy: Integer; Text: string; color, tolerance,
MinCount: Integer): Boolean;

if FindObjOre(x, y, 'Rock', OreColor, 15, 4) then Mouse(x, y, 0, 0, True);



Deformed Bitmaps

If you're not very good with bitmaps read this (http://www.villavu.com/forum/showthread.php?t=8306)and this (http://www.villavu.com/forum/showthread.php?t=9453)first!!
Another way to find objects is using deformed bitmaps. This way is a bit slower but finds the object most of the time in one try. The bitmap you need for deformed bitmap finding is the same as you need for a normal FindBitmap.
It's the best if you make a sliced bitmap. These are bitmaps from 1 or 2 pixels high (1*8, 2*16, 8*2, 16*1).


//Example bmp, from Charmz:
WillowTree := BitmapFromString(2, 6, '18180E303016304016283' +
'01648502C30382160682C3040135850444848324850244850 39');

function FindObjectDeformed(var ObjX, ObjY :integer; UpText1, UpText2: String; BMP, a, b, c, d: integer): Boolean;
//This is in SRL.

if FindObjectDeformed(x, y, 'Tree', 'ree', 'Chop down Tree', WillowTree, MSX1, MSY1, MSX2, MSY2) then Mouse(x, y, 0, 0, True);





Doors

One of the harder objects to find are doors. You can do a few things to find them:
You can create a few bitmap slices from different angles, and try to find them deformed (last chapter), you can try it using a regular FindObj, or you can try my own DoorFind procedure (FindObjDoor):


function getArrayFromBox(arColor: TPointArray; Width, Height: Integer): TPointArray; //Lorax
var
Count, Count3, arLength: Integer;
DoNotAccept : Boolean;
begin
SetArrayLength(Result, 1);
Result[0] := arColor[0];
arLength := GetArrayLength(arColor);
if ( arLength = 1 ) then
Exit;

for Count := 1 to arLength - 1 do
begin
if(arColor[Count].x < arColor[Count - 1].x + Width)and
(arColor[Count].y < arColor[Count - 1].y + Height)and
(arColor[Count].x > arColor[Count - 1].x - Width)and
(arColor[Count].y > arColor[Count - 1].y - Height)then
else
begin
DoNotAccept := False;
for Count3 := 0 to GetArrayLength(Result) - 1 do
begin
if (arColor[Count].x < Result[Count3].x + Width)and
(arColor[Count].y < Result[Count3].y + Height)and
(arColor[Count].x > Result[Count3].x - Width)and
(arColor[Count].y > Result[Count3].y - Height)then
DoNotAccept := True;
if DoNotAccept then
Break;
end;
if (DoNotAccept = False) then
begin
SetArrayLength(Result, GetArrayLength(Result) + 1);
Result[GetArrayLength(Result) - 1] := arColor[Count];
end;
end;
end;
end;

function IsMultiUpTextColor(Color, Tol: Integer; Range: Byte; Text1, Text2, Text3: String): Boolean;
var
TempText: String;
begin
TempText := GetUpTextColor(Color, Tol, Range);
if Pos(Text1, TempText) <> 0 then Result := True else
if Pos(Text2, TempText) <> 0 then Result := True else
if Pos(Text3, TempText) <> 0 then Result := True;
end;

function FindObjDoor(var cx, cy: Integer; DoorType, x1, y1, x2, y2: Integer): Boolean;
var
tx, ty, i, c, Color, Count, H, bmp: integer;
Points, Ar1: TPointArray;
X, Y, Z: Extended;
begin
ColorToleranceSpeed(2); // 2640749 1989237 5730945 3956587
SetColorSpeed2Modifiers(0.1, 0.4); // You might want to take this out.
bmp := BitmapFromString(MSX2 + 20, MSY2 + 20, ' ');
CopyClientToBitmap(bmp, 0, 0, MSX2 +20, MSY2 +20);
H := GetClientWindowHandle;
SetTargetBitmap(bmp);

case DoorType of
1 : FindColorsSpiralTolerance(cx, cy, Points, 1989237, x1, y1, x2, y2, 10);
2 : FindColorsSpiralTolerance(cx, cy, Points, 2640749, x1, y1, x2, y2, 10);
3 : FindColorsSpiralTolerance(cx, cy, Points, 3956587, x1, y1, x2, y2, 10);
4 : FindColorsSpiralTolerance(cx, cy, Points, 6126219, x1, y1, x2, y2, 10);
5 : begin
FindColorsSpiralTolerance(cx, cy, Points, 1989237, x1, y1, x2, y2, 10);
FindColorsSpiralTolerance(cx, cy, Ar1, 2640749, x1, y1, x2, y2, 10);
Points := AddTPA(Points, Ar1);
FindColorsSpiralTolerance(cx, cy, Ar1, 3956587, x1, y1, x2, y2, 10);
Points := AddTPA(Points, Ar1);
FindColorsSpiralTolerance(cx, cy, Ar1, 5730945, x1, y1, x2, y2, 10);
Points := AddTPA(Points, Ar1);
end;
else begin WriteLn('Unknown DoorType'); Exit; end;
end;

if Length(Points) < 1 then Exit;

for i := 0 to GetArrayLength(Points) -1 do
begin
Color := FastGetPixel(bmp, Points[i].x, Points[i].y);
try
Count := CountColor(Color, Points[i].x -20, Points[i].y -20, Points[i].x +20, Points[i].y +20);
finally
if Count < 35 then
if Count > 10 then
begin
SetArrayLength(Ar1, GetArrayLength(Ar1) +1);
Ar1[GetArrayLength(Ar1) -1] := Points[i];
end;
except Break; end;
end;

if Length(Ar1) < 1 then Exit;

SetArrayLength(Points, 0);
for i := 1 to GetArrayLength(Ar1) -1 do
begin
Color := FastGetPixel(bmp, Ar1[i].x, Ar1[i].y);
ColorToXYZ(Color, X, Y, Z);
if ((DoorType = 1) or (DoorType = 5)) and SimilarColors(Color, 1989237, 10) then
begin
if (Y > 2.0) and (X > 11.5) then
begin
SetArrayLength(Points, Length(Points) +1);
Points[ Length(Points) -1] := Ar1[i];
end;
end else
if ((DoorType = 2) or (DoorType = 5)) and SimilarColors(Color, 2640749, 10) then
begin
if (Y > 2.7) and (X > 9.0) then
begin
SetArrayLength(Points, Length(Points) +1);
Points[ Length(Points) -1] := Ar1[i];
end;
end else
if (DoorType = 3) or (DoorType = 5) and SimilarColors(Color, 3956587, 10) then
begin
if (Y > 4.0) and (X > 10.0) then
begin
SetArrayLength(Points, Length(Points) +1);
Points[ Length(Points) -1] := Ar1[i];
end;
end else
if (DoorType >= 4) and SimilarColors(Color, 6126219, 10) then
begin
if (Y > 8.0) and (X > 16.0) then
begin
SetArrayLength(Points, Length(Points) +1);
Points[ Length(Points) -1] := Ar1[i];
end;
end
end;

Ar1 := Points;
if Length(Ar1) < 1 then Exit;
ColorToleranceSpeed(1);
Points := getArrayFromBox(Ar1, 35, 35);

for i := 0 to Length(Points) -1 do
begin
FindColorsTolerance(Ar1, FastGetPixel(bmp, Points[i].x, Points[i].y), Points[i].x -35, Points[i].y -35, Points[i].x +35, Points[i].y +35, 10);
if Length(Ar1) <> 0 then
begin
for c := 0 to Length(Ar1) -1 do
begin
tx := tx + Ar1[c].x;
ty := ty + Ar1[c].y;
end;
tx := tx / Length(Ar1);
ty := ty / Length(Ar1);
end else
begin
tx := Points[i].x;
ty := Points[i].y;
end;
MMouse(tx, ty, 2, 2);
Wait(120 + Random(150));
if IsMultiUpTextColor(13159171, 60, tr_Letters, 'oor', 'or', 'Do') then
begin
Result := True;
cx := tx;
cy := ty;
FreeBitmap(bmp);
SetClientWindowHandle(H);
Exit;
end;
tx := 0;
ty := 0;
end;
FreeBitmap(bmp);
SetClientWindowHandle(H);
end;

cx, and cy are the variables where the place of the door will be stored. DoorType is the type of the door: 1 - Normal doors, 2 - Lumbridge doors, 3 - Varrock doors, 4 - Falador, 5 - All kinds. And x1, y1, x2, y2 are the places where the procedure has to look.


I hoped this tutorial has helped you on your way to find the objects you need.
Thanks for reading,
Nielsie95

me_ntal
05-07-2007, 12:39 PM
Thanks for making this, I actually took your advice and used deformeds in my cow killer works so well.

Nice tut you explained everything very well.

Smartzkid
05-07-2007, 09:05 PM
:D Awesome!

PS: Congrats on DEV!!

nielsie95
05-07-2007, 09:14 PM
Thank you :)
Any suggestions about what I could add to it?

Fourscape
05-07-2007, 11:15 PM
Why it works the way it does. You could do something like this...

Begin
If FindMSColorTol(X, Y,113332, 4) then
Begin
MMouse(X, Y, 0, 0)
If IsUpText('Chop down') then
Begin
Result := True;
Mouse(X, Y, 0, 0, True)
end;
end;
end;

But FindObj works better, maybe explain why.

Harry
05-11-2007, 08:50 PM
Thank you... im a scripting noobie, i really want srl member title =)

RudeBoiAlex
05-17-2007, 03:38 PM
can u just put



if FindObj(x, y, 'Tree', 123, 10) then Mouse(x, y, 0, 0, True);

ir does it have to be

FindObj(var cx, cy: Integer; Text: String; color, tolerance: Integer): Boolean;

if FindObj(x, y, 'Tree', 123, 10) then Mouse(x, y, 0, 0, True);

EDIT: wppt 700th post

nielsie95
06-24-2007, 02:14 PM
RudeboiAlex: It has to be the first.. But I guess you know that now, sorry for the late response. :(


Updated

I added a Chapter for Doors and added my own DoorFinding function!

BobboHobbo
06-25-2007, 08:05 AM
Nice guide, It will help da noobies alot :D

rkroxpunk
07-18-2007, 12:31 PM
hey why not add using an array of colours? then do that loop thingy with i

cathering_
07-26-2007, 06:08 PM
Love the tutorial well explained :)

dvdcrayola
08-17-2007, 05:35 PM
nice tut, helped me a lot

lordsaturn
08-17-2007, 06:02 PM
Thanks for the info on deformed...I used that in my script. =]

nielsie95
08-17-2007, 06:08 PM
Great it helped! :)