--[[ To change how the messages are said (e.g. language, channel), visit this page: http://www.wowpedia.org/API_SendChatMessage ]] --[[ 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 = "WHISPER" 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 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. Format: [#] = "Phrase", [#] = "Phrase", Any occurrence of the following placeholders will be replaced as follows: %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. Does not work for summon messages. 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!", --End of table } --END OF CONFIGURATION. DO NOT MODIFY ANYTHING ELSE BELOW UNLESS YOU REALLY KNOW WHAT YOU'RE DOING! local ADDON_NAME, ns = ... local LWB_events = {} local LWB_frame = CreateFrame("Frame") LWB_frame:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED") local PLAYER_NAME = UnitName("player") local PLAYER_GUID = UnitGUID("player") local LIGHTWELL_SPELLID = 724 local RENEW_SPELLID = 7001 local charges_used = 0 local charges_remaining = 0 local message; local random = random local gsub = string.gsub local SendChatMessgae = SendChatMessage local function GetMessage(whichTable, destName) 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 arg == "%u" then return destName elseif arg == "%x" then return charges_used end end) end local function resetCharges() charges_remaining = 10 charges_used = 0 for i = 7, NUM_GLYPH_SLOTS do local enabled, glyphType, glyphTooltipIndex, glyphSpellID, icon = GetGlyphSocketInfo(i); if ( enabled ) then if glyphSpellID == 55673 then charges_remaining = 15 end end end end function LWB_events:COMBAT_LOG_EVENT_UNFILTERED(timestamp, event, hideCaster, sourceGUID, sourceName, sourceFlags, sourceRaidFlags, destGUID, destName, destFlags, destRaidFlags, spellId, spellName, spellSchool, ...) if not PLAYER_GUID then PLAYER_GUID = UnitGUID("player") end if event == "SPELL_SUMMON" and sourceGUID == PLAYER_GUID and spellId == LIGHTWELL_SPELLID then resetCharges() GetMessage(SUMMON_PHRASES, destName) if random(SUMMON_CHANCE) == 1 then SendChatMessage(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 GetMessage(SAP_PHRASES, destName) if random(SAP_CHANCE) == 1 then SendChatMessage(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)