SRL Archive - SRL Archives

Amazing Tree finder


Cazax

2009-01-14 16:10:47

I made an any tree finder, I have only tested it with willows, oaks, trees and yews. I read lorax's tut about in HSL and decided to experiment with HSL, and got this:
Function FindTree(Var X, Y : Integer): Boolean;
Var
TPA, TPA2 : TPointArray;
ATPA : T2DPointArray;
I, J, lastCol, Took : Integer;
L : TExtendedArray;
LTol, H, S, tempH, tempS, tempL : Extended;
Begin
LTol := 10.0;
Took := GetTickCount;
FindColorsSpiralTolerance(MSCX, MSCY, TPA, 5869445, MSX1, MSY1, MSX2, MSY2, 15);
If Length(TPA) = 0 Then
Exit;
SetLength(L, Length(TPA));
For I := 0 To High(TPA) Do
ColorToHSL(GetColor(TPA[I].X, TPA[I].Y), H, S, L[I]);
lastCol := GetColor(TPA[Low(TPA)].X, TPA[Low(TPA)].Y);
For J := 0 To High(TPA) Do
Begin
ColorToHSL(lastCol, tempH, tempS, tempL);
If (iAbs(Round(LTol) - Round(Abs(tempL - L[J]))) < 10) And ((Round(tempH) > 15) And (Round(tempH) < 25)) Then
Begin
LTol := tempL - L[J];
SetLength(TPA2, Length(TPA2) + 1);
TPA2[High(TPA2)] := TPA[J];
End;
lastCol := GetColor(TPA[J].X, TPA[J].Y);
End;
Result := Length(TPA2) <> 0;
If Result Then
Begin
Writeln('Found Tree in: ' + IntToStr(GetTickCount - Took) + 'ms');
ATPA := TPAtoATPAex(TPA2, 25, 25);
For I := 0 To High(ATPA) Do
Begin
MiddleTPAex(ATPA[I], X, Y);
MMouse(X, Y, 5, 5);
Wait(100 + Random(100));
If IsUpText('hop') Then
Begin
Result := True;
GetMousePos(X, Y);
Writeln('Luminance Tolerance = ' + FloatToStr(Abs(LTol)));
Exit;
End;
End;
End;
Result := False;
End;
You can change the isuptext('hop') to the uptext of your tree. It takes between 30 - 100 ms to find the tree, depends on how many trees are on the screen. It has never missed a tree ;)

NCDS

2009-01-14 16:47:14

Looks great!
You should have added your own credits at the top!

Nice Job with this, Im sure we will all see it in plenty of scripts to come :rolleyes:

bullzeye95

2009-01-14 17:14:50

Finding a tree is the easy part. Figuring out what kind of tree it is without moving the mouse to it is the hard part.

Cazax

2009-01-14 17:53:04

From: bullzeye95
Finding a tree is the easy part. Figuring out what kind of tree it is without moving the mouse to it is the hard part.

That is too hard, there is almost no difference between yews, trees and oaks. I have tried with different colors and things, but the only difference between them is the size. The only findable tree(F2P) is the willow(in colors). The good about this function that doesn't hover any other object than trees.

bullzeye95

2009-01-14 18:44:21

I managed to do it pretty well once, but the biggest problem is when two trees overlap each other. Then it gets hard.

Smarter Child

2009-01-14 20:05:06

Can i use this in my script?

I'll credit..:p

lordsaturn

2009-01-27 03:59:02

Here's what I got from my test..


:(