SRL Archive - Test corner

FindObjDoor


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).

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 :)

SKy Scripter

2007-06-19 17:02:51

i wish i was as smart as you :)


kool if it works fast…. nice job :)

Bobarkinator

2007-06-19 17:41:45

Good job. Arrays are the best :)

I still hate XYZ lol

WhiteShadow

2007-06-19 18:09:37

Mainscreen bruteforcing, nice. Looks like a great function, nielsie. :) I'll test it later for you.

SKy Scripter

2007-06-20 00:00:50

I still hate XYZ lol


dude XYZ is very nice… it is based off the human eye…. same
with L*A*B…

n3ss3s

2007-06-20 05:04:22

What the H*** are LAB and XYZ ?? heard of em but cant remember..

nielsie95

2007-06-20 08:23:57

XYZ and LAB.

But now on-topic.. Test, please :)

JuKKa

2007-06-20 08:48:43

nielsie nielsie… WHERE are u from? :duh:

so complicated :redface:

rkroxpunk

2007-06-20 09:47:06

Works in draynor 100% but don't be too far away from the door as it won't find it but if u just use the red on the MM you should end up right next to it, hence it will find :P

EDIT: Fally works 100% so does lumby. for lumby just a note the double doors and single doors outside are normal (type 1) but the single doors inside castle are lumby(type2)

Starblaster100

2007-06-20 10:56:14

3 words

A - Maz - ing!

Bobarkinator

2007-06-20 11:05:02

That's one word to the intelligent human being :p

neG

2007-06-23 07:14:39

Worked 100% for me.
Everytime. Nice work!! :p

From: nielsie95
XYZ and LAB.

But now on-topic.. Test, please :)


Haha, that was a really boring read.
Someone should right a tutorial on how to implement it into SCAR scripting.

SKy Scripter

2007-06-23 12:14:38

Someone should right a tutorial on how to implement it into SCAR scripting.

iv thought about it.. but i cant write tuts that well XD.
and nobody would understand lol…. i might make a EDITER tool to help people though…. :p

nielsie95

2007-06-23 17:48:56

@neG: You could read my tut about AutoColoring. It handles BruteForcing with RGB… It's pretty much the same way with other styles (HSL + XYZ).

Town

2007-06-25 11:50:25

Very nice. You have to move the map/angles, etc depending on whether it's open or closed. You have to be able to see the large side of the door. That's easy enough though, seems to work perfectly. Which procedure is it that writes the uptext in the debug box, "IsMultiUpTextColor(13159171, 60, tr_Letters, 'oor', 'or', 'Do')"?

– Using normal doors.