Negaal
01-19-2008, 09:06 PM
Here it is, big thanks to Nielsie for explaining wizzyplugin functions and Markus for testing:)
function FindTree(var x, y: Integer; Treetype : String): Boolean;
var
TPA : TpointArray;
ATPA : Array of TPointArray;
MSCPoint : Tpoint;
i, CTS, Color : integer;
Uptext : String;
begin
x := mscx;
y := mscy;
MSCPoint.x := mscy;
MSCPoint.y := mscy;
Color := 2966339;
Case lowercase(TreeType) of
'tree', 'usual' : Uptext := 'Tree';
'oak' : UpText := 'Oak';
'willow' : UpText := 'illo';
'yew' : UpText := 'Yew';
end;
CTS := GetColorToleRanceSpeed;
ColorToleranceSpeed(2);
SetColorspeed2Modifiers(0.2, 0.2);
FindColorsSpiralTolerance(x, y, TPA, Color, msx1, msy1, msx2, msy2, 10)
ColorToleranceSpeed(CTS);
if Length(TPA) > 4 then
begin
ATPA := SplitTPA(TPA, 15);
SortATPAFrom(ATPA, MSCPoint);
for i := 0 to High(ATPA) do
begin
MiddleTPAEx(ATPA[i], x, y);
MMouse(x, y, 3, 3);
Wait(100 + random(100));
if IsUpText(UpText) then
begin
Result := True;
Getmousepos(x, y);
Exit;
end;
end;
end;
end;
Edit:
This one should be lot better xD :D
function FindTree(var a, b: Integer; Treetype : String): Boolean;
var
TPA : TpointArray;
ATPA : Array of TPointArray;
i, C, CTS, Color : integer;
Uptext : String;
Colors : Array of integer;
SortedTPA : TPointArray;
x, y, z, h, s, l,
maxx, minx, maxy, miny, maxz, minz,
maxh, minh, maxs, mins, maxl, minl : extended;
begin
Color := 2446923;
Minx := 1;
Maxx := 22;
Miny := 0;
Maxy := 11;
Minz := 1;
Maxz := 28;
Minh := 17;
Maxh := 22;
Mins := 23;
Maxs := 62;
Minl := 7;
Maxl := 45;
Case lowercase(TreeType) of
'tree' : Uptext := 'ree';
'oak' : UpText := 'ak';
'willow' : UpText := 'llo';
'yew' : UpText := 'ew';
'all' : UpText := 'hop d';
end;
CTS := GetColorToleRanceSpeed;
ColorToleranceSpeed(2);
SetColorspeed2Modifiers(0.15, 0.5);
FindColorsSpiralTolerance(mscx, mscy, TPA, Color, msx1, msy1, msx2, msy2, 9)
ColorToleranceSpeed(CTS);
SetColorspeed2Modifiers(0.2, 0.2);
Colors := GetColors(TPA);
for C := 0 to High(TPA) do
begin
colortoxyz(colors[i], x, y, z);
if (x > minx) then
if (x < maxx) then
if (y > miny) then
if (y < maxy) then
if (z > minz) then
if (z < maxz) then
begin
colortohsl(colors[i], h, s, l);
if (h > minh) then
if (h < maxh) then
if (s > mins) then
if (s < maxs) then
if (l > minl) then
if (l < maxl) then
begin
Setlength(SortedTPA, length(SortedTPA) + 1);
SortedTPA[high(SortedTPA)] := TPA[C];
end;
end;
end;
if Length(SortedTPA) >= 50 then
begin
ATPA := SplitTPAEx(SortedTPA, 20, 15);
SortATPAFrom(ATPA, IntToPoint(MSCX, MSCY));
for i := 0 to High(ATPA) do
if Length(ATPA[i]) >= 50 then
begin
MiddleTPAEx(ATPA[i], a, b);
MMouse(a-10, b-10, 21, 21);
Wait(50 + random(50));
if IsUpText(UpText) then
begin
Result := True;
Getmousepos(a, b);
Exit;
end;
end;
end;
end;
Edit: I made min, max, etc to vars because I had lot of messing with them...Hard to understand...remove em and put in HSL and XYZ if you want...
Did like Wizzup? said and now takes only ~250 ms and hard to notice tiny lag
function FindTree(var a, b: Integer; Treetype : String): Boolean;
var
TPA : TpointArray;
ATPA : Array of TPointArray;
i, C, CTS, Count : integer;
Uptext : String;
Colors : Array of integer;
SortedTPA : TPointArray;
x, y, z, h, s, l : extended;
begin
Case lowercase(TreeType) of
'tree' : Uptext := 'ree';
'oak' : UpText := 'ak';
'willow' : UpText := 'llo';
'yew' : UpText := 'ew';
'all' : UpText := 'hop d';
end;
CTS := GetColorToleRanceSpeed;
ColorToleranceSpeed(2);
SetColorspeed2Modifiers(0.15, 0.5);
FindColorsSpiralTolerance(mscx, mscy, TPA, 2446923, msx1, msy1, msx2, msy2, 9);
ColorToleranceSpeed(CTS);
SetColorspeed2Modifiers(0.2, 0.2);
TPA:=ReArrangeandShortenArrayEx(TPA, 5, 5);
Colors := GetColors(TPA);
SetLength(SortedTPA, Length(TPA));
Count := 0;
for C := 0 to High(TPA) do
begin
colortoxyz(colors[i], x, y, z);
if(x > 1)and(x < 22)and(y > 0)and(y < 11)and(z > 1)and(z < 28)then
begin
colortohsl(colors[i], h, s, l);
if (h > 17)and(h < 22)and(s > 23)and(s < 62)and(l > 7)and(l < 45) then
begin
SortedTPA[Count] := TPA[C];
Count := Count + 1;
end;
end;
end;
SetLength(SortedTPA, Count);
SortedTPA := TPA;
begin
ATPA := SplitTPAEx(SortedTPA, 20, 15);
SortATPAFrom(ATPA, IntToPoint(MSCX, MSCY));
for i := 0 to High(ATPA) do
if Length(ATPA[i]) >= 50 then
begin
MiddleTPAEx(ATPA[i], a, b);
MMouse(a-10, b-10, 21, 21);
Wait(50 + random(50));
if IsUpText(UpText) then
begin
Result := True;
Getmousepos(a, b);
Exit;
end;
end;
end;
end;
Usage example
Findtree(x, y, 'yew');
You can choose between tree, oak, willow and yew and all.
function FindTree(var x, y: Integer; Treetype : String): Boolean;
var
TPA : TpointArray;
ATPA : Array of TPointArray;
MSCPoint : Tpoint;
i, CTS, Color : integer;
Uptext : String;
begin
x := mscx;
y := mscy;
MSCPoint.x := mscy;
MSCPoint.y := mscy;
Color := 2966339;
Case lowercase(TreeType) of
'tree', 'usual' : Uptext := 'Tree';
'oak' : UpText := 'Oak';
'willow' : UpText := 'illo';
'yew' : UpText := 'Yew';
end;
CTS := GetColorToleRanceSpeed;
ColorToleranceSpeed(2);
SetColorspeed2Modifiers(0.2, 0.2);
FindColorsSpiralTolerance(x, y, TPA, Color, msx1, msy1, msx2, msy2, 10)
ColorToleranceSpeed(CTS);
if Length(TPA) > 4 then
begin
ATPA := SplitTPA(TPA, 15);
SortATPAFrom(ATPA, MSCPoint);
for i := 0 to High(ATPA) do
begin
MiddleTPAEx(ATPA[i], x, y);
MMouse(x, y, 3, 3);
Wait(100 + random(100));
if IsUpText(UpText) then
begin
Result := True;
Getmousepos(x, y);
Exit;
end;
end;
end;
end;
Edit:
This one should be lot better xD :D
function FindTree(var a, b: Integer; Treetype : String): Boolean;
var
TPA : TpointArray;
ATPA : Array of TPointArray;
i, C, CTS, Color : integer;
Uptext : String;
Colors : Array of integer;
SortedTPA : TPointArray;
x, y, z, h, s, l,
maxx, minx, maxy, miny, maxz, minz,
maxh, minh, maxs, mins, maxl, minl : extended;
begin
Color := 2446923;
Minx := 1;
Maxx := 22;
Miny := 0;
Maxy := 11;
Minz := 1;
Maxz := 28;
Minh := 17;
Maxh := 22;
Mins := 23;
Maxs := 62;
Minl := 7;
Maxl := 45;
Case lowercase(TreeType) of
'tree' : Uptext := 'ree';
'oak' : UpText := 'ak';
'willow' : UpText := 'llo';
'yew' : UpText := 'ew';
'all' : UpText := 'hop d';
end;
CTS := GetColorToleRanceSpeed;
ColorToleranceSpeed(2);
SetColorspeed2Modifiers(0.15, 0.5);
FindColorsSpiralTolerance(mscx, mscy, TPA, Color, msx1, msy1, msx2, msy2, 9)
ColorToleranceSpeed(CTS);
SetColorspeed2Modifiers(0.2, 0.2);
Colors := GetColors(TPA);
for C := 0 to High(TPA) do
begin
colortoxyz(colors[i], x, y, z);
if (x > minx) then
if (x < maxx) then
if (y > miny) then
if (y < maxy) then
if (z > minz) then
if (z < maxz) then
begin
colortohsl(colors[i], h, s, l);
if (h > minh) then
if (h < maxh) then
if (s > mins) then
if (s < maxs) then
if (l > minl) then
if (l < maxl) then
begin
Setlength(SortedTPA, length(SortedTPA) + 1);
SortedTPA[high(SortedTPA)] := TPA[C];
end;
end;
end;
if Length(SortedTPA) >= 50 then
begin
ATPA := SplitTPAEx(SortedTPA, 20, 15);
SortATPAFrom(ATPA, IntToPoint(MSCX, MSCY));
for i := 0 to High(ATPA) do
if Length(ATPA[i]) >= 50 then
begin
MiddleTPAEx(ATPA[i], a, b);
MMouse(a-10, b-10, 21, 21);
Wait(50 + random(50));
if IsUpText(UpText) then
begin
Result := True;
Getmousepos(a, b);
Exit;
end;
end;
end;
end;
Edit: I made min, max, etc to vars because I had lot of messing with them...Hard to understand...remove em and put in HSL and XYZ if you want...
Did like Wizzup? said and now takes only ~250 ms and hard to notice tiny lag
function FindTree(var a, b: Integer; Treetype : String): Boolean;
var
TPA : TpointArray;
ATPA : Array of TPointArray;
i, C, CTS, Count : integer;
Uptext : String;
Colors : Array of integer;
SortedTPA : TPointArray;
x, y, z, h, s, l : extended;
begin
Case lowercase(TreeType) of
'tree' : Uptext := 'ree';
'oak' : UpText := 'ak';
'willow' : UpText := 'llo';
'yew' : UpText := 'ew';
'all' : UpText := 'hop d';
end;
CTS := GetColorToleRanceSpeed;
ColorToleranceSpeed(2);
SetColorspeed2Modifiers(0.15, 0.5);
FindColorsSpiralTolerance(mscx, mscy, TPA, 2446923, msx1, msy1, msx2, msy2, 9);
ColorToleranceSpeed(CTS);
SetColorspeed2Modifiers(0.2, 0.2);
TPA:=ReArrangeandShortenArrayEx(TPA, 5, 5);
Colors := GetColors(TPA);
SetLength(SortedTPA, Length(TPA));
Count := 0;
for C := 0 to High(TPA) do
begin
colortoxyz(colors[i], x, y, z);
if(x > 1)and(x < 22)and(y > 0)and(y < 11)and(z > 1)and(z < 28)then
begin
colortohsl(colors[i], h, s, l);
if (h > 17)and(h < 22)and(s > 23)and(s < 62)and(l > 7)and(l < 45) then
begin
SortedTPA[Count] := TPA[C];
Count := Count + 1;
end;
end;
end;
SetLength(SortedTPA, Count);
SortedTPA := TPA;
begin
ATPA := SplitTPAEx(SortedTPA, 20, 15);
SortATPAFrom(ATPA, IntToPoint(MSCX, MSCY));
for i := 0 to High(ATPA) do
if Length(ATPA[i]) >= 50 then
begin
MiddleTPAEx(ATPA[i], a, b);
MMouse(a-10, b-10, 21, 21);
Wait(50 + random(50));
if IsUpText(UpText) then
begin
Result := True;
Getmousepos(a, b);
Exit;
end;
end;
end;
end;
Usage example
Findtree(x, y, 'yew');
You can choose between tree, oak, willow and yew and all.