View difference between Paste ID: bmUVhWE9 and RZq6YkY2
SHOW: | | - or go back to the newest paste.
1
local warningSound = true
2
minToWarn = 1
3
defaultThreshold = 3000
4
defaultTracking = true
5
6
--[[                                      CurrencyMonitor (Description currently inaccurate)
7
8
This program watches a player's justice points, valor points, conquest points, and honor points
9
and flashes a raid warning and optional raid warning sound when any of them exceeds a predetermined 
10
threshold.  CurrencyMonitor is meant to be super simple and configurable only from within this file,
11
meaning you won't find any slash commands or in-game configuration (yet).
12-
-- Basically obsolete once saved settings are working
12+
13-
local trackingTable = {
13+
Line 1 holds the threshold at which you want CurrencyMonitor to alert you; simply change the value 
14-
	true,
14+
on line 1 to your desired threshold. After gaining a currency, for example Justice Points, if you 
15-
	true,
15+
have more than your threshold, this add-on will alert you with a raid warning. If you want the raid 
16-
	true,
16+
warning sound, simply change line 3 to true.
17-
	true
17+
18
The variable minToWarn (line 2) represents the individual amount for which CM will warn the 
19
user. For example, by default honorable kills worth 7 honor will not fire the warning because 
20
they are less than 50 (the default value for minToWarn). If you set minToWarn to zero, every 
21
honor gain while over your threshold, even 1 point, will spam you. Find a happy medium with this
22
number.
23
24
                 *** CurrencyMonitor is Copyright 2011 by Phael of Hydraxis ***
25
26
Please do not distribute altered copies of this add-on because it can make maintaining it a 
27
nightmare. If you want to see a feature built into it, please add a comment on the official 
28
download pages on curse.com and wowinterface.com.
29
30
For now, I will take bug reports and feature requests directly in the comments sections of the 
31
official release channels. Until such a time that I believe I need a ticket tracking system (which
32
hopefully never happens), I will simply answer bug reports/feature requests in comments sections.
33
34
---------------
35
Version History
36
---------------
37
38
-- DATE -- - V.2.0       Created the first in-game GUI. Bugs likely. Added slash command to hide or
39
						 show the GUI.
40
07/02/2012 - V.1.2.3	 Removed an unnecessary registered event. Matched default values to 
41
						 description. Flipped the change log. Moved variables around in the file to
42-
-- Register the events our invisible frame cares about
42+
						 make maintaining it just a bit easier.
43
02/24/2012 - V.1.2.2	 Fixed a problem with the currency warning not updating to reflect the
44
						 current amount of points when points are awarded. Minor .toc file fix.
45
12/15/2011 - V.1.2.1	 Changed some variables to local to avoid polluting the global environment.
46
12/09/2011 - V.1.2       Spam bug fix. Also warns of only the type of currency that triggered the 
47
					     warning. Considerable code rewrite for less redundancy.
48
12/05/2011 - V.1.1       Removed BG spamminess through smart points announcement.
49
12/02/2011 - V.1.0       Now firing on the correct event.					 
50
12/02/2011 - V.0.1(BETA) (Initial release)
51-
		trackingTable[i] = true -- Will be replaced with saved settings
51+
52
-----
53
To-Do
54
-----
55
56
Nap. Damn I love naps.
57-
	print(type(CM_db)) -- For some reason, this always returns 'nil'
57+
58
--- Credits ---
59
60
Credit goes to Wowhead user eidyia for the idea and additional input that helped hone this add-on's
61
functionality. Specifically, thank eidyia for the version 1.1 removal of BG spam and the 1.2 removal
62
of buggy spam!
63
64
--]]
65
66
----------------- Know what you're doing before you edit anything below this line. -----------------
67
68
-- Add slash command configuration menu
69
SLASH_CURRENCYMONITOR1, SLASH_CURRENCYMONITOR2 = "/cm", "/currencymonitor";
70
function SlashCmdList.CURRENCYMONITOR(msg, editbox)
71
	CM_ToggleGUI()
72
	print(type(CM_db))
73
end
74
75
-- Table to reference to determine if a currency is tracked
76
local trackingTable = {}
77
78
-- Table to store currency IDs for querying the server
79
local currencies = {
80
	"395", -- Justice points
81
	"396", -- Valor points
82
	"392", -- Honor points
83
	"390"  -- Conquest points
84
}
85
86
-- Table to store currency names for display to the player
87
local allCurrency = {
88
	"Justice Points",
89
	"Valor Points",
90
	"Honor Points",
91
	"Conquest Points"
92
}
93
94
-- Table to store currency thresholds over which the player should be notified
95
local currencyThresholds = {}
96
97
-- An empty table that gets used more often than a $5 whore
98
local currentAmount = {}
99
100
-- Register the event our invisible frame cares about and set up the GUI
101
function CurrencyMonitor_OnLoad() 
102
103
	CurrencyMonitorFrame:RegisterEvent("CHAT_MSG_CURRENCY")
104
	CurrencyMonitorFrame:RegisterEvent("ADDON_LOADED")
105
end
106
107
-- Update whether or not the currency is marked for tracking
108
function CM_updateChecked(self, i)
109-
function CurrencyMonitor_OnEvent(event, arg1)
109+
110
	if self:GetChecked() then
111
		trackingTable[i] = true
112
	else
113
		trackingTable[i] = false
114
	end
115
	-- Debugging information
116
	print("Item "..i.." is now "..tostring(trackingTable[i])..".")
117
	print(type(CM_db))
118
end
119
120
-- Update all thresholds with edit box values when the Accept button is pressed
121
function CM_UpdateAll(v,j,c,h)
122
123-
	if (event == "ADDON_LOADED" or event == "PLAYER_ENTERING_WORLD") and arg1 == "CurrencyMonitor" then
123+
124
	
125
	CM_db["valor"] = {
126
		["threshold"] = currencyThresholds[1],
127
		["tracked"] = trackingTable[1]
128
	}
129
	CM_db["justice"] = {
130-
		-- Assign default values to the new table
130+
131-
		CM_db["valor"] = {["threshold"] = defaultThreshold, ["tracked"] = true}
131+
132-
		CM_db["justice"] = {["threshold"] = defaultThreshold, ["tracked"] = true}
132+
133-
		CM_db["conquest"] = {["threshold"] = defaultThreshold, ["tracked"] = true}
133+
134-
		CM_db["honor"] = {["threshold"] = defaultThreshold, ["tracked"] = true}
134+
135
		["tracked"] = trackingTable[3]
136-
		-- Set the edit boxs' default values
136+
137-
		--***********************************
137+
138
		["threshold"] = currencyThresholds[4],
139
		["tracked"] = trackingTable[4]
140
	}
141
	
142
	for k, v in pairs(CM_db) do
143-
		-- Some leftover junk I'm not sure if I need or not
143+
144-
		--[[else -- There's gotta be an easier way to do this :\
144+
145
	CM_ToggleGUI()
146-
			currencyThresholds[1] = CM_db.valor["threshold"]
146+
147-
			trackingTable[1] = CM_db.valor["tracked"]
147+
148-
			
148+
149-
			currencyThresholds[2] = CM_db["justice"].threshold
149+
150-
			trackingTable[2] = CM_db["justice"].tracked
150+
151-
			
151+
152-
			currencyThresholds[3] = CM_db["conquest"].threshold
152+
153-
			trackingTable[3] = CM_db["conquest"].tracked
153+
154-
			
154+
155-
			currencyThresholds[4] = CM_db["honor"].threshold
155+
156-
			trackingTable[4] = CM_db["honor"].tracked
156+
157-
			
157+
158-
			CM_ValorEdit:SetText(CM_db["valor"].threshold)
158+
159-
			CM_JusticeEdit:SetText(CM_db["justice"].threshold)
159+
160-
			CM_ConquestEdit:SetText(CM_db["conquest"].threshold)
160+
161-
			CM_HonorEdit:SetText(CM_db["honor"].threshold)		--]]	
161+
162-
		--end
162+
163
				PlaySoundFile("Sound\\Interface\\RaidWarning.wav")
164
			end
165
			RaidNotice_AddMessage(RaidWarningFrame, "You have " .. currentAmount[i] .. " " .. allCurrency[i] .. "!", ChatTypeInfo["RAID_WARNING"])
166
		end
167
	end
168
end
169
170
-- The functions to run when our registered events fire
171
function CurrencyMonitor_OnEvent(self, event, arg1)
172
173
	if event == "CHAT_MESSAGE_CURRENCY" and tonumber(string.match(arg1, '%d+', -4)) >= minToWarn then		
174
		getAllCurrencies()
175
		for i = 1, 4 do
176
			local triggerCurrency = string.match(arg1, allCurrency[i])
177
			if (currentAmount[i] >= currencyThresholds[i]) and (trackingTable[i]) then
178
				printOutput(triggerCurrency)
179
			end
180
		end
181
	-- Empty the working tables for next use
182
	currentAmount = nil
183
	currentAmount = {}	
184
	end
185
	
186
	if (event == "ADDON_LOADED" and arg1 == "CurrencyMonitor") then
187
		
188
		-- If there isn't a table already in the saved variables from last session, create one
189
		if not (CM_db) then
190
			CM_db = {}
191
			-- Assign default values to the new table
192
			CM_db["valor"] = {["threshold"] = defaultThreshold, ["tracked"] = defaultTracking}
193
			CM_db["justice"] = {["threshold"] = defaultThreshold, ["tracked"] = defaultTracking}
194
			CM_db["conquest"] = {["threshold"] = defaultThreshold, ["tracked"] = defaultTracking}
195
			CM_db["honor"] = {["threshold"] = defaultThreshold, ["tracked"] = defaultTracking}			
196
		end
197
		print(type(CM_db))
198
	
199
		-- Set the edit boxes' default values
200
		CM_ValorEdit:SetText(CM_db["valor"].threshold)
201
		CM_JusticeEdit:SetText(CM_db["justice"].threshold)
202
		CM_ConquestEdit:SetText(CM_db["conquest"].threshold)
203
		CM_HonorEdit:SetText(CM_db["honor"].threshold)
204
	end
205
end
206
207
-- Hide the GUI if it's shown, or show it if it's hidden
208
function CM_ToggleGUI(self)
209
210
	if CurrencyMonitorFrame:IsVisible(self) then
211
		CurrencyMonitorFrame:Hide(self)
212
	else
213
		CurrencyMonitorFrame:Show(self)
214
	end
215
end