Quantcast

v0.05

Matthew Cooney [07-04-11 - 08:36]
v0.05
Filename
README
core.lua
diff --git a/README b/README
index 223b601..06038b7 100644
--- a/README
+++ b/README
@@ -7,6 +7,17 @@ To configure the AddOn, simply edit the core.lua file (in any text editor) as in
 Thanks to Hershe of Silver Hand US for the concept and for testing and fixing my initial version.

 ==Change Log==
+--v0.05--
+Split many of the existing configuration constants into two separate constants, one for SPELL_AURA_APPLIED events and the other for SPELL_SUMMON events.
+
+Added the SAP_CHANCE and SUMMON_CHANCE constants to adjust the frequency that messages are sent at.
+
+Changed the SUMMON_MESSAGE string constant into the SUMMON_PHRASES table constant. Summon messages are now randomised like SPELL_AURA_APPLIED messages.
+
+Moved the message randomisation code to a new local function GetMessage. The first argument is the variable that the message gets assigned to, the second is the table that the message is chosen from.
+
+Changed some of the existing single line explanation comments to more detailed multi-line comments for easier reading.
+
 --v0.04 (Hershe's Edit)--
 -Summary-
 Added a summon message and the ability to put the number of used/remaining charges in messages.
@@ -21,10 +32,9 @@ Added the "SMART" channel value to use RAID, PARTY or SAY depending on your grou
 Added the %c and %x tokens to the SPELL_AURA_APPLIED message to be replaced with charges_remaining and charges_used respectively.

 --v0.03--
-Added the sourceRaidFlags and destRaidFlags arguments to COMBAT_LOG)EVENT_UNFILTERED to fix for patch 4.2.
+Added the sourceRaidFlags and destRaidFlags arguments to COMBAT_LOG_EVENT_UNFILTERED to fix for patch 4.2.

 Changed Interface to 40200.

 --v0.02 (Hershe's Second Fix)--
-
 The PLAYER_GUID constant wasn't being assigned correctly during the loading process. If not already assigned, it will be assigned on the first occurrence of COMBAT_LOG_EVENT_UNFILTERED.
diff --git a/core.lua b/core.lua
index f90c43e..642e7bb 100644
--- a/core.lua
+++ b/core.lua
@@ -3,41 +3,92 @@ To change how the messages are said (e.g. language, channel), visit this page:
 	http://www.wowpedia.org/API_SendChatMessage
 ]]

---SELECT YOUR CHANNEL. You may enter the name of the channel you want your messages to go to (for example "SAY", "EMOTE", "PARTY", "RAID", "BATTLEGROUND", "GUILD", "OFFICER", or "SMART"). "SMART" will send the message to raid if you're in a raid, party if you're in a party, or say if you're in neither.
-local MESSAGE_CHANNEL = "SMART"
+--[[
+Prefixes:
+SAP_ - These fields will be used when someone uses your Lightwell. Short for SPELL_APPLIED_APPLIED, the sub-event of COMBAT_LOG_EVENT_UNFILTERED that fires when people use your Lightwell.
+SUMMON_ - These fields will be used when you summon your Lightwell. Short for SPELL_SUMMON, the sub-event of COMBAT_LOG_EVENT_UNFILTERED that fires when you summon your Lightwell.
+]]
+
+--[[
+SELECT YOUR CHANNEL TYPE.
+You may enter the name of the channel you want your messages to go to.
+e.g. SAY, EMOTE, PARTY, RAID, BATTLEGROUND, GUILD, OFFICER, or "SMART"
+
+When typed without quotation marks, the uppercase english name for all channel types except "RAID_WARNING" will be replaced by the same name translated into your game client's language (the English name will be used if you're using an English game client).
+"SAMRT" uses the translated names for party/raid/say,
+
+"SMART" will send the message to raid if you're in a raid, party if you're in a party, or say if you're in neither.
+WHISPER will send the message as a whisper to the user of the Lightwell. This won't work properly for your summon message.
+]]
+local SAP_CHANNEL_TYPE = "SMART"
+local SUMMON_CHANNEL_TYPE = "SMART"
+
+
+--[[
+SELECT YOUR CHANNEL NUMBER.
+This is the channel number that will be used if you specify "CHANNEL" as your channel type.
+This is the same number that you'd put after a slash in-gamne to speak in the channel.
+e.g. By default, 1 is General, 2 is Trade and 3 is Local Defense.
+]]
+local SAP_CHANNEL_NUMBER = 5
+local SUMMON_CHANNEL_NUMBER = 5
+
+
+--[[
+SELECT YOUR LANGUAGE.
+This is the language that all of your your messages will be sent in.
+e.g. "TROLL", "TAURAHE", "DWARVEN", "DRAENEI".
+nil uses your default language (Orcish for Horde, Common for Alliance)
+]]
+local SAP_LANGUAGE = nil
+local SUMMON_LANGUAGE = nil

---SELECT YOUR LANGUAGE. This is the language that all of your your messages will be sent in. e.g. "TROLL", "TAURAHE", "DWARVEN", "DRAENEI". nil uses your default language (Orcish for Horde, Common for Alliance)
-local MESSAGE_LANGUAGE = nil

---ENTER LIGHTWELL SUMMON MESSAGE. Select a channel and enter a message to be displayed when you summon your lightwell.
-local SUMMON_MESSAGE = "Click my Lightwell for a SURPRISE!"
-local SUMMON_CHANNEL = "SMART"
+--[[
+SELECT THE FREQUENCY OF MESSAGES.
+Messages will only be announced if a randomly generated integer between 1 and this number is equal to 1.
+The default setting of 1 will announce messages 100% of the time.
+The higher the number, the lower the chance of the messages being announced.
+
+Useful formulae:
+-> % chance = (1 / this number) * 100

+-> this number = (1 / % chance) * 100
+]]
+local SAP_CHANCE = 1
+local SUMMON_CHANCE = 1

---[[Add Messages:
+
+--[[
+ADD MESSAGES.
 Format:
 	[#] = "Phrase",
 	[#] = "Phrase",

 Any occurrence of the following placeholders will be replaced as follows:
-%u will be replaced by the Lightwell user's name.
+%u will be replaced by the Lightwell user's name. Does not work for summon messages.
 %p will be replace by your name.
 %c will be replaced by the number of charges remaining on the lightwell
-%x will be replaced by the number of charges used on the lightwell.
+%x will be replaced by the number of charges used on the lightwell. Does not work for summon messages.

-Put a double dash ( -- ) at the start of a line in this table to "comment" it and stop LWB from using that phrase.
+Put a double dash ( -- ) at the start of a line in these tables to "comment" it and stop LWB from using that phrase.
 To use the \ (backslash) or | (vertical bar) characters in the phrase, you may need to use \\ or || respectively.
 ]]
+local SAP_PHRASES = {
+	--Start of table
+	[1] = "Thank you for using the Lightwell %u!",
+	[2] = "May the Light bless you %u.",

+	--End of table
+}
+local SUMMON_PHRASES = {
+	--Start of table
+	[1] = "Click my Lightwell for a SURPRISE!",

-local LWB_phrases = {
-  --Start of table
-  [1] = "Thank you for using the Lightwell %u!",
-  [2] = "May the Light bless you %u.",
-
-  --End of table
+	--End of tabke
 }

+
 --END OF CONFIGURATION. DO NOT MODIFY ANYTHING ELSE BELOW UNLESS YOU REALLY KNOW WHAT YOU'RE DOING!


@@ -56,12 +107,36 @@ local RENEW_SPELLID = 7001
 local charges_used = 0
 local charges_remaining = 0

-local message;
+local SAP_message;
+local SUMMON_message;

+local random = random
 local gsub = string.gsub
 local SendChatMessgae = SendChatMessage


+local function GetMessage(message, whichTable)
+	message = nil --reset the message
+
+	repeat --keep trying to pick a random message until we get one
+		message = whichTable[random(#whichTable)] or nil
+	until message
+
+	message = gsub(message, "(%%[pucx])", function(arg)
+		if arg == "%p" then
+			return PLAYER_NAME
+		elseif arg == "%c" then
+			return charges_remaining
+		elseif whichTable == SAP_PHRASES then --Only substitute destName/charges_used if the message is for a SPELL_AURA_APPLIED event.
+			if	arg == "%u" then
+				return destName
+			elseif arg == "%x" then
+				return charges_used
+			end
+		end
+	end)
+end
+
 local function resetCharges()
 	charges_remaining = 10
 	charges_used = 0
@@ -83,34 +158,25 @@ function LWB_events:COMBAT_LOG_EVENT_UNFILTERED(timestamp, event, hideCaster, so

 	if event == "SPELL_SUMMON" and sourceGUID == PLAYER_GUID and spellId == LIGHTWELL_SPELLID then
 		resetCharges()
-		SendChatMessage(SUMMON_MESSAGE, SUMMON_CHANNEL == "SMART" and ((GetNumRaidMembers() > 0 and RAID) or (GetNumPartyMembers() > 0 and PARTY) or (SAY)) or SUMMON_CHANNEL, MESSAGE_LANGUAGE, nil)
+
+		GetMessage(SUMMON_message, SUMMON_PHRASES)

+		if random(SUMMON_CHANCE) == 1 then
+		  SendChatMessage(SUMMON_message, SUMMON_CHANNEL_TYPE == "SMART" and ((GetNumRaidMembers() > 0 and RAID) or (GetNumPartyMembers() > 0 and PARTY) or (SAY)) or SUMMON_CHANNEL_TYPE, SUMMON_LANGUAGE, (SUMMON_CHANNEL_TYPE == CHANNEL and SUMMON_CHANNEL_NUMBER) or nil)
+		end
 	elseif event == "SPELL_AURA_APPLIED" and sourceGUID == PLAYER_GUID and spellId == RENEW_SPELLID then
 		charges_remaining = charges_remaining - 1
 		charges_used = charges_used + 1
-		message = nil --reset the message
-
-		repeat --keep trying to pick a random message until we get one
-			message = LWB_phrases[random(#LWB_phrases)] or nil
-		until message

-		message = gsub(message, "(%%[pucx])", function(arg)
-			if arg == "%p" then
-				return PLAYER_NAME
-			elseif	arg == "%u" then
-				return destName
-			elseif arg == "%c" then
-				return charges_remaining
-			elseif arg == "%x" then
-				return charges_used
-			end
-		end)
+		GetMessage(SAP_message, SAP_PHRASES)

-	SendChatMessage(message, MESSAGE_CHANNEL == "SMART" and ((GetNumRaidMembers() > 0 and RAID) or (GetNumPartyMembers() > 0 and PARTY) or (SAY)) or MESSAGE_CHANNEL, MESSAGE_LANGUAGE, (MESSAGE_CHANNEL == "WHISPER" and destName) or nil) --Say the message. DO NOT CHANGE THE message ARGUMENT.
+		if random(SAP_CHANCE) == 1 then
+			SendChatMessage(SAP_message, SAP_CHANNEL_TYPE == "SMART" and ((GetNumRaidMembers() > 0 and RAID) or (GetNumPartyMembers() > 0 and PARTY) or (SAY)) or SAP_CHANNEL_TYPE, SAP_LANGUAGE, (SAP_CHANNEL_TYPE == WHISPER and destName) or (SAP_CHANNEL_TYPE == CHANNEL and SAP_CHANNEL_NUMBER) or nil)
+		end
 	end
 end


 LWB_frame:SetScript("OnEvent", function(self, event, ...)
 	LWB_events[event](self, ...)
-end)
\ No newline at end of file
+end)