You are still talking about meters, but there is no such function that will tell you range in meters. All functions returns normalized position on the selected map - numbers between 0 and 1:
Code:
0,0 --- 0,1
| |
| |
1,0 --- 1,1
Each map texture has different scale, so you can't use texture size or number of tiles to calculate distance in meters.
I do not know if it is reliable, but you can try to get position relative to the world map. In this case you will need just one scale:
Lua Code:
SetMapToPlayerLocation()
local mapId = GetCurrentMapIndex()
--if current map is subzone or dungeon, mapId is nil
if mapId == nil then
--select parent map
MapZoomOut()
--parent map of both dungeons and subzones is always zone with defined mapId
--but I never tried it on main quest or guild maps
mapId = GetCurrentMapIndex()
end
local worldsize
--if mapId is 23 it means that current world map is Coldharbour
if mapId ~= 23 then
--select Tamriel world map. I could use MapZoomOut() once more, but I think this is safer way how to select map
SetMapToMapListIndex(1)
worldsize = 33440 --Tamriel size in meters
else
worldsize = 6000 --Coldharbour size in meters
--size is untested, I have found it in Zygor's addon
end
local playerX, playerY = GetMapPlayerPosition("player")
local targetX, targetY = GetMapPlayerPosition("reticleover")
--return map back to player
SetMapToPlayerLocation()
local dX = targetX - playerX
local dY = targetY - playerY
local normalizedDistance = zo_sqrt(dX*dX + dY*dY)
local distance = normalizedDistance * worldsize
d(zo_strformat("Distance is: <<1>>m", zo_round(distance))
(completely untested code, I have typed it without testing)