This bit is from Nautilus. It looks for the dots on screen and finds the closest one to u and moves the camera to it. There is a couple booleans that are in script and not explained in it. Its a bit more complex but its way faster then randomly searching.
SCAR Code:
function MobTPAs: TPointArray;
var
TPA: TPointArray;
begin
FindColorsSpiralTolerance(MMCX, MMCY, TPA, 195836, MMCX - 35, MMCY - 35, MMCX + 35, MMCY + 35, 0);
if Length(TPA) < 1 then
Exit;
RAaSTPA(TPA, 4);
SortTPAFrom(TPA, IntToPoint(MMCX, MMCY));
result := TPA;
end;
function MobsOnScreen: integer;
var
i: integer;
mTPA: TPointArray;
begin
mTPA := MobTPAs;
for i := 0 to High(mTPA) do
if InAbstractBox(590, 63, 656, 63, 646, 100, 600, 100, mTPA[i].x, mTPA[i].y) then
result := result + 1;
end;
function MobFinder: boolean;
var
mTPA: TPointArray;
mAng: Integer;
begin
mTPA := MobTPAs;
if Length(mTPA) < 1 then
begin
result := false;
Exit;
end;
if (Distance(mTPA[0].x, mTPA[0].y, MMCX, MMCY) > 17) then
begin
if ClickToMobMM then
begin
Mouse(mTPA[0].x - 2, mTPA[0].y - 2, 5, 5, true);
FFlag(1);
end
else
begin
result := false;
exit;
end;
end
else
begin//Calculates the angle to the NPC - important bit
mAng := Round(Degrees(ArcTan2(mTPA[0].Y - MMCY, mTPA[0].X - MMCX)) + 90 + rs_GetCompassAngleDegrees);
if (mAng < 0) then
mAng := mAng + 360;
if (mAng > 360) then
mAng := mAng - 360;
mAng := RandomRange(mAng - 20, mAng + 20);
MakeCompass(inttostr(mAng));
end;
if (MobsOnScreen > 0) then
result := true;
end;