There is already a timeout built into SPS_WalkPath .. it has a 25 second timeout, I think when it goes back after clicking the minimap it should compare the position that it got to the old position and if it didnt change then exit.
// Walks the path "Path"; always walks to the furthest point possible
function SPS_WalkPath(Path: TPointArray): boolean;
var
I, H, T, D: integer;
P, MM,tempP: TPoint;
begin
tempP := Point(-1,-1);
H := High(Path);
T := GetSystemTime + 20000 + Random(5000);
while (not Result) and (GetSystemTime < T) do
begin
RunEnergy(20);
P := SPS_GetMyPos;
If tempP.X <> -1 then // check if player is stuck.
if InRange(tempP.X, (P.X - 10), (P.X + 10)) then
If InRange(tempP.Y, (P.Y - 10), (P.Y + 10)) then
Begin
Result := false;
Exit;
end;
tempP := P;
for I := H downto 0 do
begin
MM.X := MMCX + Path[I].X - P.X;
MM.Y := MMCY + Path[I].Y - P.Y;
D := Distance(MM.X, MM.Y, MMCX, MMCY);
if (D < 10) then
break
else
if (D < 70) then
begin
if (SPS_MultiMouse) then
MultiMouse(MM.X, MM.Y, 25, 3, false)
else
Mouse(MM.X, MM.Y, 5, 5, mouse_Left);
FFlag(Integer(I <> H) * 15);
T := getSystemTime + 20000 + Random(1000);
Break;
end;
end;
Result := (I = H);
end;
end;