Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local warningSound = true
- minToWarn = 1
- defaultThreshold = 3000
- -- Add slash command configuration menu
- SLASH_CURRENCYMONITOR1, SLASH_CURRENCYMONITOR2 = "/cm", "/currencymonitor";
- function SlashCmdList.CURRENCYMONITOR(msg, editbox)
- CM_ToggleGUI()
- end
- -- Table to reference to determine if a currency is tracked
- -- Basically obsolete once saved settings are working
- local trackingTable = {
- true,
- true,
- true,
- true
- }
- -- Table to store currency IDs for querying the server
- local currencies = {
- "395", -- Justice points
- "396", -- Valor points
- "392", -- Honor points
- "390" -- Conquest points
- }
- -- Table to store currency names for display to the player
- local allCurrency = {
- "Justice Points",
- "Valor Points",
- "Honor Points",
- "Conquest Points"
- }
- -- Table to store currency thresholds over which the player should be notified
- local currencyThresholds = {}
- -- An empty table that gets used more often than a $5 whore
- local currentAmount = {}
- -- Register the events our invisible frame cares about
- function CurrencyMonitor_OnLoad()
- CurrencyMonitorFrame:RegisterEvent("CHAT_MSG_CURRENCY")
- CurrencyMonitorFrame:RegisterEvent("ADDON_LOADED")
- end
- -- Update whether or not the currency is marked for tracking
- function CM_updateChecked(self, i)
- if self:GetChecked() then
- trackingTable[i] = true -- Will be replaced with saved settings
- else
- trackingTable[i] = false
- end
- -- Debugging information
- print("Item "..i.." is now "..tostring(trackingTable[i])..".")
- print(type(CM_db)) -- For some reason, this always returns 'nil'
- end
- -- Update all thresholds with edit box values when the Accept button is pressed
- function CM_UpdateAll(v,j,c,h)
- currencyThresholds = {v:GetText(), j:GetText(), c:GetText(), h:GetText()}
- CM_db["valor"] = {
- ["threshold"] = currencyThresholds[1],
- ["tracked"] = trackingTable[1]
- }
- CM_db["justice"] = {
- ["threshold"] = currencyThresholds[2],
- ["tracked"] = trackingTable[2]
- }
- CM_db["conquest"] = {
- ["threshold"] = currencyThresholds[3],
- ["tracked"] = trackingTable[3]
- }
- CM_db["honor"] = {
- ["threshold"] = currencyThresholds[4],
- ["tracked"] = trackingTable[4]
- }
- for k, v in pairs(CM_db) do
- print(v.threshold, v.tracked)
- end
- CM_ToggleGUI()
- end
- -- Loop through and get the current amount of the four currencies we care about
- local function getAllCurrencies()
- for i = 1, 4 do
- local _, amountNow = GetCurrencyInfo(currencies[i])
- table.insert(currentAmount, amountNow)
- end
- end
- -- Adds the warning message to the raid warning frame
- local function printOutput(triggerCurrency)
- for i = 1, 4 do
- if allCurrency[i] == triggerCurrency then
- if warningSound then
- PlaySoundFile("Sound\\Interface\\RaidWarning.wav")
- end
- RaidNotice_AddMessage(RaidWarningFrame, "You have " .. currentAmount[i] .. " " .. allCurrency[i] .. "!", ChatTypeInfo["RAID_WARNING"])
- end
- end
- end
- -- The functions to run when our registered events fire
- function CurrencyMonitor_OnEvent(event, arg1)
- if event == "CHAT_MESSAGE_CURRENCY" and tonumber(string.match(arg1, '%d+', -4)) >= minToWarn then
- getAllCurrencies()
- for i = 1, 4 do
- local triggerCurrency = string.match(arg1, allCurrency[i])
- if (currentAmount[i] >= currencyThresholds[i]) and (trackingTable[i]) then
- printOutput(triggerCurrency)
- end
- end
- -- Empty the working tables for next use
- currentAmount = nil
- currentAmount = {}
- end
- if (event == "ADDON_LOADED" or event == "PLAYER_ENTERING_WORLD") and arg1 == "CurrencyMonitor" then
- -- If there isn't a table already in the saved variables from last session, create one
- if not (CM_db) then
- CM_db = {}
- end
- -- Assign default values to the new table
- CM_db["valor"] = {["threshold"] = defaultThreshold, ["tracked"] = true}
- CM_db["justice"] = {["threshold"] = defaultThreshold, ["tracked"] = true}
- CM_db["conquest"] = {["threshold"] = defaultThreshold, ["tracked"] = true}
- CM_db["honor"] = {["threshold"] = defaultThreshold, ["tracked"] = true}
- -- Set the edit boxs' default values
- --***********************************
- CM_ValorEdit:SetText(CM_db["valor"].threshold)
- CM_JusticeEdit:SetText(CM_db["justice"].threshold)
- CM_ConquestEdit:SetText(CM_db["conquest"].threshold)
- CM_HonorEdit:SetText(CM_db["honor"].threshold)
- -- Some leftover junk I'm not sure if I need or not
- --[[else -- There's gotta be an easier way to do this :\
- currencyThresholds[1] = CM_db.valor["threshold"]
- trackingTable[1] = CM_db.valor["tracked"]
- currencyThresholds[2] = CM_db["justice"].threshold
- trackingTable[2] = CM_db["justice"].tracked
- currencyThresholds[3] = CM_db["conquest"].threshold
- trackingTable[3] = CM_db["conquest"].tracked
- currencyThresholds[4] = CM_db["honor"].threshold
- trackingTable[4] = CM_db["honor"].tracked
- CM_ValorEdit:SetText(CM_db["valor"].threshold)
- CM_JusticeEdit:SetText(CM_db["justice"].threshold)
- CM_ConquestEdit:SetText(CM_db["conquest"].threshold)
- CM_HonorEdit:SetText(CM_db["honor"].threshold) --]]
- --end
- end
- end
- -- Hide the GUI if it's shown, or show it if it's hidden
- function CM_ToggleGUI(self)
- if CurrencyMonitorFrame:IsVisible(self) then
- CurrencyMonitorFrame:Hide(self)
- else
- CurrencyMonitorFrame:Show(self)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement