nielsie95
2007-06-19 16:57:18
Hey,
I made a DoorFinder.. You can choose out of 3 kinds of doors:
1 - Normal doors (Al-Kharid, Draynor, Lumbridge).
2 - Lumbridge doors (the weird looking doors).
3 - Varrock doors.
4 - Falador doors.
4 - All doors.
It may be a bit laggy when it's looking in an area where there are a lot of doorcolors (in varrock it lags always :p).
Please comment, suggest and post bugs :)
I made a DoorFinder.. You can choose out of 3 kinds of doors:
1 - Normal doors (Al-Kharid, Draynor, Lumbridge).
2 - Lumbridge doors (the weird looking doors).
3 - Varrock doors.
4 - Falador doors.
4 - All doors.
It may be a bit laggy when it's looking in an area where there are a lot of doorcolors (in varrock it lags always :p).
program DoorOpener;
{.Include SRL/SRL.SCAR}
const TDoorType = 2; // 1 - Normal doors, 2 - Lumbridge doors, 3 - Varrock doors, 4 - Falador, 5 - All kinds
function getArrayFromBox(arColor: TPointArray; Width, Height: Integer): TPointArray;
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;
begin
SetupSRL;
x := MSCX;
y := MSCY;
if FindObjDoor(x, y, TDoorType, MSX1 +5, MSY1 +5, MSX2 -5, MSY2 -5) then WriteLn('Found!');
end.Please comment, suggest and post bugs :)