Advertisement
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 UPDATEPERIOD, elapsed = 1,0
- local string_format = string.format
- local name_obj = "Knowledge Level"
- local class, classFileName, classIndex = UnitClass("player")
- local name
- local amount
- local mydbname
- local playerName
- local playerRealm
- --Lib
- 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()
- name, amount= GetCurrencyInfo("currency:1171");
- return amount
- end
- -- Get player Info
- function PlayerInfoText()
- playerName, playerRealm = UnitName("player"), GetRealmName()
- return playerName, playerRealm
- end
- -- Create DB if doesn't exist, Fill it with value depending of Player Level/Amount of AK and Realm
- function Init_SAKL_DB()
- amount = CurrencyText();
- playerName, playerRealm = PlayerInfoText();
- if not SAKL_DB then
- SAKL_DB = {}
- elseif not SAKL_DB[playerRealm] then
- SAKL_DB[playerRealm] = { [playerName] = {
- ["class"] = classIndex;
- ["amount"] = colorBetter.. amount;
- ["level"] = UnitLevel("player");
- ["name"] = colorBetter.. playerName;
- };
- };
- elseif UnitLevel("player") < 110 then
- SAKL_DB[playerRealm][playerName] = {
- ["class"] = classIndex;
- ["amount"] = colorBetter.. "----";
- ["level"] = UnitLevel("player");
- ["name"] = colorBetter.. playerName.. " (Not 110)";
- };
- elseif amount == 25 then
- SAKL_DB[playerRealm][playerName] = {
- ["class"] = classIndex;
- ["amount"] = colorBetter.. "25 (Max)";
- ["level"] = UnitLevel("player");
- ["name"] = colorBetter.. playerName;
- };
- elseif amount == 0 then
- SAKL_DB[playerRealm][playerName] = {
- ["class"] = classIndex;
- ["amount"] = colorBetter.. "0";
- ["level"] = UnitLevel("player");
- ["name"] = colorBetter.. playerName;
- };
- else
- SAKL_DB[playerRealm][playerName] = {
- ["class"] = classIndex;
- ["amount"] = colorBetter.. amount;
- ["level"] = UnitLevel("player");
- ["name"] = colorBetter.. playerName;
- };
- end
- return SAKL_DB
- 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(...)
- mydbname = Init_SAKL_DB();
- 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
- -- Creating new_obj
- local dataobj = ldb:NewDataObject(name_obj, {
- type = "data source",
- icon = "Interface\\Icons\\Inv_scroll_11.blp"
- })
- -- 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)
- amount = CurrencyText();
- elapsed = elapsed + elap
- if elapsed < UPDATEPERIOD then return end
- elapsed = 0
- if UnitLevel("player") < 110 then
- dataobj.text = string_format("|cffffd700AK Level : ".. colorBetter.. "----")
- elseif amount == 0 then
- dataobj.text = string_format("|cffffd700AK Level : ".. colorBetter.. "Zero")
- elseif amount == 25 then
- dataobj.text = string_format("|cffffd700AK Level : ".. colorBetter.. "25 (Max)")
- else
- dataobj.text = string_format("|cffffd700AK Level : ".. colorBetter.. amount)
- end
- end)
- -- Create and show tooltip with all char in the playerRealm
- function dataobj:OnEnter()
- if ClassIndex == 0 then return end
- playerName, playerRealm = PlayerInfoText();
- amount = CurrencyText();
- --mydbname = Init_SAKL_DB();
- tooltip = bettertip:Acquire(name_obj, 2, "LEFT", "RIGHT")
- self.tooltip = tooltip
- tooltip:AddHeader("|cffffd700Server : ".. 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
- -- Security Update / Updating the database with the last amount even if the player haven't displayed he tooltip
- local UpdateDB = CreateFrame("Frame")
- UpdateDB:RegisterEvent("PLAYER_LOGOUT")
- UpdateDB:SetScript("OnEvent",function(...)
- SAKL_DB = Init_SAKL_DB();
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement