Hi, this is my code which clicks the Hill Giant Dungeon door, east of the Cooks Guild. I tried to use TPAs to detect the door which has the same color as all trees around the door. The script works perfectly. However, I was wondering if there is a better way to rewrite this code.
I tried to use FindObjTPA but it just randomly moves all around the screen before it finds my Door.
This is my code.
Simba Code:
Function clickDoor:Boolean;
var
x, y, i, l, l1, dx, dy, doorColor, doorTol, startTime:Integer;
TPA, TPA1: TPointArray;
ATPA: T2DPointArray;
Box1: TBox;
begin
doorColor := 2107434;
doorTol := 15;
MarkTime(startTime);
while(TimeFromMark(startTime)<10000) do
begin
if FindColorsSpiralTolerance(MSCX,MSCY,TPA,doorColor,MSX1,MSY1,MSX2,MSY2,doorTol) then
begin
ATPA := SplitTPA(TPA,1);
SortATPAFromFirstPoint(ATPA,Point(MSCX, MSCY));
DebugATPA(ATPA,'');
l := High(ATPA);
for i:=0 to l do
begin
TPA1 := ATPA[i];
l1 := High(TPA1);
Box1 := GetTPABounds(TPA1);
dx := Box1.X2-Box1.X1;
dy := Box1.Y2-Box1.Y1;
if (l1>400) and (l1<2200) and (dx<60) and (dy<80) then
if MiddleTPAEx(TPA1, x, y) then
begin
MMouse(x, y, 5, 5);
writeln('Points:'+IntToStr(l1)+' dx:'+IntToStr(dx)+' dy"'+IntToStr(dy));
if WaitUpTextMulti(['pen Door', 'pen', 'oor', 'Door'], 700+random(300)) then
begin
ClickMouse2(true);
if DidRedClick then
begin
Result:=True;
break;
end;
end;
end;
end;
end;
wait(800+random(200));
end;
wait(3000+random(500));
end;