Yea. Last night I did this
SCAR Code:
function BoxArrayToArrayOfTPA(Color:integer; Boxes:array of TBox): array of TPointArray;
var i:integer;
begin
setarraylength(result,getarraylength(boxes));
for i:=0 to GetArrayLength(Boxes)-1 do
FindColorsTolerance(result[i],Color,Boxes[i].x1,Boxes[i].y1,Boxes[i].x2,Boxes[i].y2,0);
end;
to get the points of the doors. Used with this
SCAR Code:
program New;
{.include SRL/SRL.scar}
const doorcolor=235;
var skippingarray:tboxarray;
AOTPA:array of TpointArray;
vx,f,vy:integer;
function tPtArrayToStr(newTPoint: TPointArray): string;
var
i: Integer;
begin
for i:=0 to GetArrayLength(newTPoint)-1 do
begin
Result := Result + IntToStr(newTPoint[i].x) + ',' +
IntToStr(newTPoint[i].y);
if (not (i = (GetArrayLength(newTPoint) - 1))) then
Result := Result + ' ';
end;
end;
function BoxArrayToArrayOfTPA(Color:integer; Boxes:array of TBox): array of TPointArray;
var i:integer;
begin
setarraylength(result,getarraylength(boxes));
for i:=0 to GetArrayLength(Boxes)-1 do
FindColorsTolerance(result[i],Color,Boxes[i].x1,Boxes[i].y1,Boxes[i].x2,Boxes[i].y2,0);
end;
procedure DisplayPicture(TheBox:tbox);
var
DebugCanvas, ClientCanvas: TCanvas;
w, h, bmp: Integer;
begin
w := Thebox.x2 - Thebox.x1;
h := Thebox.y2 - Thebox.y1;
ActivateClient;
DisplayDebugImgWindow(w, h);
DebugCanvas := GetDebugCanvas;
ClientCanvas := GetClientCanvas;
SafeCopyCanvas(ClientCanvas, DebugCanvas, TheBox.x1,TheBox.y1,TheBox.x2,TheBox.y2, 0, 0, w, h);
//bmp := BitmapFromString(w, h, '');
//CopyClientToBitmap(bmp,Thebox.x1, Thebox.y1, Thebox.x1 + w, Thebox.y1 + h);
//DisplayDebugImgWindow(w, h);
//CopyCanvas(GetBitmapCanvas(bmp), GetDebugCanvas, TheBox.x1,TheBox.y1,TheBox.x2,TheBox.y2, 0, 0, w, h);
end;
function SurroundBox(px,py:integer):Tbox;
var Inner,Outer:Tbox;
PointColor,dx,dy:integer;
begin
PointColor:=GetColor(px,py);
Inner.x1:=px;
Inner.y1:=py;
Inner.x2:=px;
Inner.y2:=py;
Outer.x1:=px-5;
Outer.y1:=py-5;
Outer.x2:=px+5;
Outer.y2:=py+5; {
repeat
// Outer.x1:=Outer.x1-1;
Inner.x1:=Inner.x1-1;
//writeln('test3');
until (not(FindColorSkipBox(dx,dy,PointColor,Outer.x1,Outer.y1,Inner.x1,Outer.y2,Inner)));
//writeln('test2');
repeat
// Outer.Y1:=Outer.Y1-1;
Inner.Y1:=Inner.y1-1;
until (not(FindColorSkipBox(dx,dy,PointColor,Outer.x1,Outer.y1,Outer.x2,Outer.y2,Inner)));
//writeln('test1');
repeat
//Outer.x2:=Outer.x2+1;
Inner.x2:=Inner.x2+1;
until (not(FindColorSkipBox(dx,dy,PointColor,Outer.x1,Outer.y1,Outer.x2,Outer.y2,Inner)));
// writeln('test1');
repeat
// Outer.y2:=Outer.y2+1;
Inner.y2:=Inner.y2+1;
until (not(FindColorSkipBox(dx,dy,PointColor,Outer.x1,Outer.y1,Outer.x2,Outer.y2,Inner)));
//writeln('test1');
Result:=inner; }result:=outer;
end;
var arraylength,i:integer;
begin
SetupSRL;
// DisplayPicture(657,120,671,129);
//mybox:=Surroundbox(myx,myy);
setarraylength(skippingarray,1);
skippingarray[0].x1:=0;
skippingarray[0].y1:=0;
skippingarray[0].x2:=1;
skippingarray[0].y2:=1;
arraylength:=1;
repeat {566,6,730,163}
if FindColorSkipBoxArray(vx,vy,DoorColor,mmx1,mmy1,mmx2,mmy2,skippingarray) then
begin
//writeln('found');
//writeln(inttostr(arraylength));
//arraylength:= getarraylength(skippingarray);
arraylength:=arraylength+1;
setarraylength(skippingarray,arraylength);
skippingarray[arraylength-1]:= Surroundbox(vx,vy);
//writeln('test1');
end;
writeln(inttostr(arraylength));
wait(1);
until ((isfkeydown(11)) or (not(FindColorSkipBoxArray(vx,vy,DoorColor,mmx1,mmy1,mmx2,mmy2,skippingarray))));
writeln('done');
{ repeat
repeat
wait(1000);
until isfkeydown(12);
i:=i+1;
DisplayPicture(Skippingarray[i]);
repeat
wait(1000);
until isfkeydown(11);
until i=(arraylength-1); }
AOTPA:=BoxArrayToArrayOfTPA(doorColor,Skippingarray)
for f:= 0 to getarraylength(AOTPA)-1 do
writeln(tPtArrayToStr(AOTPA[f]));
end.
Look at that output compared to just doing findcolorstolerance for the whole minimap. This was they are separated, 1 list for each door.
Now I am working on something to get 1 point to represent each door. I started with
SCAR Code:
program New;
{.include SRL/SRL.scar}
var tpa:tpointarray;
Tp:tpoint;
function MidPointOfLine(TheArray:array of Tpoint):Tpoint;
var
i,ArrayLength,
DiffX,TotalX,{AveX,}AverageX,
DiffY,TotalY,{AveY,}AverageY:integer;
AveX,AveY:extended;
begin
DiffX:=100;
diffy:=100;
ArrayLength:=GetArrayLength(TheArray)
for i:=0 to ArrayLength-1 do
TotalX:=TotalX+TheArray[i].x;
AveX:={Round}(TotalX/ArrayLength);
for i:=0 to ArrayLength-1 do
TotalY:=TotalY+TheArray[i].y;
AveY:={Round}(TotalY/ArrayLength);
for i:=0 to ArrayLength-1 do
begin
if (Abs(AveX-TheArray[i].x)) < DiffX then
begin
DiffX:=Round(Abs((AveX-TheArray[i].x)*1.0));
AverageX:=i;
end;
end;
for i:=0 to ArrayLength-1 do
begin
if (Abs(AveY-TheArray[i].y)) < DiffY then
begin
DiffY:=Round(Abs((AveY-TheArray[i].y)*1.0));
AverageY:=i;
end;
end;
i:=(averagex + averagey)/2;
result:=TheArray[i];
end;
function strToTPtArray(tPtStr: string): TPointArray;
var
i, commaPos, spacePos: Integer;
begin
repeat
SetArrayLength(Result, i + 1);
commaPos := Pos(',', tPtStr);
spacePos := Pos(' ', tPtStr);
Result[i].x := StrToInt(Copy(tPtStr, 1, commaPos - 1));
if (not (spacePos = 0)) then
begin
Result[i].y := StrToInt(Copy(tPtStr, commaPos + 1, spacePos - commaPos -
1));
end
else
begin
Result[i].y := StrToInt(Copy(tPtStr, commaPos + 1, Length(tPtStr)));
break;
end;
Delete(tPtStr, 1, spacePos);
i := i + 1;
until (False)
end;
begin
SetupSRL;
tpa:=strToTPtArray('610,73 610,74 610,75 610,76 610,77 611,77 611,78');
tp:=MidPointOfLine(TPA);
writeln(inttostr(tp.x)+','+inttostr(tp.y));
end.
but it doesn't work due to the way it finds the closet point to the average of points. I didn't want to have to go this far, but it looks like I will have to determine whether the door is north-south or east-west first. If the x coords are in a close range, pick the middle of the ys, and vice versa. If the door is diagonal, I can use the old method of averaging both x and y.
Once I have whether they are vertical or horizontal, and a point for each door, I can look at which is the eastern most, second western most, etc, and use this information to get around lumbridge castle (see thread in free scripts section).
Edit: I overcomplicated things as usual. I don't even need to look at the value of the TPoints.x and y. FindColorsTolerance puts the points in order for me. I need only look at the indexes of the TPoint Array and get the middle one.
SCAR Code:
program New;
{.include SRL/SRL.scar}
var tpa:tpointarray;
Tp:tpoint;
function MidPointOfLine(TheArray:array of Tpoint):Tpoint;
begin
result:=TheArray[round(getarraylength(TheArray)/2)-1];
end;
function strToTPtArray(tPtStr: string): TPointArray;
var
i, commaPos, spacePos: Integer;
begin
repeat
SetArrayLength(Result, i + 1);
commaPos := Pos(',', tPtStr);
spacePos := Pos(' ', tPtStr);
Result[i].x := StrToInt(Copy(tPtStr, 1, commaPos - 1));
if (not (spacePos = 0)) then
begin
Result[i].y := StrToInt(Copy(tPtStr, commaPos + 1, spacePos - commaPos -
1));
end
else
begin
Result[i].y := StrToInt(Copy(tPtStr, commaPos + 1, Length(tPtStr)));
break;
end;
Delete(tPtStr, 1, spacePos);
i := i + 1;
until (False)
end;
begin
SetupSRL;
tpa:=strToTPtArray('610,73 610,74 610,75 610,76 610,77 611,77 611,78');
tp:=MidPointOfLine(TPA);
writeln(inttostr(tp.x)+','+inttostr(tp.y));
end.