Originally Posted by
Panacia
Originally Posted by
Kurkon
Haha, that's the thread I started a few months ago before taking a break.
Unfortunately it doesn't seem to work. Doing everything the way it's listed doesn't show anything in game. The add on shows up in menus and such, but doesn't actually show any information.
I tried to fix up only the bare essentials of Choonster's code
Although probably Treeston, or someone else, will actually write up something way cleaner than that
Some notes about the original code:- He could also do it without using Ace3
- The event should've been UNIT_INVENTORY_CHANGED instead of UNIT_INVENTORY_UPDATE
- The original dataobj table reference was disposed of, because it was reassigned to LibStub("AceAddon-3.0").NewAddon, and then OnTooltipShow was added to that table instead. That's why it showed up in Data Display addons, while not doing anything
- There is no embeding of LibDataBroker in the .toc file. If this code actually works, then some other addon which embeds LibDataBroker, was loaded before your code
Again, probably someone else will come in, and write up something more .. cleaner and/or provide you a zip/addon with LibDataBroker embeded
Code:
local ILVL_FORMAT = "%d(E)/%d(T)"
local PLAYER_NAME;
local SERVER_NAME;
local addon, dataobj = ...
dataobj.type = "data source"
dataobj.text = ""
LibStub("LibDataBroker-1.1"):NewDataObject(addon, dataobj)
local AIL = LibStub("AceAddon-3.0"):NewAddon(addon, "AceEvent-3.0")
function AIL:OnInitialize()
self.db = LibStub("AceDB-3.0"):New(addon .. "DB")
end
function AIL:OnEnable()
self:RegisterEvent("PLAYER_ENTERING_WORLD")
self:RegisterEvent("UNIT_INVENTORY_CHANGED", "Update")
end
function AIL:PLAYER_ENTERING_WORLD(event)
PLAYER_NAME = UnitName("player")
SERVER_NAME = GetRealmName()
self:UnregisterEvent(event)
self:Update(nil, "player")
end
function AIL:Update(event, unit)
if unit ~= "player" then return end
local ilvl, ilvlEquipped = GetAverageItemLevel()
self.db.realm[PLAYER_NAME] = self.db.realm[PLAYER_NAME] or {}
self.db.realm[PLAYER_NAME].ilvl = ilvl
self.db.realm[PLAYER_NAME].ilvlEq = ilvlEquipped
dataobj.text = ILVL_FORMAT:format(ilvlEquipped, ilvl)
end
function dataobj:OnTooltipShow()
self:AddLine(SERVER_NAME)
for name, data in pairs(AIL.db.realm) do
self:AddDoubleLine(name, ILVL_FORMAT:format(data.ilvlEq, data.ilvl), 1, 1, 1, 1, 1, 1)
end
end