View Single Post
01/09/19, 03:04 AM   #7
Hydra9268
 
Hydra9268's Avatar
AddOn Author - Click to view addons
Join Date: May 2018
Posts: 33
Based on Garkin's awesome script (Big kudos).

lua Code:
  1. -- Based on Garkin's Guide
  2. -- [url]https://www.esoui.com/forums/showthread.php?t=1557[/url]
  3.  
  4. local ZGESO = {}
  5.  
  6. -- Pin's unique ID
  7. ZGESO.pinType = "MyMapPin"
  8.  
  9. -- Pin Data
  10. ZGESO.pinLayoutData = {
  11.     { level = 50, texture = "/Arrows/Stealth/arrow-error.dds", size = 40 },
  12. }
  13.  
  14. -- Unit test sample data
  15. ZGESO.pinData = {
  16.     ["alikr"] = {
  17.         ["sentinel_base"] = {
  18.             { x = 0.130820446, y = 0.378319359 },
  19.         },
  20.     },
  21. }
  22.  
  23. -- Tooltip Creator
  24. ZGESO.pinTooltipCreator = {
  25.     creator = function(pin)
  26.         local x, y = pin:GetNormalizedPosition()
  27.         InformationTooltip:AddLine( zo_strformat( "Position of my pin is: <<1>>,<<2>>", x*1000, y*1000 ) )
  28.     end,
  29.     tooltip = InformationTooltip,
  30. }
  31.  
  32. -- Add a Callback Function
  33. function ZGESO.pinTypeAddCallback(pinManager)
  34.     -- Do not create pins if your pinType is not enabled
  35.     if not ZO_WorldMap_IsCustomPinEnabled(_G[ZGESO.pinType]) then return end
  36.    
  37.     -- Do not create pins on world, alliance and cosmic maps
  38.     if (GetMapType() > MAPTYPE_ZONE) then return end
  39.  
  40.     -- Okay to continue
  41.     local textureName = GetMapTileTexture()
  42.     textureName = string.lower(textureName)
  43.     local _,_,_,zone,subzone = string.find(textureName, "(maps/)([%w%-]+)/([%w%-]+_%w+)")
  44.     local pins
  45.     print(zone, subzone)
  46.  
  47.     if ZGESO.pinData[zone] and ZGESO.pinData[zone][subzone] then
  48.         pins = ZGESO.pinData[zone][subzone]
  49.     else
  50.         return  -- Return if there's no current map data
  51.     end
  52.  
  53.     for _, pinInfo in ipairs(pins) do
  54.         -- ZO_WorldMapPins:CreatePin(pinTypeId, pinTag, locX, locY, areaRadius)
  55.         -- pinTag can be anything, but I recommend using table or string with additional info about pin, you can use it later in code
  56.         pinManager:CreatePin(_G[ZGESO.pinType], pinInfo, pinInfo.x, pinInfo.y)
  57.    end
  58. end
  59.  
  60. -- Resize callback function (usualy just nil)
  61. function ZGESO.pinTypeOnResizeCallback(pinManager, mapWidth, mapHeight)
  62.     local visibleWidth, visibleHeight = ZO_WorldMapScroll:GetDimensions()
  63.     local currentZoom = mapWidth / visibleWidth
  64.    
  65.     if currentZoom < 1.5 then
  66.         ZO_WorldMap_SetCustomPinEnabled(_G[ZGESO.pinType], false)
  67.     else
  68.         ZO_WorldMap_SetCustomPinEnabled(_G[ZGESO.pinType], true)
  69.     end
  70.  
  71.    ZO_WorldMap_RefreshCustomPinsOfType(_G[ZGESO.pinType])
  72. end
  73.  
  74. function OnLoad(eventCode, name)
  75.     -- The name of this addon
  76.     if name ~= "ZGESO" then return end
  77.  
  78.    -- Initialize map pins
  79.    ZO_WorldMap_AddCustomPin(ZGESO.pinType, ZGESO.pinTypeAddCallback, ZGESO.pinTypeOnResizeCallback, ZGESO.pinLayoutData, ZGESO.pinTooltipCreator)
  80.    
  81.    -- Custom pins are disabled by default, you have to enable them
  82.    ZO_WorldMap_SetCustomPinEnabled(_G[ZGESO.pinType], true)
  83.    
  84.    -- Force refresh pins to call pinTypeAddCalback for the current map
  85.    ZO_WorldMap_RefreshCustomPinsOfType(_G[ZGESO.pinType])
  86.  
  87.    EVENT_MANAGER:UnregisterForEvent("ZGESO_OnLoad", EVENT_ADD_ON_LOADED)
  88. end
  89.  
  90. EVENT_MANAGER:RegisterForEvent("ZGESO_OnLoad", EVENT_ADD_ON_LOADED, OnLoad)

It looks like the code works but there's a problem with the level value in ZO_MapPin.SetData?
https://esodata.uesp.net/100025/src/....lua.html#3347

lua Code:
  1. bad argument #1 to 'math.max' (number expected, got nil)
  2. stack traceback:
  3. [C]: in function 'math.max'
  4. EsoUI/Ingame/Map/WorldMap.lua:3347: in function 'ZO_MapPin:SetData'
  5.     <Locals> self = tbl, pinType = 206, pinTag = tbl, control = ud, labelControl = ud, singlePinData = tbl, overlayControl = ud, highlightControl = ud </Locals>   
  6. EsoUI/Ingame/Map/WorldMap.lua:3687: in function 'ZO_WorldMapPins:CreatePin'
  7.     <Locals> self = tbl, pinType = 206, pinTag = tbl, xLoc = 0.130820446, yLoc = 0.378319359, pin = tbl, pinKey = 71 </Locals> 
  8. user:/AddOns/ZGESO/Pointer.lua:181: in function 'ZGESO.pinTypeAddCallback'
  9.     <Locals> pinManager = tbl, textureName = "art/maps/alikr/sentinel_bas...", _ = 5, _ = 28, _ = "maps/", zone = "alikr", subzone = "sentinel_base", pins = tbl, _ = 1, pinInfo = tbl </Locals>   
  10. EsoUI/Ingame/Map/WorldMap.lua:3667: in function 'ZO_WorldMapPins:RefreshCustomPins'
  11.     <Locals> self = tbl, pinTypeId = 206, pinData = tbl </Locals>  
  12. EsoUI/Ingame/Map/WorldMap.lua:6100: in function 'ZO_WorldMap_UpdateMap'
  13.     <Locals> zoneName = "Sentinel", mapTitle = "Sentinel" </Locals>
  14. user:/AddOns/ZGESO/Viewer/GuideViewerFrame.lua:1095: in function 'Viewer:HandleActionLayer'
  15.     <Locals> self = tbl, isActive = [C]:-1 </Locals>   
  16. user:/AddOns/ZGESO/Viewer/GuideViewerFrame.lua:1133: in function 'Viewer:EVENT_ACTION_LAYER_POPPED'
  17.     <Locals> self = tbl, event = 65553, layerIndex = 7, activeLayerIndex = 2 </Locals> 
  18. user:/AddOns/ZGESO/Events.lua:58: in function 'EventHandler'
  19.     <Locals> event = 65553, self = tbl, eventString = "EVENT_ACTION_LAYER_POPPED", _ = 1, hand = tbl, func = user:/AddOns/ZGESO/Viewer/GuideViewerFrame.lua:1131, funcSelf = tbl </Locals>

Extra information:

1. The pinLayoutData array has a value for level.

2. The print(zone, subzone) on line 45 splits out what appears to be an endless list of zone, subzone. My conclusion is there needs to be a max value to stop it from overloading ZO_MapPin.SetData. Is that causing the problem?


3. An observational finding https://i.imgur.com/SpnGhqf.png

Last edited by Hydra9268 : 01/09/19 at 03:40 AM.
  Reply With Quote