View Single Post
05/24/14, 03:45 PM   #9
Garkin
 
Garkin's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 832
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:
  1. SetMapToPlayerLocation()
  2. local mapId = GetCurrentMapIndex()
  3. --if current map is subzone or dungeon, mapId is nil
  4. if mapId == nil then
  5.    --select parent map
  6.    MapZoomOut()
  7.    --parent map of both dungeons and subzones is always zone with defined mapId
  8.    --but I never tried it on main quest or guild maps
  9.    mapId = GetCurrentMapIndex()
  10. end
  11.  
  12. local worldsize
  13. --if mapId is 23 it means that current world map is Coldharbour
  14. if mapId ~= 23 then
  15.    --select Tamriel world map. I could use MapZoomOut() once more, but I think this is safer way how to select map
  16.    SetMapToMapListIndex(1)
  17.    worldsize = 33440   --Tamriel size in meters
  18. else
  19.    worldsize = 6000    --Coldharbour size in meters
  20.    --size is untested, I have found it in Zygor's addon
  21. end
  22. local playerX, playerY = GetMapPlayerPosition("player")
  23. local targetX, targetY = GetMapPlayerPosition("reticleover")
  24. --return map back to player
  25. SetMapToPlayerLocation()
  26.  
  27. local dX = targetX - playerX
  28. local dY = targetY - playerY
  29.  
  30. local normalizedDistance = zo_sqrt(dX*dX + dY*dY)
  31.  
  32. local distance = normalizedDistance * worldsize
  33.  
  34. d(zo_strformat("Distance is: <<1>>m", zo_round(distance))
(completely untested code, I have typed it without testing)

Last edited by Garkin : 05/24/14 at 03:48 PM.
  Reply With Quote