Havent tried this but it compiles:
function CheckIfOnMSIfNotFixLoc (IDs : TIntegerArray) : Boolean;
var
Alters, DistancesToAlter, DistanceQuickSort : TIntegerArray;
AlterUnique : TRSObject;
Alter : TRSObjectArray;
I,II : Integer;
OnMS : Boolean;
begin
If Not LoggedIn Then Exit;
Result := false;
OnMS := False;
For I:= 0 To high(IDs) Do
Begin
AlterUnique := GetObjectByID(IDs[I],OBJECT_TYPE_INTERACTABLE,25);
If TileOnMS(AlterUnique.Tile,0) Then
Begin
Result := True;
Exit;
End;
End;
if not Result then
begin
Alter := GetObjectsByID(IDs,OBJECT_TYPE_INTERACTABLE,25);
Writeln ('Did not find any alters on the mainscreen, now moving to nearest one.');
SetArrayLength (DistancesToAlter, high(IDs)+1);
SetArrayLength (DistanceQuickSort, high(IDs)+1);
For I:= 0 To high(Alter) Do
Begin
DistancesToAlter[I] := DistanceFrom (Alter[I].Tile);
DistanceQuickSort[I] := DistanceFrom (Alter[I].Tile);
End;
QuickSort(DistanceQuickSort);
For II:=0 to high(IDs) do
begin
if DistanceQuickSort[0] = DistancesToAlter[II] then
begin
if TileOnMM (Alter[II].Tile) then
begin
WalkPath ([Alter[II].Tile]);
wait (300+random(300));
Result := True;
Exit;
end else
begin
Writeln ('The closest alter was not on the minimap, something is terribly wrong.');
Exit;
end;
end;
end;
end;
end;
Function GetWhere : String;
Var
Alters : TIntegerArray;
Alter : TRSObject;
I,II : Integer;
Begin
If Not LoggedIn Then Exit;
Result := ''; // Must have failsafe
II := -1; // Failsafe
Alters := [2478, 2479, 2480, 2481, 2482, 2483]; // Air/mind/water/earth/fire/body
If CheckIfOnMSIfNotFixLoc (Alters) then
Begin
For I:= 0 To 5 Do
Begin
Alter := GetObjectByID(Alters[I],OBJECT_TYPE_INTERACTABLE,25);
If TileOnMS(Alter.Tile,0) Then
Begin
II := I
Break;
End;
End;
if II = -1 then Writeln ('Warning, could not find any alters on the mainscreen');
Case II Of
0: Result := 'Air';
1: Result := 'Mind';
2: Result := 'Water';
3: Result := 'Earth';
4: Result := 'Fire';
5: Result := 'Body';
End;
End Else Writeln ('Warning: No alter was on MS');
End;
What I do in that new function is:
1) Check if any of them are on mainscreen, if so return true and exit
2) If not, then get the distances to all the alters
3) Quicksort the distances (makes lowest number first, biggest last)
4) Check the distance array (to see which one is closest) based on Quicksort's first array position (which is our closest)
5) Moves to that one on the minimap, if it can't returns false
Now, if you don't want to move to the closest one, then you can't really use that function.