Home API Manuals About Forum
Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Back to homepage

GetDistance

Returns the distance in tiles from the current character to the object with ObjID.

Returns -1 if the object does not exist. Otherwise returns the distance in tiles.

The distance is calculated as Round(Sqrt(dX*dX + dY*dY)) (Euclidean distance), where dX / dY are the coordinate differences between the character and the object. Only X and Y are used — Z is ignored.

This is a different metric from Dist, which returns Max(|dX|, |dY|) (Chebyshev distance) — the tile distance the server itself uses for range checks. Both agree along straight lines and diverge on diagonals: for an object offset by 2 tiles along both X and Y, Dist returns 2 while GetDistance returns 3. To reproduce a server-side range check, use Dist with GetX / GetY.

Unlike Dist (which takes two arbitrary coordinate pairs), this method always measures from the current character’s position. For an object inside a container, the distance is measured to its topmost parent — the container lying in the world, or the character carrying it.

Возвращает расстояние в тайлах от текущего персонажа до объекта с ObjID.

Возвращает -1, если объект не существует. Иначе возвращает расстояние в тайлах.

Расстояние вычисляется как Round(Sqrt(dX*dX + dY*dY)) (евклидово расстояние), где dX / dY — разности координат персонажа и объекта. Учитываются только X и Y — Z игнорируется.

Это другая метрика, чем у Dist, который возвращает Max(|dX|, |dY|) (расстояние Чебышёва) — именно такое расстояние в тайлах сервер использует для проверки дистанции. По прямой обе метрики совпадают, по диагонали расходятся: для объекта, смещённого на 2 тайла и по X, и по Y, Dist вернёт 2, а GetDistance3. Чтобы воспроизвести серверную проверку дистанции, используйте Dist с GetX / GetY.

В отличие от Dist (который принимает две произвольные пары координат), этот метод всегда измеряет от позиции текущего персонажа. Для объекта внутри контейнера расстояние измеряется до его самого верхнего родителя — контейнера, лежащего в мире, или персонажа, который его несёт.

Pascal

function GetDistance(ObjID: Cardinal): Integer;

Parameters:

  • ObjID — ID of the target object.

Python

def GetDistance(ObjID: int) -> int: ...

Pascal Example

begin
  if GetDistance(chest_id) > 1 then
  begin
    AddToSystemJournal('Proceeding to chest');
    MoveXY(GetX(chest_id), GetY(chest_id), True, 1, True);
    Wait(1000);
  end;
end.

Python Example

if GetDistance(chest_id) > 1:
    AddToSystemJournal('Proceeding to chest')
    MoveXY(GetX(chest_id), GetY(chest_id), True, 1, True)
    Wait(1000)

See Also

Dist, GetX, GetY