Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Special Thanks to /u/AlfertAfterLife from wowaddons subreddit for the advice he provided
- local AddonName = ...
- local UPDATEPERIOD, elapsed = 1,0
- local display
- local string_format = string.format
- local name_obj = "Knowledge Level"
- local RAID_CLASS_COLORS = RAID_CLASS_COLORS
- local class, classFileName, classIndex = UnitClass("player")
- local color = RAID_CLASS_COLORS[classFileName]
- local colorBetter
- local mydbname
- local bettertip = LibStub('LibQTip-1.0')
- local ldb = LibStub:GetLibrary("LibDataBroker-1.1")
- -- Color Text with the Class Color
- local colorByClass = {
- [1]= "|cffc79c6e", --war
- [2]= "|cfff58cba", --pal
- [3]= "|cffabd473", --hunt
- [4]= "|cfffff569", --rogue
- [5]= "|cffffffff", --priest
- [6]= "|cffc41f3b", --dk
- [7]= "|cff0070de", --sham
- [8]= "|cff69ccf0", --mage
- [9]= "|cff9482c9", --demo
- [10]= "|cff00ff96", --monk
- [11]= "|cffff7d0a", --druid
- [12] = "|cffa330c9", --DH
- [13] = "|cffff0000", --color for None/Max
- }
- local colorBetter = colorByClass[classIndex]
- local colorBetterAmount = colorByClass[13]
- -- Get amount Of Artifact Knowledge Research learned
- function CurrencyText()
- local name, amount= GetCurrencyInfo("currency:1171");
- return amount
- end
- -- Get player Info
- function PlayerInfoText()
- local playerName, playerRealm = UnitName("player"), GetRealmName()
- return playerName, playerRealm
- end
- -- Check if DB exist, if not, create a new one as a table and then store the data inside.
- local CreateDB = CreateFrame("Frame")
- CreateDB:RegisterEvent("PLAYER_ENTERING_WORLD")
- CreateDB:SetScript("OnEvent",function(...)
- amount = CurrencyText();
- playerName, playerRealm = PlayerInfoText();
- if not SAKL_DB then
- SAKL_DB = {}
- end
- if not SAKL_DB[playerRealm] then
- SAKL_DB[playerRealm] = { [playerName] = {
- ["class"] = classIndex;
- ["amount"] = colorBetter.. amount;
- ["level"] = UnitLevel("player");
- ["name"] = colorBetter.. playerName;
- };
- };
- end
- SAKL_DB[playerRealm][playerName] = {
- ["class"] = classIndex;
- ["amount"] = colorBetter.. amount;
- ["level"] = UnitLevel("player");
- ["name"] = colorBetter.. playerName;
- };
- end)
- -- This is my test part, when I try to access different table's value and print them to see if I'm wrong or not
- local AmountFrame = CreateFrame("Frame")
- AmountFrame:RegisterEvent("PLAYER_ENTERING_WORLD")
- AmountFrame:SetScript("OnEvent",function(...)
- mydbname = SAKL_DB;
- for k,v in next,mydbname[playerRealm],nil do
- local db_name = k
- for k,v in pairs(mydbname[playerRealm][db_name]) do
- amount_db = mydbname[playerRealm][db_name]["amount"]
- color_db_name = mydbname[playerRealm][db_name]["name"]
- end
- print (color_db_name.. amount_db)
- end
- end)
- -- Creating new_obj
- local dataobj = ldb:NewDataObject(name_obj, {
- type = "data source",
- icon = "Interface\\Icons\\Inv_scroll_11.blp"
- })
- -- print(amount) If I print amount here, it return nil hmm
- -- Here is the main display on an LDB display, only for the active char
- local frame_ms = CreateFrame("Frame","_LDB")
- frame_ms:SetScript("OnUpdate", function(self, elap)
- elapsed = elapsed + elap
- if elapsed < UPDATEPERIOD then return end
- elapsed = 0
- amount = CurrencyText();
- if amount == 0 then
- dataobj.text = string_format(colorBetterAmount.. "None")
- return
- end
- if amount == 25 then
- elapsed = 0
- dataobj.text = string_format(colorBetterAmount.. "25 (Max)")
- return
- end
- if amount ~= 0 and amount ~= 25 then
- dataobj.text = string_format("%s", colorBetter.. amount)
- return
- end
- end
- )
- -- Create and show tooltip with all char in the playerRealm
- function dataobj:OnEnter()
- if ClassIndex == 0 then
- return
- end
- if not mydbname then
- return
- end
- tooltip = bettertip:Acquire(name_obj, 2, "LEFT", "RIGHT")
- self.tooltip = tooltip
- tooltip:AddHeader("|cffffd700On Server : ".. playerRealm, "|cffffd700 - Level")
- for k,v in next,mydbname[playerRealm],nil do
- local db_name = k
- for k,v in pairs(mydbname[playerRealm][db_name]) do
- amount_db = mydbname[playerRealm][db_name]["amount"]
- color_db_name = mydbname[playerRealm][db_name]["name"]
- end
- tooltip:AddLine(color_db_name, amount_db)
- end
- tooltip:SmartAnchorTo(self)
- tooltip:Show()
- end
- -- Release tooltip when leaving the obj
- function dataobj:OnLeave()
- bettertip:Release(tooltip)
- tooltip = nil
- end
- -- Updating the database with the last amount
- local UpdateDB = CreateFrame("Frame")
- UpdateDB:RegisterEvent("PLAYER_LOGOUT")
- UpdateDB:SetScript("OnEvent",function(...)
- amount = CurrencyText();
- playerName, playerRealm = PlayerInfoText();
- SAKL_DB[playerRealm][playerName] = {
- ["class"] = classIndex;
- ["amount"] = colorBetter.. amount;
- ["level"] = UnitLevel("player");
- ["name"] = colorBetter.. playerName;
- };
- end)
Add Comment
Please, Sign In to add comment