absolute93

Ligne.lua

Jan 23rd, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.80 KB | None | 0 0
  1. -- Special Thanks to /u/AlfertAfterLife from wowaddons subreddit for the advice he provided
  2.  
  3. local AddonName = ...
  4. local UPDATEPERIOD, elapsed = 1,0
  5. local display
  6. local string_format = string.format
  7. local name_obj = "Knowledge Level"
  8. local RAID_CLASS_COLORS = RAID_CLASS_COLORS
  9. local class, classFileName, classIndex = UnitClass("player")
  10. local color = RAID_CLASS_COLORS[classFileName]
  11. local colorBetter
  12. local mydbname
  13.  
  14. local bettertip = LibStub('LibQTip-1.0')
  15. local ldb = LibStub:GetLibrary("LibDataBroker-1.1")
  16.  
  17.  
  18. -- Color Text with the Class Color
  19. local colorByClass = {
  20.     [1]= "|cffc79c6e",  --war
  21.     [2]= "|cfff58cba",  --pal
  22.     [3]= "|cffabd473",  --hunt
  23.     [4]= "|cfffff569",  --rogue
  24.     [5]= "|cffffffff",  --priest
  25.     [6]= "|cffc41f3b",  --dk
  26.     [7]= "|cff0070de",  --sham
  27.     [8]= "|cff69ccf0",  --mage
  28.     [9]= "|cff9482c9",  --demo
  29.     [10]= "|cff00ff96", --monk
  30.     [11]= "|cffff7d0a", --druid
  31.     [12] = "|cffa330c9",    --DH
  32.     [13] = "|cffff0000", --color for None/Max
  33.    
  34. }  
  35. local colorBetter = colorByClass[classIndex]
  36. local colorBetterAmount = colorByClass[13]
  37.  
  38.  
  39. -- Get amount Of Artifact Knowledge Research learned
  40. function CurrencyText()
  41.     local name, amount= GetCurrencyInfo("currency:1171");
  42.     return amount
  43. end
  44.  
  45.  
  46. -- Get player Info
  47. function PlayerInfoText()
  48.     local playerName, playerRealm = UnitName("player"), GetRealmName()
  49.     return playerName, playerRealm
  50. end
  51.  
  52.  
  53. -- Check if DB exist, if not, create a new one as a table and then store the data inside.
  54. local CreateDB = CreateFrame("Frame")
  55. CreateDB:RegisterEvent("PLAYER_ENTERING_WORLD")
  56. CreateDB:SetScript("OnEvent",function(...)
  57.     amount = CurrencyText();
  58.     playerName, playerRealm = PlayerInfoText();
  59.    
  60.     if not SAKL_DB then
  61.     SAKL_DB = {}
  62.     end
  63.     if not SAKL_DB[playerRealm] then
  64.         SAKL_DB[playerRealm] = { [playerName] = {
  65.                                     ["class"] = classIndex;
  66.                                     ["amount"] = colorBetter.. amount;
  67.                                     ["level"] = UnitLevel("player");
  68.                                     ["name"] = colorBetter.. playerName;
  69.                                 };
  70.         };
  71.     end
  72.    
  73.     SAKL_DB[playerRealm][playerName] = {
  74.     ["class"] = classIndex;
  75.     ["amount"] = colorBetter.. amount;
  76.     ["level"] = UnitLevel("player");
  77.     ["name"] = colorBetter.. playerName;
  78.     };
  79.        
  80. end)
  81.  
  82. -- 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
  83. local AmountFrame = CreateFrame("Frame")
  84. AmountFrame:RegisterEvent("PLAYER_ENTERING_WORLD")
  85. AmountFrame:SetScript("OnEvent",function(...)
  86.    
  87.     mydbname = SAKL_DB;
  88.     for k,v in next,mydbname[playerRealm],nil do
  89.     local db_name = k
  90.         for k,v in pairs(mydbname[playerRealm][db_name]) do
  91.             amount_db = mydbname[playerRealm][db_name]["amount"]
  92.             color_db_name = mydbname[playerRealm][db_name]["name"]
  93.         end
  94.     print (color_db_name.. amount_db)
  95.     end
  96.    
  97. end)
  98.  
  99.  
  100. -- Creating new_obj
  101. local dataobj = ldb:NewDataObject(name_obj, {
  102.     type = "data source",
  103.     icon = "Interface\\Icons\\Inv_scroll_11.blp"
  104.    
  105. })
  106.  
  107.  
  108. -- print(amount) If I print amount here, it return nil hmm
  109.  
  110.  
  111. -- Here is the main display on an LDB display, only for the active char
  112. local frame_ms = CreateFrame("Frame","_LDB")
  113. frame_ms:SetScript("OnUpdate", function(self, elap)
  114.     elapsed = elapsed + elap
  115.     if elapsed < UPDATEPERIOD then return end
  116.     elapsed = 0
  117.         amount = CurrencyText();
  118.         if amount == 0 then
  119.         dataobj.text = string_format(colorBetterAmount.. "None")
  120.         return
  121.         end
  122.         if amount == 25 then
  123.         elapsed = 0
  124.         dataobj.text = string_format(colorBetterAmount.. "25 (Max)")
  125.         return
  126.         end
  127.         if amount ~= 0 and amount ~= 25 then
  128.         dataobj.text = string_format("%s", colorBetter.. amount)
  129.         return
  130.         end
  131.    
  132. end
  133. )
  134.  
  135. -- Create and show tooltip with all char in the playerRealm
  136. function dataobj:OnEnter()
  137.     if ClassIndex == 0 then
  138.     return
  139.     end
  140.     if not mydbname then
  141.     return
  142.     end
  143.     tooltip = bettertip:Acquire(name_obj, 2, "LEFT", "RIGHT")
  144.     self.tooltip = tooltip
  145.     tooltip:AddHeader("|cffffd700On Server : ".. playerRealm, "|cffffd700 - Level")
  146.    
  147.     for k,v in next,mydbname[playerRealm],nil do
  148.     local db_name = k
  149.         for k,v in pairs(mydbname[playerRealm][db_name]) do
  150.             amount_db = mydbname[playerRealm][db_name]["amount"]
  151.             color_db_name = mydbname[playerRealm][db_name]["name"]
  152.         end
  153.    
  154.     tooltip:AddLine(color_db_name, amount_db)
  155.     end
  156.     tooltip:SmartAnchorTo(self)
  157.     tooltip:Show()
  158.    
  159. end
  160.  
  161.  
  162. -- Release tooltip when leaving the obj
  163. function dataobj:OnLeave()
  164.    bettertip:Release(tooltip)
  165.    tooltip = nil
  166. end
  167.  
  168.  
  169. -- Updating the database with the last amount
  170. local UpdateDB = CreateFrame("Frame")
  171. UpdateDB:RegisterEvent("PLAYER_LOGOUT")
  172. UpdateDB:SetScript("OnEvent",function(...)
  173.     amount = CurrencyText();
  174.     playerName, playerRealm = PlayerInfoText();
  175.    
  176.     SAKL_DB[playerRealm][playerName] = {
  177.     ["class"] = classIndex;
  178.     ["amount"] = colorBetter.. amount;
  179.     ["level"] = UnitLevel("player");
  180.     ["name"] = colorBetter.. playerName;
  181.     };
  182.        
  183. end)
Add Comment
Please, Sign In to add comment