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:
local LMP = LibStub("LibMapPins-1.0")
local pinType1 = "My_unique_name"
local pinType2 = "My_even_more_unique_name"
local pinTypeId1, pinTypeId2
--sample layout
local pinLayoutData = {
level = 50,
texture = "/esoui/art/mappins/compassvendor.dds",
size = 30,
}
--tooltip creator
local pinTooltipCreator = {
creator = function(pin)
local locX, locY = pin:GetNormalizedPosition()
InformationTooltip:AddLine(zo_strformat("Position of my pin is: <<1>>•<<2>>", ("%05.02f"):format(locX*100), ("%05.02f"):format(locY*100)))
end,
tooltip = InformationTooltip,
}
--click handlers
local LMB_handler = {
{
name = "LMB action 1",
callback = function(pin) d("LMB action 1!") end,
show = function(pin) return pin:GetControl():GetHeight() == 30 end,
},
{
name = "LMB action 2",
callback = function(pin) d("LMB action 2!") end,
show = function(pin) return pin:GetControl():GetHeight() == 20 end,
},
}
local RMB_handler = {
{
name = "RMB action",
callback = function(pin) d("RMB action!") end,
},
}
--add callback function
local pinTypeAddCallback = function(pinManager)
--do not create pins if your pinType is not enabled
if not LMP:IsEnabled(pinType1) then return end
--do not create pins on world, alliance and cosmic maps
if (GetMapType() > MAPTYPE_ZONE) then return end
local zone, subzone = LMP:GetZoneAndSubzone()
local pins = VendSaved.data[zone .. "/" .. subzone] ------ NIL ingame I dont understand :S
--return if no data for the current map
d(pins)
if not pins then return end
for _, pinInfo in ipairs(pins) do
LMP:CreatePin(pinType1, pinInfo, pinInfo.x, pinInfo.y)
end
end
--resize callback function (usually just nil)
local pinTypeOnResizeCallback = function(pinManager, mapWidth, mapHeight)
local visibleWidth, visibleHeight = ZO_WorldMapScroll:GetDimensions()
local currentZoom = mapWidth / visibleWidth
if currentZoom < 1.5 then
LMP:SetLayoutData(pinType1, pinLayoutData)
LMP:RefreshPins(pinType1)
else
LMP:SetLayoutData(pinType1, {})
LMP:RefreshPins(pinType1)
end
end
function Log(...)
local data = {}
local dataStr = ""
local sv
if VendSaved == nil then
d("Attempted to log unknown type to the database")
return
else
sv = VendSaved.data
end
for i = 1, select("#", ...) do
local value = select(i, ...)
data[i] = value
dataStr = dataStr .. tostring(value)
end
d("Logged data: " .. dataStr)
if #sv == 0 then
sv[1] = data
else
sv[#sv+1] = data
end
end
local function OnLoad(eventCode, name)
if name ~= "Vendors" then return end
--saved variables
VendSaved = ZO_SavedVars:New("Vendors_SavedVariables", 1, nil, { filters = true, data = {}, })
--initialize map pins
pinTypeId1 = LMP:AddPinType(pinType1, pinTypeAddCallback, pinTypeOnResizeCallback, pinLayoutData, pinTooltipCreator)
pinTypeId2 = LMP:AddPinType(pinType2, function() d("refresh") end)
--set click handlers
LMP:SetClickHandlers(pinTypeId1, LMB_handler, RMB_handler)
--add pin filter to the world map
LMP:AddPinFilter(pinTypeId1, "Vendor's pins", false, VendSaved, "filters")
LMP:AddPinFilter(pinTypeId2, nil, nil, VendSaved)
EVENT_MANAGER:UnregisterForEvent("Vendors_OnLoad", EVENT_ADD_ON_LOADED)
end
EVENT_MANAGER:RegisterForEvent("Vendors_OnLoad", EVENT_ADD_ON_LOADED, OnLoad)
EVENT_MANAGER:RegisterForEvent("Vendors", EVENT_RETICLE_TARGET_CHANGED, TargetChanged) ---- Seperate File VendorsScanner.lua
SAVED VARS SAMPLE for above reference
Lua Code:
Vendors_SavedVariables =
{
["Default"] =
{
[""] =
{
["Skoodat"] =
{
["data"] =
{
[1] =
{
[1] = [[Yazhin-dar]],
[2] = [[Pack Merchant]],
[3] = [[reapersmarch/rawlkha_base]],
[4] = 0.506472,
[5] = 0.476661,
},
[2] =
{
[1] = [[Edhelvir]],
[2] = [[Leatherworker]],
[3] = [[reapersmarch/rawlkha_base]],
[4] = 0.507405,
[5] = 0.524607,
},
[3] =
{
[1] = [[Riba]],
[2] = [[Armorer]],
[3] = [[reapersmarch/rawlkha_base]],
[4] = 0.518817,
[5] = 0.536067,
},
[4] =
{
[1] = [[Alandil]],
[2] = [[Alchemist]],
[3] = [[reapersmarch/rawlkha_base]],
[4] = 0.561045,
[5] = 0.531067,
},
[5] =
{
[1] = [[Ciindewal]],
[2] = [[Tailor]],
[3] = [[reapersmarch/rawlkha_base]],
[4] = 0.576883,
[5] = 0.482738,
},
["filters"] = true,
["version"] = 1,
},
},
},
}
Scanner.lua figured i would post this too but it works perfect lol logging part of my addon....
Lua Code:
local LMP = LibStub("LibMapPins-1.0")
function TargetChanged(Event, Unit)
local Name = GetUnitName("reticleover") -- Get The Reticle Target
local Blank = (Name == "" or Name == " ") -- Ignore Blank Targets
local Caption = GetUnitCaption("reticleover") -- Get Unit Caption "BlackSmith" "Bank"
local CBlank = (Caption == "" or Caption == " ")
local Reaction = GetUnitReaction('reticleover') -- Get Unit Reaction For Checking Purposes 3 == NPC
local TargetX, TargetY, TargetH = GetMapPlayerPosition('reticleover')
local SelfX, SelfY, SelfH = GetMapPlayerPosition('player')
local zone, subzone = LMP:GetZoneAndSubzone()
local Floor, Floors = GetMapFloorInfo()
---------------------------------------------------------------------------------------------------------------------------------------------------
--if VendSaved.Toggle then
if not IsCritter(Name) and not Blank then -- Check For Critters
if DoesUnitExist('reticleover') then -- Make Sure Thier Is A Target
if not IsUnitPlayer('reticleover') then -- Make Sure Unit Isnt A Player
if Reaction == UNIT_REACTION_INTERACT or UNIT_REACTION_NPC_ALLY then -- Get Unit Reaction For Checking Purposes 5 == NPC
if Caption == nil then return end
if Caption and not CBlank then
---------------------------------------------------------------------------------------------------------------------------------------------------
for i = 1, #VendSaved.data do
local item = VendSaved.data[i]
if item[1] == (Name) and item[3] == zone.. "/" ..subzone then -- MapSubzone For Dubble NPCs Like Boatswains
d("|c00FF00Found NPC|r |cFFFFFF" ..Name.. " " ..Caption.. "|r |c00FF00Of|r |cFFFFFF" .. zone .. "/" .. subzone .. "|r |c00FF00In The Saved Var File NOT ADDING|r")
return
end
end
---------------------------------------------------------------------------------------------------------------------------------------------------
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
--if VendSaved.VendorOutput then
--d("New Vendor, Added " ..Caption.." "..Name.." in "..MapSubzone.." at "..TargetX.." "..TargetY.." To The Vendors Database!")
--ZO_Alert(1, 1, "New Vendor, Added " ..Caption.." "..Name.." in "..MapSubzone.." at "..TargetX.." "..TargetY.." To The Vendors Database!")
ZO_ChatWindowTemplate1Buffer:AddMessage("|c00FF00New Vendor Added:|r " ..Caption.." "..Name.." |c00FF00in|r "..zone .. "/" .. subzone.." |c00FF00at|r "..TargetX.." "..TargetY.."|c00FF00.|r")
--end
--------------------------------------------------------------------------------------------------------------------------------------------------
end
end
end
end
end
--end
end
function IsCritter(Name) -- Function To Check If Critter
if (GetUnitLevel("reticleover") ~= 1) then return false end -- Critters Are Always Level 1
local Critters = { -- The List Of Critters
"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",
}
for I = 1, #Critters do -- Is The Target A Critter?
if (Name == Critters[i]) then return true end
end
return false -- Otherwise False
end