Advertisement
absolute93

SAKL.lua (change)

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