Advertisement
absolute93

SAKL.lua (opti)

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