SRL Archive - Research & Development Lounge

[Function]radialCompassWalk


Velvet Glam

2012-03-01 12:27:01

I use this in my guild miner :), but it is very useful to others..It has been done on this forum before, but nothing recent..

This function will allow you to walk to a color at any compass angle. YOU MUST GET THE ORIGINAL RADIALS & OFFSETS WHILE FACING NORTH!

I have the function personalized, but you can very easily add tolerance and specific radiuses..

Once this function finds the object middle, it then rotates your offsets, and finally reduces your offsets(if needed) so it does not click off the minimap, which is cool..

function radialCompassWalk(color, startRad, endRad, xOffset, yOffset, flagDist: Integer): Boolean;
var
TPA: TPointArray;
p: TPoint;
currentAngle, i, newStart, newEnd, x, y: Integer;
begin
Result := False;

currentAngle := Round(rs_GetCompassAngleDegrees);

if InRange(currentAngle, 0, 5) or InRange(currentAngle, 355, 360) then
begin
newStart := startRad;
newEnd := endRad;
end else
begin
newStart := startRad - currentAngle;
newEnd := endRad - currentAngle;
end;
if newStart < 0 then
newStart := newStart + 360;
if newEnd < 0 then
newEnd := newEnd + 360;

FindColors(TPA, color, MMX1, MMY1, MMX2, MMY2);
FilterPointsPie(TPA, newStart, newEnd, 10, 76, MMCX, MMCY);

if Length(TPA) > 0 then
begin
p := MiddleTPA(TPA);
p := RotatePoint(Point(p.x + xOffset, p.y + yOffset),
2 * PI - rs_GetCompassAngleRadians,
p.x, p.y);

i := Round(FixD(Degrees(ArcTan2(p.y - MMCY, p.x - MMCX)) + 90)) / 45;
case i of
0, 7, 8 : y := 1;
1, 2 : x := -1;
3, 4 : y := -1;
5, 6 : x := 1;
end;
i := 0;
while ( not rs_OnMinimap(p.x, p.y) ) and
( i < 45 ) do
begin
p.x := p.x + x;
p.y := p.y + y;
i := i + 1;
end;

Result := rs_OnMinimap(p.x, p.y);
if ( not Result ) then
Exit;

Mouse(p.x, p.y, 0, 0, True);
FFlag(flagDist);
end;
end;