PDA

View Full Version : [FUNCTION] FindDoorColour: integer; By ZephyrsFury [FUNCTION]



ZephyrsFury
07-25-2007, 05:25 AM
This function is designed to return the red colour of the doors on the minimap. It searches for a colour between 200 and 254 (the typical colours of the doors) then uses the fact that drop dots don't have the same colour in more than one pixel. It searches the area 1 pixel around the colour found to make sure its a door colour. Then it continues searching, storing any other door colours it comes across. After finishing with colour 254, it will check to see if the door colours its found occur in any other places. The colour that is found the most will be returned.

I scripted this function because I've found SRL's GetDoorColor to be unreliable - returning the colours of drop dots more than the actual doors. This function is simple yet reliable. I use this in my Rune Mysteries Runner and it works very well even in the presence of many door colours and drop dots (Wizard's Tower for example).


function FindDoorColour: integer;
var
x1, y1, x2, y2, x3, y3, x4, y4 : integer;
DoorBox1, DoorBox2 : TBox;
i, TempColour1, TempColour2 : integer;
begin
for i := 200 to 254 do
begin
if (FindColor(x1, y1, i, MMX1, MMY1, MMX2, MMY2)) then
begin
if (FindColor(x2, y2, i, x1 - 1, y1 - 1, x1 + 1, y1 - 1)) or
(FindColor(x2, y2, i, x1 - 1, y1 - 1, x1 - 1, y1 + 1)) or
(FindColor(x2, y2, i, x1 - 1, y1 + 1, x1 + 1, y1 + 1)) or
(FindColor(x2, y2, i, x1 + 1, y1 - 1, x1 + 1, y1 + 1)) then
begin
TempColour1 := i;
Break;
end;
end;
end;
if (TempColour1 = 0) then Exit;
for i := TempColour1 + 1 to 254 do
begin
if (FindColor(x3, y3, i, MMX1, MMY1, MMX2, MMY2)) then
begin
if (FindColor(x2, y2, i, x3 - 1, y3 - 1, x3 + 1, y3 - 1)) or
(FindColor(x2, y2, i, x3 - 1, y3 - 1, x3 - 1, y3 + 1)) or
(FindColor(x2, y2, i, x3 - 1, y3 + 1, x3 + 1, y3 + 1)) or
(FindColor(x2, y2, i, x3 + 1, y3 - 1, x3 + 1, y3 + 1)) then
begin
TempColour2 := i;
Break;
end;
end;
end;
DoorBox1.x1 := x1 - 5;
DoorBox1.y1 := y1 - 5;
DoorBox1.x2 := x1 + 5;
DoorBox1.y2 := y1 + 5;
DoorBox2.x1 := x3 - 5;
DoorBox2.y1 := y3 - 5;
DoorBox2.x2 := x3 + 5;
DoorBox2.y2 := y3 + 5;
if (TempColour2 = 0) then
Result := TempColour1
else
if (FindColorSkipBox(x4, y4, TempColour1, MMX1, MMY1, MMX2, MMY2, DoorBox1)) then
Result := TempColour1
else
if (FindColorSkipBox(x4, y4, TempColour2, MMX1, MMY1, MMX2, MMY2, DoorBox2)) then
Result := TempColour2
end;


I'll also attach it as a SCAR file.

If you use this function in any of your scripts, please give me credit. I only released it because I'm nice. :p

Zeph

XcanadamanX
07-25-2007, 01:12 PM
ill check it out see how it goes.

edit: not bad not bad at all.

Boreas
07-25-2007, 03:53 PM
Please make sure you have the bugfix for Doors and then send me a screenie of where it got the wrong color.

n3ss3s
07-25-2007, 04:12 PM
Pretty good for non-member... Well its only one function, but maybe you zephyr will be applying soon?

ZephyrsFury
07-26-2007, 08:58 AM
Please make sure you have the bugfix for Doors and then send me a screenie of where it got the wrong color.

It was at Lummy Castle on the lower floor but all the doors have gone now. I don't have a screenie unfortunately but when I was making my Rune Mysteries Runner, I used GetDoorColor to find the colour then moved on to FindColorTolerance if GetDoorColor returned 0 (this happened quite a lot). Other times it returned colours like 206 and 217 which I found only in the drop dots.

And yes I might apply soon. :)

nielsie95
07-26-2007, 09:47 AM
Are you sure you had the bugfix (http://www.srl-forums.com/forum/doors-t8796.html?p=81685#post81685) :)?

ZephyrsFury
07-26-2007, 09:57 AM
Yes... I'm sure that I was using SCAR 3.06+ with SRL 3.81 because it was after that update that caused everyone so much trouble. Anyway, It doesn't matter now. I think I'll use my function even if GetDoorColor works. ;)

Boreas
07-27-2007, 05:17 AM
The bugfix may not have been in 3.81. Eh mine is twice as fast, although it doesn't get called over and over again so it won't make a difference.

ZephyrsFury
07-27-2007, 08:14 AM
The bugfix may not have been in 3.81. Eh mine is twice as fast, although it doesn't get called over and over again so it won't make a difference.

Lol.. thats just because its made by you. I made it call FindColor around 10 times so thats probably why.

EDIT: Wow, its actually about 600 times...

Eicca
07-27-2007, 08:35 AM
Pretty genius :D Gj m8!

ZephyrsFury
07-27-2007, 08:45 AM
Pretty genius :D Gj m8!

Why thank you... :D But its not really, just a heap of FindColor functions called like 600 times.