Thread Tools Display Modes
06/07/14, 01:52 PM   #1
SkOODaT
 
SkOODaT's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 58
Question Need help with LibMapPins-1.0

I'm trying to take data from a saved var file and post it onto a map using LibMapPins-1.0 I've taken the TEST.lua from LibMapPins-1.0 and slightly altered it to start converting my other addon to use it the problem is tho i cant get it to pull the data from the saved var file for just the NPCs in the area on the map its just Nil and looks like it should work right, i am pretty new to lua still no pro was looking for some help here possibly.......


This is the generic MapPinTest.lua slightly altered... Line 51 is the problem im pretty sure.. but im lost

Lua Code:
  1. local LMP = LibStub("LibMapPins-1.0")
  2.  
  3. local pinType1 = "My_unique_name"
  4. local pinType2 = "My_even_more_unique_name"
  5. local pinTypeId1, pinTypeId2
  6.  
  7. --sample layout
  8. local pinLayoutData  = {
  9.    level = 50,
  10.    texture = "/esoui/art/mappins/compassvendor.dds",
  11.    size = 30,
  12. }
  13.  
  14. --tooltip creator
  15. local pinTooltipCreator = {
  16.    creator = function(pin)
  17.       local locX, locY = pin:GetNormalizedPosition()
  18.       InformationTooltip:AddLine(zo_strformat("Position of my pin is: <<1>>•<<2>>", ("%05.02f"):format(locX*100), ("%05.02f"):format(locY*100)))
  19.    end,
  20.    tooltip = InformationTooltip,
  21. }
  22.  
  23. --click handlers
  24. local LMB_handler = {
  25.    {
  26.       name = "LMB action 1",
  27.       callback = function(pin) d("LMB action 1!") end,
  28.       show = function(pin) return pin:GetControl():GetHeight() == 30 end,
  29.    },
  30.    {
  31.       name = "LMB action 2",
  32.       callback = function(pin) d("LMB action 2!") end,
  33.       show = function(pin) return pin:GetControl():GetHeight() == 20 end,
  34.    },
  35. }
  36. local RMB_handler = {
  37.    {
  38.       name = "RMB action",
  39.       callback = function(pin) d("RMB action!") end,
  40.    },
  41. }
  42.  
  43. --add callback function
  44. local pinTypeAddCallback = function(pinManager)
  45.    --do not create pins if your pinType is not enabled
  46.    if not LMP:IsEnabled(pinType1) then return end
  47.    --do not create pins on world, alliance and cosmic maps
  48.    if (GetMapType() > MAPTYPE_ZONE) then return end
  49.  
  50.    local zone, subzone = LMP:GetZoneAndSubzone()
  51.    local pins = VendSaved.data[zone .. "/" .. subzone]                  ------ NIL ingame I dont understand :S
  52.    --return if no data for the current map
  53.  
  54.    d(pins)                                                              
  55.    if not pins then return end
  56.  
  57.    for _, pinInfo in ipairs(pins) do
  58.       LMP:CreatePin(pinType1, pinInfo, pinInfo.x, pinInfo.y)
  59.    end
  60.    
  61.  
  62. end
  63.  
  64. --resize callback function (usually just nil)
  65. local pinTypeOnResizeCallback = function(pinManager, mapWidth, mapHeight)
  66.    local visibleWidth, visibleHeight = ZO_WorldMapScroll:GetDimensions()
  67.    local currentZoom = mapWidth / visibleWidth
  68.  
  69.    if currentZoom < 1.5 then
  70.       LMP:SetLayoutData(pinType1, pinLayoutData)
  71.       LMP:RefreshPins(pinType1)
  72.    else
  73.       LMP:SetLayoutData(pinType1, {})
  74.       LMP:RefreshPins(pinType1)
  75.    end
  76. end
  77.  
  78. function Log(...)  
  79.     local data = {}
  80.     local dataStr = ""
  81.     local sv
  82.     if VendSaved == nil then
  83.         d("Attempted to log unknown type to the database")
  84.         return
  85.     else
  86.         sv = VendSaved.data
  87.     end
  88.     for i = 1, select("#", ...) do
  89.         local value = select(i, ...)
  90.         data[i] = value
  91.         dataStr = dataStr .. tostring(value)
  92.     end
  93.     d("Logged data: " .. dataStr)
  94.     if #sv == 0 then
  95.         sv[1] = data
  96.     else
  97.         sv[#sv+1] = data
  98.     end
  99. end
  100.  
  101. local function OnLoad(eventCode, name)
  102.    if name ~= "Vendors" then return end
  103.  
  104.    --saved variables
  105.    VendSaved = ZO_SavedVars:New("Vendors_SavedVariables", 1, nil, { filters = true, data = {}, })
  106.    --initialize map pins
  107.    pinTypeId1 = LMP:AddPinType(pinType1, pinTypeAddCallback, pinTypeOnResizeCallback, pinLayoutData, pinTooltipCreator)
  108.    pinTypeId2 = LMP:AddPinType(pinType2, function() d("refresh") end)
  109.    --set click handlers
  110.    LMP:SetClickHandlers(pinTypeId1, LMB_handler, RMB_handler)
  111.    --add pin filter to the world map
  112.    LMP:AddPinFilter(pinTypeId1, "Vendor's pins", false, VendSaved, "filters")
  113.    LMP:AddPinFilter(pinTypeId2, nil, nil, VendSaved)
  114.  
  115.    EVENT_MANAGER:UnregisterForEvent("Vendors_OnLoad", EVENT_ADD_ON_LOADED)
  116. end
  117.  
  118. EVENT_MANAGER:RegisterForEvent("Vendors_OnLoad", EVENT_ADD_ON_LOADED, OnLoad)
  119. EVENT_MANAGER:RegisterForEvent("Vendors", EVENT_RETICLE_TARGET_CHANGED, TargetChanged)         ----   Seperate File VendorsScanner.lua

SAVED VARS SAMPLE for above reference
Lua Code:
  1. Vendors_SavedVariables =
  2. {
  3.     ["Default"] =
  4.     {
  5.         [""] =
  6.         {
  7.             ["Skoodat"] =
  8.             {
  9.                 ["data"] =
  10.                 {
  11.                     [1] =
  12.                     {
  13.                         [1] = [[Yazhin-dar]],
  14.                         [2] = [[Pack Merchant]],
  15.                         [3] = [[reapersmarch/rawlkha_base]],
  16.                         [4] = 0.506472,
  17.                         [5] = 0.476661,
  18.                     },
  19.                     [2] =
  20.                     {
  21.                         [1] = [[Edhelvir]],
  22.                         [2] = [[Leatherworker]],
  23.                         [3] = [[reapersmarch/rawlkha_base]],
  24.                         [4] = 0.507405,
  25.                         [5] = 0.524607,
  26.                     },
  27.                     [3] =
  28.                     {
  29.                         [1] = [[Riba]],
  30.                         [2] = [[Armorer]],
  31.                         [3] = [[reapersmarch/rawlkha_base]],
  32.                         [4] = 0.518817,
  33.                         [5] = 0.536067,
  34.                     },
  35.                     [4] =
  36.                     {
  37.                         [1] = [[Alandil]],
  38.                         [2] = [[Alchemist]],
  39.                         [3] = [[reapersmarch/rawlkha_base]],
  40.                         [4] = 0.561045,
  41.                         [5] = 0.531067,
  42.                     },
  43.                     [5] =
  44.                     {
  45.                         [1] = [[Ciindewal]],
  46.                         [2] = [[Tailor]],
  47.                         [3] = [[reapersmarch/rawlkha_base]],
  48.                         [4] = 0.576883,
  49.                         [5] = 0.482738,
  50.                     },
  51.                 ["filters"] = true,
  52.                 ["version"] = 1,
  53.             },
  54.         },
  55.     },
  56. }

Scanner.lua figured i would post this too but it works perfect lol logging part of my addon....
Lua Code:
  1. local LMP = LibStub("LibMapPins-1.0")
  2.  
  3. function TargetChanged(Event, Unit)
  4.     local Name = GetUnitName("reticleover")                                                             -- Get The Reticle Target
  5.     local Blank = (Name == "" or Name == " ")                                                           -- Ignore Blank Targets
  6.     local Caption = GetUnitCaption("reticleover")                                                       -- Get Unit Caption "BlackSmith" "Bank"
  7.     local CBlank = (Caption == "" or Caption == " ")
  8.     local Reaction = GetUnitReaction('reticleover')                                                     -- Get Unit Reaction For Checking Purposes 3 == NPC
  9.     local TargetX, TargetY, TargetH = GetMapPlayerPosition('reticleover')
  10.     local SelfX, SelfY, SelfH = GetMapPlayerPosition('player')
  11.     local zone, subzone = LMP:GetZoneAndSubzone()
  12.     local Floor, Floors = GetMapFloorInfo()
  13.     ---------------------------------------------------------------------------------------------------------------------------------------------------
  14.     --if VendSaved.Toggle then
  15.         if not IsCritter(Name) and not Blank then                                                           -- Check For Critters
  16.             if DoesUnitExist('reticleover') then                                                            -- Make Sure Thier Is A Target
  17.                 if not IsUnitPlayer('reticleover') then                                                     -- Make Sure Unit Isnt A Player
  18.                     if Reaction == UNIT_REACTION_INTERACT or UNIT_REACTION_NPC_ALLY then                    -- Get Unit Reaction For Checking Purposes 5 == NPC
  19.                         if Caption == nil then return end
  20.                         if Caption and not CBlank then
  21.                         ---------------------------------------------------------------------------------------------------------------------------------------------------
  22.                         for i = 1, #VendSaved.data do
  23.                             local item = VendSaved.data[i]
  24.                             if item[1] == (Name) and item[3] == zone.. "/" ..subzone then                             -- MapSubzone For Dubble NPCs Like Boatswains
  25.                                 d("|c00FF00Found NPC|r |cFFFFFF" ..Name.. " " ..Caption.. "|r |c00FF00Of|r |cFFFFFF" .. zone .. "/" .. subzone .. "|r |c00FF00In The Saved Var File NOT ADDING|r")
  26.                                 return
  27.                             end
  28.                         end
  29.                         ---------------------------------------------------------------------------------------------------------------------------------------------------
  30.                         Log(Name, Caption, zone.. "/" ..subzone, TargetX, TargetY)--, Floor) --GetMapFloorInfo() Is Massively Buged ATM Upon Reload In EldenRoot Floor Changes Its Number Will Test More Later
  31.                         --if VendSaved.VendorOutput then
  32.                             --d("New Vendor, Added " ..Caption.." "..Name.." in "..MapSubzone.." at "..TargetX.." "..TargetY.." To The Vendors Database!")
  33.                             --ZO_Alert(1, 1, "New Vendor, Added " ..Caption.." "..Name.." in "..MapSubzone.." at "..TargetX.." "..TargetY.." To The Vendors Database!")
  34.                             ZO_ChatWindowTemplate1Buffer:AddMessage("|c00FF00New Vendor Added:|r " ..Caption.." "..Name.." |c00FF00in|r "..zone .. "/" .. subzone.." |c00FF00at|r "..TargetX.." "..TargetY.."|c00FF00.|r")
  35.                         --end
  36.                         --------------------------------------------------------------------------------------------------------------------------------------------------
  37.                         end
  38.                     end
  39.                 end
  40.             end
  41.         end
  42.     --end
  43. end
  44.  
  45. function IsCritter(Name)                                                                            -- Function To Check If Critter
  46.     if (GetUnitLevel("reticleover") ~= 1) then return false end                                     -- Critters Are Always Level 1
  47.     local Critters = {                                                                              -- The List Of Critters
  48.         "Butterfly", "Lizard", "Rat", "Snake", "Pony Guar", "Frog", "Squirrel", "Rabbit", "Deer", "Cat", "Pig", "Sheep", "Antelope", "Wasp", "Monkey", "Fleshflies", "Centipede", "Chicken", "Torchbug", "Spider", "Scorpion", "Goat", "Scrib", "Scuttler",
  49.     }
  50.     for I = 1, #Critters do                                                                         -- Is The Target A Critter?
  51.         if (Name == Critters[i]) then return true end
  52.     end
  53.     return false                                                                                    -- Otherwise False
  54. end
  Reply With Quote
06/07/14, 02:33 PM   #2
Garkin
 
Garkin's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 832
In your saved variabled does not exist key VendSaved.data[zone .. "/" .. subzone]. In your database is VendSaved.data[index] and each subtable has defined key [3] with a map name.

If you want to use loop as it is now in your add callback, VendSaved.data should look like this (key names are up to you):
lua Code:
  1. VendSaved.data = {
  2.    [[reapersmarch/rawlkha_base]] = {
  3.       [1] = {
  4.           ["name"] = [[Yazhin-dar]],
  5.           ["caption"] = [[Pack Merchant]],
  6.           ["x"] = 0.506472,
  7.           ["y"] = 0.476661,
  8.       },
  9.       [2] = {
  10.           ["name"] = [[Edhelvir]],
  11.           ["caption"] = [[Leatherworker]],
  12.           ["x"] = 0.507405,
  13.           ["y"] = 0.524607,
  14.       },
  15.       [3] = {
  16.           ["name"] = [[Riba]],
  17.           ["caption"] = [[Armorer]],
  18.           ["x"] = 0.518817,
  19.           ["y"] = 0.536067,
  20.       },
  21.    },
  22. }

If you want to use your current format of saved variables, you need to change add callback this way:
Lua Code:
  1. local function pinTypeAddCallback()
  2.    if not LMP:IsEnabled(pinType1) then return end
  3.    if (GetMapType() > MAPTYPE_ZONE) then return end
  4.      
  5.     local mapName = LMP:GetZoneAndSubzone(true) --it will give you "zone/subzone", so you do not need to connect strings
  6.      
  7.    for _, pinInfo in ipairs(VendSaved.data) do --or use the same loop as you have in Scanner.lua - for i = 1, #VendSaved.data do
  8.       if pinInfo[3] == mapName then
  9.          LMP:CreatePin(pinType1, pinInfo, pinInfo[4], pinInfo[5])
  10.       end
  11.    end
  12.      
  13. end
By the way your format of data is inefficient, as you have to go through whole database instead of just subtables for the current map.

Last edited by Garkin : 06/07/14 at 02:48 PM.
  Reply With Quote
06/08/14, 01:54 PM   #3
SkOODaT
 
SkOODaT's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 58
Garkin helped me tremendously with all this and more in messages thank you
  Reply With Quote

ESOUI » Developer Discussions » General Authoring Discussion » Need help with LibMapPins-1.0


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off