
Originally Posted by
TomTuff
Find the teleport focus's tile. Sort the door object tiles by the distance from the teleport focus. The first door in the sorted array is the door your after (Doors[0]).
Thanks I got it:
Simba Code:
//Sorts Objects By Distance From Another..
//Objects = Multiple Objects To Sort.
//SingleObject = Object To Sort From.
//SingleObjectType = Type Of Object To Sort From.
//Distance = Distance from you to the SingleObject Object to Search.
function R_SortObjects(Objects: TRSOBJECTARRAY; SingleObject, SingleObjectType, Distance: Integer): TRSOBJECTARRAY;
var
i,i2, L: integer;
tpa: TPointArray;
Obj, AltarDoor: TRSOBJECT;
begin
Obj:= R_GetObject(SingleObject, SingleObjectType, Distance);
if(R_FindObject(SingleObject, SingleObjectType, Distance, Obj)) then
Repeat
wait(RandomRange(500, 1000));
Until(R_FindObject(SingleObject, SingleObjectType, Distance, Obj));
L := GetArrayLength(Objects);
if L < 1 then Exit;
SetArrayLength(TPA, L);
SetArrayLength(Result, L);
for i := 0 to L-1 do
TPA[i] := Objects[i].Tile;
SortTPAFrom(TPA, Obj.Tile);
for i := 0 to L-1 do
for i2 := 0 to L-1 do
if (TPA[i].x=Objects[i2].Tile.x) and (TPA[i].y=Objects[i2].Tile.y) then
Result[i] := Objects[i2];
end;