Advertisement
Guest User

CurrencyMonitor_HelpMe

a guest
Jul 7th, 2012
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.27 KB | None | 0 0
  1. local warningSound = true
  2. minToWarn = 1
  3. defaultThreshold = 3000
  4.  
  5. -- Add slash command configuration menu
  6. SLASH_CURRENCYMONITOR1, SLASH_CURRENCYMONITOR2 = "/cm", "/currencymonitor";
  7. function SlashCmdList.CURRENCYMONITOR(msg, editbox)
  8. CM_ToggleGUI()
  9. end
  10.  
  11. -- Table to reference to determine if a currency is tracked
  12. -- Basically obsolete once saved settings are working
  13. local trackingTable = {
  14. true,
  15. true,
  16. true,
  17. true
  18. }
  19.  
  20. -- Table to store currency IDs for querying the server
  21. local currencies = {
  22. "395", -- Justice points
  23. "396", -- Valor points
  24. "392", -- Honor points
  25. "390" -- Conquest points
  26. }
  27.  
  28. -- Table to store currency names for display to the player
  29. local allCurrency = {
  30. "Justice Points",
  31. "Valor Points",
  32. "Honor Points",
  33. "Conquest Points"
  34. }
  35.  
  36. -- Table to store currency thresholds over which the player should be notified
  37. local currencyThresholds = {}
  38.  
  39. -- An empty table that gets used more often than a $5 whore
  40. local currentAmount = {}
  41.  
  42. -- Register the events our invisible frame cares about
  43. function CurrencyMonitor_OnLoad()
  44. CurrencyMonitorFrame:RegisterEvent("CHAT_MSG_CURRENCY")
  45. CurrencyMonitorFrame:RegisterEvent("ADDON_LOADED")
  46. end
  47.  
  48. -- Update whether or not the currency is marked for tracking
  49. function CM_updateChecked(self, i)
  50. if self:GetChecked() then
  51. trackingTable[i] = true -- Will be replaced with saved settings
  52. else
  53. trackingTable[i] = false
  54. end
  55. -- Debugging information
  56. print("Item "..i.." is now "..tostring(trackingTable[i])..".")
  57. print(type(CM_db)) -- For some reason, this always returns 'nil'
  58. end
  59.  
  60. -- Update all thresholds with edit box values when the Accept button is pressed
  61. function CM_UpdateAll(v,j,c,h)
  62.  
  63. currencyThresholds = {v:GetText(), j:GetText(), c:GetText(), h:GetText()}
  64.  
  65. CM_db["valor"] = {
  66. ["threshold"] = currencyThresholds[1],
  67. ["tracked"] = trackingTable[1]
  68. }
  69. CM_db["justice"] = {
  70. ["threshold"] = currencyThresholds[2],
  71. ["tracked"] = trackingTable[2]
  72. }
  73. CM_db["conquest"] = {
  74. ["threshold"] = currencyThresholds[3],
  75. ["tracked"] = trackingTable[3]
  76. }
  77. CM_db["honor"] = {
  78. ["threshold"] = currencyThresholds[4],
  79. ["tracked"] = trackingTable[4]
  80. }
  81.  
  82. for k, v in pairs(CM_db) do
  83. print(v.threshold, v.tracked)
  84. end
  85. CM_ToggleGUI()
  86. end
  87.  
  88. -- Loop through and get the current amount of the four currencies we care about
  89. local function getAllCurrencies()
  90. for i = 1, 4 do
  91. local _, amountNow = GetCurrencyInfo(currencies[i])
  92. table.insert(currentAmount, amountNow)
  93. end
  94. end
  95.  
  96. -- Adds the warning message to the raid warning frame
  97. local function printOutput(triggerCurrency)
  98. for i = 1, 4 do
  99. if allCurrency[i] == triggerCurrency then
  100. if warningSound then
  101. PlaySoundFile("Sound\\Interface\\RaidWarning.wav")
  102. end
  103. RaidNotice_AddMessage(RaidWarningFrame, "You have " .. currentAmount[i] .. " " .. allCurrency[i] .. "!", ChatTypeInfo["RAID_WARNING"])
  104. end
  105. end
  106. end
  107.  
  108. -- The functions to run when our registered events fire
  109. function CurrencyMonitor_OnEvent(event, arg1)
  110. if event == "CHAT_MESSAGE_CURRENCY" and tonumber(string.match(arg1, '%d+', -4)) >= minToWarn then
  111. getAllCurrencies()
  112. for i = 1, 4 do
  113. local triggerCurrency = string.match(arg1, allCurrency[i])
  114. if (currentAmount[i] >= currencyThresholds[i]) and (trackingTable[i]) then
  115. printOutput(triggerCurrency)
  116. end
  117. end
  118. -- Empty the working tables for next use
  119. currentAmount = nil
  120. currentAmount = {}
  121. end
  122.  
  123. if (event == "ADDON_LOADED" or event == "PLAYER_ENTERING_WORLD") and arg1 == "CurrencyMonitor" then
  124.  
  125. -- If there isn't a table already in the saved variables from last session, create one
  126. if not (CM_db) then
  127. CM_db = {}
  128. end
  129.  
  130. -- Assign default values to the new table
  131. CM_db["valor"] = {["threshold"] = defaultThreshold, ["tracked"] = true}
  132. CM_db["justice"] = {["threshold"] = defaultThreshold, ["tracked"] = true}
  133. CM_db["conquest"] = {["threshold"] = defaultThreshold, ["tracked"] = true}
  134. CM_db["honor"] = {["threshold"] = defaultThreshold, ["tracked"] = true}
  135.  
  136. -- Set the edit boxs' default values
  137. --***********************************
  138. CM_ValorEdit:SetText(CM_db["valor"].threshold)
  139. CM_JusticeEdit:SetText(CM_db["justice"].threshold)
  140. CM_ConquestEdit:SetText(CM_db["conquest"].threshold)
  141. CM_HonorEdit:SetText(CM_db["honor"].threshold)
  142.  
  143. -- Some leftover junk I'm not sure if I need or not
  144. --[[else -- There's gotta be an easier way to do this :\
  145.  
  146. currencyThresholds[1] = CM_db.valor["threshold"]
  147. trackingTable[1] = CM_db.valor["tracked"]
  148.  
  149. currencyThresholds[2] = CM_db["justice"].threshold
  150. trackingTable[2] = CM_db["justice"].tracked
  151.  
  152. currencyThresholds[3] = CM_db["conquest"].threshold
  153. trackingTable[3] = CM_db["conquest"].tracked
  154.  
  155. currencyThresholds[4] = CM_db["honor"].threshold
  156. trackingTable[4] = CM_db["honor"].tracked
  157.  
  158. CM_ValorEdit:SetText(CM_db["valor"].threshold)
  159. CM_JusticeEdit:SetText(CM_db["justice"].threshold)
  160. CM_ConquestEdit:SetText(CM_db["conquest"].threshold)
  161. CM_HonorEdit:SetText(CM_db["honor"].threshold) --]]
  162. --end
  163. end
  164. end
  165.  
  166. -- Hide the GUI if it's shown, or show it if it's hidden
  167. function CM_ToggleGUI(self)
  168. if CurrencyMonitorFrame:IsVisible(self) then
  169. CurrencyMonitorFrame:Hide(self)
  170. else
  171. CurrencyMonitorFrame:Show(self)
  172. end
  173. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement