Thread Tools Display Modes
03-21-14, 11:21 AM   #1
Tactica
Not Amused
 
Tactica's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2010
Posts: 96
Class colors in message output

Greetings all, I am fairly new to lua and I have been pooling multiple resources to try and get this abandoned addon up to date and have made progress, however I am trying to add the class color of the person who conjures/creates and item to show in the message that is sent:

Code:
		 local timestamp, type, hideCaster, sourceGUID, sourceName, sourceFlags, sourceRaidFlags, destGUID, destName, destFlags, destRaidFlags, spellID, spellName = ...
		
		--print (type,spellID,sourceName,destName)
		--printMessage (searchTable)

		if (AnnouncerState == true and (UnitInParty(sourceName) or UnitInRaid(sourceName)) and (type=="SPELL_CREATE" or type=="SPELL_SUMMON" or type=="SPELL_CAST_SUCCESS") and GetNumGroupMembers()>0 and checkTable[spellID]~=nil) then
			--printMessage ("**************")
			--printMessage (type,spellID,sourceName,destName)
			
			-- use this for cauldrons, they show up only for SPELL_CAST_START and have null for destName
			if (destName==nil) then
				destName = spellName
			end

			
			if (destName=="Create Soulwell") then
				return
			end
			
		local _, class = GetPlayerInfoByGUID(sourceGUID)
		local color, message = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)[class]
			if color then
				message = ("{rt1}\124c%s%s\124r has created %s{rt1}"):format(color.colorStr, sourceName, GetSpellLink(spellID))
			else
				message = ("{rt1}%s has created %s{rt1}"):format(sourceName, GetSpellLink(spellID))
			end
If the entire lua is needed I can post. The above loads and does not report a bug when and item is conjured, but no message is being sent out.
  Reply With Quote
03-21-14, 11:37 AM   #2
Dridzt
A Pyroguard Emberseer
 
Dridzt's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2005
Posts: 1,360
If you are trying to use this with the SendChatMessage API it will not work.

You cannot send any kind of escape codes (this includes colors) in chat with the exception of target charms. ({rt#})

You can only colorize messages locally (in your own chatframes)

I can't tell what you're trying to do from that snippet you posted, you need to post more relevant code or link to the addon in question.
  Reply With Quote
03-21-14, 11:41 AM   #3
Tactica
Not Amused
 
Tactica's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2010
Posts: 96
I am trying to update Conjured Announcer. I have a version that works fine with the exception of noodle carts >Working w/o Carts.

This below is an attempt at printing the class color of the person/player that conjures the item/spell.

Tested and confirmed both in game and http://codepad.org/dlhrKHRC there are no errors, but with the lua below the addon loads fine but there is no chat output whatsoever.

Code:
function displayMessage(msg)
	inInstance, instanceType = IsInInstance()

	local messageType = "PARTY"

	if AnnouncerPARTY==true then
		--
	elseif inInstance == 1 and instanceType ~= "none" then
		messageType = "INSTANCE_CHAT"
	end

	if (AnnouncerRW == true and (UnitIsGroupAssistant("player") or UnitIsGroupLeader("player")) and IsInRaid()) then
		messageType = "RAID_WARNING"
	end
	
	SendChatMessage(msg,messageType)
end

function printMessage(msg)
	print("|cff7f7fff[CA 2] "..msg)
end

function OnEvent(self, event, ...)
	if event == "VARIABLES_LOADED" then
	
		if AnnouncerState==nil then
			AnnouncerState = true
		end

		if AnnouncerPARTY==nil then
			AnnouncerPARTY = true
		end
		if AnnouncerRW==nil then
			AnnouncerRW = false
		end		
		
		if AnnouncerState==true then
			conjuredAnnouncer:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
		else
			conjuredAnnouncer:UnregisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
		end
		
		printMessage("Conjured Announcer loaded.")
		printMessage("Type /can or /cann for options. Announcer state is: "..getState(AnnouncerState))
			
		SlashCmdList["FFDCMD"] = SlashCommand;
		SLASH_FFDCMD1 = "/can";
		SLASH_FFDCMD2 = "/cann";
	else
		 local timestamp, type, hideCaster, sourceGUID, sourceName, sourceFlags, sourceRaidFlags, destGUID, destName, destFlags, destRaidFlags, spellID, spellName = ...
		
		--print (type,spellID,sourceName,destName)
		--printMessage (searchTable)

		if (AnnouncerState == true and (UnitInParty(sourceName) or UnitInRaid(sourceName)) and (type=="SPELL_CREATE" or type=="SPELL_SUMMON" or type=="SPELL_CAST_SUCCESS") and GetNumGroupMembers()>0 and checkTable[spellID]~=nil) then
			--printMessage ("**************")
			--printMessage (type,spellID,sourceName,destName)
			
			-- use this for cauldrons, they show up only for SPELL_CAST_START and have null for destName
			if (destName==nil) then
				destName = spellName
			end

			
			if (destName=="Create Soulwell") then
				return
			end
			
		local _, class = GetPlayerInfoByGUID(sourceGUID)
		local color, message = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)[class]
			if color then
				message = ("{rt1}\124c%s%s\124r has created %s{rt1}"):format(color.colorStr, sourceName, GetSpellLink(spellID))
			else
				message = ("{rt1}%s has created %s{rt1}"):format(sourceName, GetSpellLink(spellID))
			end	
			

			
			if (antispamtable[message]==nil) then
				antispamtable[message] = time()
				displayMessage(message)
			else			
				if (time()-antispamtable[message])>10 then
					antispamtable[message] = time()
					displayMessage(message)
				end
			end
		end
	end
end

function helptxt()
	printMessage(" Conjured Announcer 2. Current state: "..getState(AnnouncerState))
	printMessage(" ")	
	printMessage(" Activate : /can on")
	printMessage(" Deactivate: /can off")
	printMessage(" Announce on party: /can party")
	printMessage(" Announce on group chat: /can group")
	printMessage(" Announce on raid warning: /can rw")
end

function SlashCommand(msg)
	local argc, argv = 0, {}
	gsub(msg, "[^%s]+", function (word) argc=argc+1; argv[argc]=word; end);

	if (argc == 1) then
		if (argv[1] == "help") then
			helptxt()
		elseif (argv[1] == "off") then
			printMessage("Announcer state OFF. Type /can on to activate")
			AnnouncerState = false;		
			conjuredAnnouncer:UnregisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
		elseif  (argv[1] == "on") then
			printMessage("Announcer state ON. Type /can off to deactivate")
			AnnouncerState = true
			conjuredAnnouncer:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
		elseif  (argv[1] == "party") then
			AnnouncerPARTY = true
			printMessage("Announcer set to PARTY.")
		elseif  (argv[1] == "rw") then
			AnnouncerRW = not AnnouncerRW
			printMessage("Announcer using raidwarning: "..getState(AnnouncerRW))
		elseif  (argv[1] == "group") then
			AnnouncerPARTY = false
			printMessage("Announcer set to GROUP.")			
		end
	else
		helptxt()
	end
end

function getState(cond)
	if cond==true then
		return "ON"	
	else
		return "OFF"
	end
end

	
--67826 Jeeves
--54711 Scrapbot
--44389 Field Repair Bot 110G
--22704 Field Repair Bot 74A
--57426 Fish Feast
--57301 Great Feast
--54710 MOLL-E

--92824 Ritual of Refreshment
--43987 Refreshment Portal
--698   Ritual of Summoning
--29893 Ritual of Souls

--41458 Cauldron of Major Arcane Protection
--41500 Cauldron of Major Fire Protection
--41501 Cauldron of Major Frost Protection
--92649 Cauldron of Battle
--92712 Big Cauldron of Battle
--87915 Goblin Barbecue Feast
--87644 Seafood Magnifique Feast
--87643 Broiled Dragon Feast

--145196 Pandaren Treasure Noodle Cart Kit
--145169 Deluxe Noodle Cart
--145166 Noodle Cart	
--104958 Pandaren Banquet
--126492 Banquet of the Grill
--126494 Great Banquet of the Grill
--126501 Banquet of the Oven
--145061 Deluxe Noodle Cart Kit
--145038 Noodle Cart Kit
--126502 Great Banquet of the Oven
--126504 Great Banquet of the Brew
--126498 Great Banquet of the Pot
--126500 Great Banquet of the Steamer
--126496 Great Banquet of the Wok
--105193 Great Pandaren Banquet
--126503 Banquet of the Brew
--126497 Banquet of the Pot
--126499 Banquet of the Steamer
--126495 Banquet of the Wok

--10059 STORMWIND PORTAL
--11416 IRONFORGE PORTAL
--11417 ORGRIMMAR PORTAL
--11418 UNDERCITY PORTAL
--11419 DARNASSUS PORTAL
--11420 THUNDER BLUFF PORTAL
--32266 EXODAR PORTAL
--32267 SILVERMOON PORTAL
--33691 SHATTRATH PORTAL
--35717 SHATTRATH PORTAL
--49360 THERAMORE PORTAL
--49361 STONARD PORTAL
--53142 DALARAN PORTAL
--88345 TOL BARAD PORTAL
--88346 TOL BARAD PORTAL
--120146 ANCIENT DALARAN PORTAL
--132620 VALE OF ETERNAL BLOSSOMS PORTAL
--132626 VALE OF ETERNAL BLOSSOMS PORTAL

spellIDS   = {67826,54711,44389,22704,57426,57301,54710,92824,43987,698,29893,41458,41500,41501,92649,92712,87915,87644,87643,145196,145169,145166,104958,126492,126494,126501,145061,145038,126502,126504,126498,126500,126496,105193,126503,126497,126499,126495,10059,11416,11417,11418,11419,11420,32266,32267,33691,35717,49360,49361,53142,88345,88346,120146,132620,132626}
checkTable = {}

for i=1,#spellIDS do checkTable[spellIDS[i]]=1 end

msgType = {}
msgType["pvp"]="BATTLEGROUND"
msgType["arena"]="PARTY"
msgType["party"]="PARTY"
msgType["instance"]="INSTANCE"
msgType["raid"]="RAID"

antispamtable = {}



conjuredAnnouncer = CreateFrame("Frame")
conjuredAnnouncer:RegisterEvent("VARIABLES_LOADED")
conjuredAnnouncer:SetScript("OnEvent", OnEvent)

Last edited by Tactica : 03-21-14 at 12:30 PM. Reason: updated working code link
  Reply With Quote
03-21-14, 02:22 PM   #4
Tactica
Not Amused
 
Tactica's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2010
Posts: 96
For some reason the addon does not detect when a player is in an instance/LFD which is a more pressing issue than anything else:

Code:
function displayMessage(msg)
	inInstance, instanceType = IsInInstance()

	local messageType = "party"

	if Announcerparty==true then
		--
	elseif inInstance == 1 and instanceType ~= "none" then
		messageType = "INSTANCE_CHAT"
	end

	if (AnnouncerRW == true and (UnitIsGroupAssistant("player") or UnitIsGroupLeader("player")) and IsInRaid()) then
		messageType = "RAID_WARNING"
	end
	
	SendChatMessage(msg,messageType)
end

function printMessage(msg)
	print("|cff7f7fff[Conjured Announcer 2] "..msg)
end

function OnEvent(self, event, ...)
	if event == "VARIABLES_LOADED" then
	
		if AnnouncerState==nil then
			AnnouncerState = true
		end

		if Announcerparty==nil then
			Announcerparty = true
		end
		if AnnouncerRW==nil then
			AnnouncerRW = false
		end		
		
		if AnnouncerState==true then
			conjuredAnnouncer:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
		else
			conjuredAnnouncer:UnregisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
		end
		
		printMessage("Conjured Announcer 2 loaded.")
		printMessage("Type /can or /cann for options. Announcer state is: "..getState(AnnouncerState))
			
		SlashCmdList["FFDCMD"] = SlashCommand;
		SLASH_FFDCMD1 = "/can";
		SLASH_FFDCMD2 = "/cann";
	else
		local timestamp, type, sourceGUID,hideCaster, sourceName, sourceFlags,sourceRaidFlags, destGUID, destName, destFlags,destRaidFlags, spellID, spellName = select(1, ...)
		
		--print (type,spellID,sourceName,destName)
		--printMessage (searchTable)

		if (AnnouncerState == true and (UnitInParty(sourceName) or UnitInRaid(sourceName)) and (type=="SPELL_CREATE" or type=="SPELL_SUMMON" or type=="SPELL_CAST_START") and GetNumGroupMembers()>0 and checkTable[spellID]~=nil) then
			--printMessage ("**************")
			--printMessage (type,spellID,sourceName,destName)
			
			-- use this for cauldrons, they show up only for SPELL_CAST_START and have null for destName
			if (destName==nil) then
				destName = spellName
			end

			
			if (destName=="Create Soulwell") then
				return
			end
			
			message     = "{rt1}" ..sourceName .. " has created " .. GetSpellLink(spellID).."{rt1}"
			

			
			if (antispamtable[message]==nil) then
				antispamtable[message] = time()
				displayMessage(message)
			else			
				if (time()-antispamtable[message])>10 then
					antispamtable[message] = time()
					displayMessage(message)
				end
			end
		end
	end
end

function helptxt()
	printMessage(" Conjured Announcer 2. Current state: "..getState(AnnouncerState))
	printMessage(" ")	
	printMessage(" Activate : /can on")
	printMessage(" Deactivate: /can off")
	printMessage(" Announce on party: /can party")
	printMessage(" Announce on group chat: /can group")
	printMessage(" Announce on raid warning: /can rw")
end

function SlashCommand(msg)
	local argc, argv = 0, {}
	gsub(msg, "[^%s]+", function (word) argc=argc+1; argv[argc]=word; end);

	if (argc == 1) then
		if (argv[1] == "help") then
			helptxt()
		elseif (argv[1] == "off") then
			printMessage("Announcer state OFF. Type /can on to activate")
			AnnouncerState = false;		
			conjuredAnnouncer:UnregisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
		elseif  (argv[1] == "on") then
			printMessage("Announcer state ON. Type /can off to deactivate")
			AnnouncerState = true
			conjuredAnnouncer:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
		elseif  (argv[1] == "party") then
			Announcerparty = true
			printMessage("Announcer set to party.")
		elseif  (argv[1] == "rw") then
			AnnouncerRW = not AnnouncerRW
			printMessage("Announcer using raidwarning: "..getState(AnnouncerRW))
		elseif  (argv[1] == "group") then
			Announcerparty = false
			printMessage("Announcer set to GROUP.")			
		end
	else
		helptxt()
	end
end

function getState(cond)
	if cond==true then
		return "ON"	
	else
		return "OFF"
	end
end

	
--67826 jewels
--54711 scrapbot
--44389 Field Repair Bot 110G
--57426 fishfeast
--57301 great feast
--54710 moll-e

--92824 Ritual of Refreshment
--43987 Refreshment Portal
--698   Ritual of Summoning
--29893 Ritual of Souls

--92649 Cauldron of Battle
--92712 Big Cauldron of Battle
--87915 Goblin Barbecue Feast
--87644 Seafood Magnifique Feast
--87643 Broiled Dragon Feast

--104958 Pandaren Banquet
--126492 Banquet of the Grill
--126494 Great Banquet of the Grill
--126501 Banquet of the Oven
--126502 Great Banquet of the Oven
--126504 Great Banquet of the Brew
--126498 Great Banquet of the Pot
--126500 Great Banquet of the Steamer
--126496 Great Banquet of the Wok
--105193 Great Pandaren Banquet
--126503 Banquet of the Brew
--126497 Banquet of the Pot
--126499 Banquet of the Steamer
--126495 Banquet of the Wok

--10059 STORMWIND PORTAL
--11416 IRONFORGE PORTAL
--11417 ORGRIMMAR PORTAL
--11418 UNDERCITY PORTAL
--11419 DARNASSUS PORTAL
--11420 THUNDER BLUFF PORTAL
--32266 EXODAR PORTAL
--32267 SILVERMOON PORTAL
--33691 SHATTRATH PORTAL
--35717 SHATTRATH PORTAL
--49360 THERAMORE PORTAL
--49361 STONARD PORTAL
--53142 DALARAN PORTAL
--88345 TOL BARAD PORTAL
--88346 TOL BARAD PORTAL
--120146 ANCIENT DALARAN PORTAL
--132620 VALE OF ETERNAL BLOSSOMS PORTAL
--132626 VALE OF ETERNAL BLOSSOMS PORTAL

spellIDS   = {67826,54711,44389,22704,57426,57301,54710,92824,43987,698,29893,41458,41500,41501,92649,92712,87915,87644,87643,145196,145169,145166,104958,126492,126494,126501,145061,145038,126502,126504,126498,126500,126496,105193,126503,126497,126499,126495,10059,11416,11417,11418,11419,11420,32266,32267,33691,35717,49360,49361,53142,88345,88346,120146,132620,132626}
checkTable = {}

for i=1,#spellIDS do checkTable[spellIDS[i]]=1 end

msgType = {}
msgType["pvp"]="BATTLEGROUND"
msgType["arena"]="PARTY"
msgType["party"]="PARTY"
msgType["raid"]="RAID"

antispamtable = {}



conjuredAnnouncer = CreateFrame("Frame")
conjuredAnnouncer:RegisterEvent("VARIABLES_LOADED")
conjuredAnnouncer:SetScript("OnEvent", OnEvent)

Last edited by Tactica : 03-21-14 at 03:19 PM.
  Reply With Quote
03-21-14, 04:01 PM   #5
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
The globals in that code are simply horrifying, and I wouldn't be surprised in the least if it's not working because some other addons are overwriting them. Also, the usage of the VARIABLES_LOADED event is a dead giveaway that the codebase is extremely outdated, or at least that it was copied from some extremely outdated code. Here is a rewritten version that does not leak badly named globals (or any globals) and uses the correct events to function as expected in the current version of WoW:

Lua Code:
  1. local announceSpells = {
  2.     [67826] = true, -- jewels
  3.     [54711] = true, -- scrapbot
  4.     [22704] = true, -- Field Repair Bot 74A
  5.     [44389] = true, -- Field Repair Bot 110G
  6.     [57426] = true, -- fishfeast
  7.     [57301] = true, -- great feast
  8.     [54710] = true, -- moll-e
  9.     [92824] = true, -- Ritual of Refreshment
  10.     [43987] = true, -- Refreshment Portal
  11.     [698] = true, --   Ritual of Summoning
  12.     [29893] = true, -- Ritual of Souls
  13.  
  14.     [41458] = true, -- Cauldron of Major Arcane Protection
  15.     [41500] = true, -- Cauldron of Major Fire Protection
  16.     [41501] = true, -- Cauldron of Major Frost Protection
  17.  
  18.     [92649] = true, -- Cauldron of Battle
  19.     [92712] = true, -- Big Cauldron of Battle
  20.     [87915] = true, -- Goblin Barbecue Feast
  21.     [87644] = true, -- Seafood Magnifique Feast
  22.     [87643] = true, -- Broiled Dragon Feast
  23.  
  24.     [104958] = true, -- Pandaren Banquet
  25.     [126492] = true, -- Banquet of the Grill
  26.     [126494] = true, -- Great Banquet of the Grill
  27.     [126501] = true, -- Banquet of the Oven
  28.     [126502] = true, -- Great Banquet of the Oven
  29.     [126504] = true, -- Great Banquet of the Brew
  30.     [126498] = true, -- Great Banquet of the Pot
  31.     [126500] = true, -- Great Banquet of the Steamer
  32.     [126496] = true, -- Great Banquet of the Wok
  33.     [105193] = true, -- Great Pandaren Banquet
  34.     [126503] = true, -- Banquet of the Brew
  35.     [126497] = true, -- Banquet of the Pot
  36.     [126499] = true, -- Banquet of the Steamer
  37.     [126495] = true, -- Banquet of the Wok
  38.  
  39.     [145166] = true, -- Noodle Cart
  40.     [145169] = true, -- Deluxe Noodle Cart
  41.     [145196] = true, -- Pandaren Treasure Noodle Cart
  42.  
  43.     [10059] = true, -- STORMWIND PORTAL
  44.     [11416] = true, -- IRONFORGE PORTAL
  45.     [11417] = true, -- ORGRIMMAR PORTAL
  46.     [11418] = true, -- UNDERCITY PORTAL
  47.     [11419] = true, -- DARNASSUS PORTAL
  48.     [11420] = true, -- THUNDER BLUFF PORTAL
  49.     [32266] = true, -- EXODAR PORTAL
  50.     [32267] = true, -- SILVERMOON PORTAL
  51.     [33691] = true, -- SHATTRATH PORTAL
  52.     [35717] = true, -- SHATTRATH PORTAL
  53.     [49360] = true, -- THERAMORE PORTAL
  54.     [49361] = true, -- STONARD PORTAL
  55.     [53142] = true, -- DALARAN PORTAL
  56.     [88345] = true, -- TOL BARAD PORTAL
  57.     [88346] = true, -- TOL BARAD PORTAL
  58.     [120146] = true, -- ANCIENT DALARAN PORTAL
  59.     [132620] = true, -- VALE OF ETERNAL BLOSSOMS PORTAL
  60.     [132626] = true, -- VALE OF ETERNAL BLOSSOMS PORTAL
  61. }
  62.  
  63. local db
  64.  
  65. local Addon = CreateFrame("Frame", "ConjuredAnnouncer")
  66. Addon:SetScript("OnEvent", function(self, event, ...) return self[event](self, ...) end)
  67. Addon:RegisterEvent("PLAYER_LOGIN")
  68.  
  69. function Addon:Print(message)
  70.     DEFAULT_CHAT_FRAME:AddMessage("|cff7f7fff[Conjured Announcer 2]|r " .. message)
  71. end
  72.  
  73. function Addon:SendMessage(message)
  74.     local channel
  75.     if db.raidWarning and IsInRaid() and (UnitIsGroupLeader("player") or UnitIsGroupAssistant("player")) then
  76.         channel = "RAID_WARNING"
  77.     elseif IsInGroup(LE_PARTY_CATEGORY_INSTANCE) then
  78.         channel = "INSTANCE_CHAT"
  79.     elseif IsInRaid() and not db.partyInRaid then
  80.         channel = "RAID"
  81.     elseif IsInGroup() then
  82.         channel = "PARTY"
  83.     end
  84.  
  85.     if channel then
  86.         SendChatMessage(message, channel)
  87.     end
  88. end
  89.  
  90. local FILTER_GROUP = bit.bor(COMBATLOG_OBJECT_TYPE_PLAYER, COMBATLOG_OBJECT_AFFILIATION_PARTY, COMBATLOG_OBJECT_AFFILIATION_RAID)
  91. local MESSAGE_TEMPLATE = ">>> %s has created %s <<<"
  92.  
  93. local lastAnnounced = {}
  94. local announceEvents = {
  95.     ["SPELL_CAST_START"] = true,
  96.     ["SPELL_CREATE"] = true,
  97.     ["SPELL_SUMMON"] = true,
  98. }
  99.  
  100. function Addon:COMBAT_LOG_EVENT_UNFILTERED(_, combatEvent, _, sourceGUID, sourceName, sourceFlags, _, destGUID, destName, destFlags, _, spellID, spellName)
  101.     if not announceEvents[combatEvent] or not announceSpells[spellID] or bit.band(sourceGUID, FILTER_GROUP) == 0 then return end
  102.    
  103.     -- use this for cauldrons, they show up only for SPELL_CAST_START and have null for destName
  104.     if not destName then
  105.         destName = spellName
  106.     end
  107.    
  108.     local message = format(MESSAGE_TEMPLATE, sourceName, destName)
  109.    
  110.     local now = GetTime()
  111.     local lastTime = lastAnnounced[message]
  112.     if lastTime and (now - lastTime < 10) then
  113.         return
  114.     end
  115.    
  116.     lastAnnounced[message] = now
  117.     self:SendMessage(message)
  118. end
  119.  
  120. function Addon:GROUP_ROSTER_UPDATE()
  121.     if db.enable and IsInGroup() then
  122.         self:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
  123.     else
  124.         self:UnregisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
  125.     end
  126. end
  127.  
  128. function Addon:PLAYER_LOGIN()
  129.     db = ConjuredAnnouncerDB
  130.     if not db then
  131.         db = {
  132.             enable = true,
  133.             partyInRaid = false,
  134.             raidWarning = true,
  135.         }
  136.         ConjuredAnnouncerDB = db
  137.  
  138.         -- Only print a welcome message the first time. Nobody likes spam.
  139.         self:Print("Welcome! Type /can or /cann for options.")
  140.     end
  141.  
  142.     self:GROUP_ROSTER_UPDATE()
  143. end
  144.  
  145. SLASH_CONJUREDANNOUNCER1 = "/can"
  146. SLASH_CONJUREDANNOUNCER2 = "/cann"
  147.  
  148. local ON = "|cff7fff7fON|"
  149. local OFF = "|cff7f7f7fOFF|r"
  150.  
  151. SlashCmdList["CONJUREDANNOUNCER"] = function(input)
  152.     local command, args = strsplit(" ", input or "", 2)
  153.     command = strlower(command)
  154.  
  155.     if command == "off" then
  156.         db.enable = false
  157.         Addon:GROUP_ROSTER_UPDATE()
  158.         Addon:Print("Announcements " .. OFF .. ". Type '/can on' to enable.")
  159.     elseif command == "on" then
  160.         db.enable = true
  161.         Addon:GROUP_ROSTER_UPDATE()
  162.         Addon:Print("Announcements " .. ON ..". Type '/can off' to disable.")
  163.     elseif command == "party" then
  164.         db.partyInRaid = not db.partyInRaid
  165.         Addon:Print("Now announcing to " .. (db.partyInRaid and "party only" or "the entire raid") .. " while in a raid.")
  166.     elseif command == "rw" then
  167.         db.raidWarning = not db.raidWarning
  168.         Addon:Print("Raid warning announcements " .. (db.raidWarning and ON or OFF)
  169.     else
  170.         Addon:Print("Current state is " .. (db.enable and ON or OFF))
  171.         print("    Use /can or /cann with the following commands:")
  172.         print("  |cffffff7f on |r- enable announcements")
  173.         print("  |cffffff7f off |r- disable announcements")
  174.         print("  |cffffff7f party |r- announce only to your party in a raid (" .. (db.partyInRaid and ON or OFF) .. ")")
  175.         print("  |cffffff7f rw |r- announce to raid warning when possible (" .. (db.raidWarning and ON or OFF) .. ")")
  176.         print("  |cffffff7f help |r- shows this list of commands")
  177.     end
  178. end

However, as Dridzt already pointed out, it is not possible to use colors in messages you send to other players. The other players would need to be using an addon that detected player names in chat messages and colorized them. There is no way for you to do that on your side of things. (The only way to "send colors" would be to send a colorized link, but you can't send player links through SendChatMessage either.)
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.

Last edited by Phanx : 03-22-14 at 09:38 PM.
  Reply With Quote
03-21-14, 04:27 PM   #6
Tactica
Not Amused
 
Tactica's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2010
Posts: 96
Thank you so much! This loaded fine and in game menu commands were beautiful but when I set a banquet out in a party of two people (total) I got:

Date: 2014-03-21 18:19:50
ID: 2
Error occured in: Global
Count: 1
Message: ...rface\AddOns\ConjuredAnnouncer\ConjuredAnnouncer.lua line 108:
bad argument #3 to 'format' (string expected, got nil)
Debug:
[C]: ?
[C]: format()
...rface\AddOns\ConjuredAnnouncer\ConjuredAnnouncer.lua:108:
...rface\AddOns\ConjuredAnnouncer\ConjuredAnnouncer.lua:100
(tail call): ?
Locals:
After review of the specified lines 100 & 108 I am not sure what is wrong with them:

Code:
function Addon:COMBAT_LOG_EVENT_UNFILTERED(_, combatEvent, _, sourceGUID, sourceName, sourceFlags, _, destGUID, destName, destFlags, _, spellID, spellName)
        if not announceEvents[combatEvent] or not announceSpells[spellID] or bit.band(sourceGUID, FILTER_GROUP) == 0 then return end
       
        -- use this for cauldrons, they show up only for SPELL_CAST_START and have null for destName
        if not destName then
            dsetName = spellName
        end
       
        local message = format(MESSAGE_TEMPLATE, sourceName, destName)
EDIT:
Just tested some portals cast by another /party member and got the same error as above. I am liking this code but am such a noob at this lua I have searched and can't find the "missing string" in:

local message = format(MESSAGE_TEMPLATE, sourceName, destName)

Last edited by Tactica : 03-21-14 at 06:34 PM.
  Reply With Quote
03-21-14, 07:32 PM   #7
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Typo on line 105. Change dsetName to destName
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
03-21-14, 07:58 PM   #8
Tactica
Not Amused
 
Tactica's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2010
Posts: 96
Originally Posted by Seerah View Post
Typo on line 105. Change dsetName to destName
Fixed, now getting:
Message: ConjuredAnnouncer\ConjuredAnnouncer-1.9.9.9.3.lua:112: attempt to perform arithmetic on local "lastTime" (a nil value)
Time: 03/21/14 21:53:13
Count: 1
Stack: (tail call): ?

Code:
local now = GetTime()
        local lastTime = lastAnnounced[message]
        if now - lastTime < 10 then
            return
        end
line 112: if now - lastTime < 10 then

should it be if now = lastTime < 10 then?

Last edited by Tactica : 03-21-14 at 08:03 PM.
  Reply With Quote
03-21-14, 08:10 PM   #9
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by Rakenaid View Post
should it be if now = lastTime < 10 then?
No, you're checking a variable there, not setting one. Change this:

Code:
if now - lastTime < 10 then
to this:

Code:
if lastTime and now - lastTime < 10 then
Also edited the code in my previous post with this and the other typo fix.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
03-21-14, 08:19 PM   #10
Tactica
Not Amused
 
Tactica's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2010
Posts: 96
Excellent! Now this is all great, but what about putting GetSpellLink in the message? What would I modify as this currently uses
Code:
.. TRADESKILL_LOG_THIRDPERSON ..
My previous version used the following for a link in the message:
Code:
..sourceName .. " has created " .. GetSpellLink(spellID)..
I attempted some changes with the following but it gives me an error on line 66 which is:
Code:
Addon:SetScript("OnEvent", function(self, event, ...) return self[event](self, ...) end)
The attempted changed to announce the conjured item as a clickable link:
Code:
 function Addon:COMBAT_LOG_EVENT_UNFILTERED(_, combatEvent, _, sourceGUID, sourceName, GetSpellLink, GetSpellLink, sourceFlags, _, destGUID, destName, destFlags, _, spellID, spellName)
        if not announceEvents[combatEvent] or not announceSpells[spellID] or bit.band(sourceGUID, FILTER_GROUP) == 0 then return end
       
        -- use this for cauldrons, they show up only for SPELL_CAST_START and have null for destName
        if not destName then
            destName = spellName
        end
       
        local message = format(MESSAGE_TEMPLATE, sourceName, GetSpellLink(spellID))
       
        local now = GetTime()
        local lastTime = lastAnnounced[message]
        if lastTime and now - lastTime < 10 then
            return
        end

Last edited by Tactica : 03-21-14 at 08:49 PM.
  Reply With Quote
03-21-14, 09:06 PM   #11
Tactica
Not Amused
 
Tactica's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2010
Posts: 96
When using the command /can rw to announce to Raid Warning I get the following error:
Message: ConjuredAnnouncer\ConjuredAnnouncer-1.9.9.9.3.lua:165: attempt to concatenate field "raidWarning" (a boolean value)
line165:
Code:
Addon:Print("Raid warning announcements " .. db.raidWarning and "ON" or "OFF")

Code:
        if command == "off" then
            db.enabled = false
            Addon:GROUP_ROSTER_UPDATE()
            Addon:Print("Announcements OFF. Type '/can on' to enable.")
        elseif command == "on" then
            db.enabled = true
            Addon:GROUP_ROSTER_UPDATE()
            Addon:Print("Announcements ON. Type '/can off' to disable.")
        elseif command == "party" then
            db.partyInRaid = not db.partyInRaid
            Addon:Print("Now announcing to " .. (db.partyInRaid and "party only" or "the entire raid") .. " while in a raid.")
        elseif command == "rw" then
            db.raidWarning = not db.raidWarning
            Addon:Print("Raid warning announcements " .. db.raidWarning and "ON" or "OFF")
Also would like to get the message to include a clickable link of the item conjured. Would I use something like:
Code:
.. GetSpellLink(spellID)..
So,
1) Would like to have spell/item linked in the message
2) Portals messages should be sent on SPELL_CAST_SUCCESS in case the person cancels the cast
3) Noodle Carts still seem to be an issue, but will look into it after I can fix the previous issues

Last edited by Tactica : 03-21-14 at 09:27 PM.
  Reply With Quote
03-21-14, 10:17 PM   #12
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by Rakenaid View Post
The attempted changed to announce the conjured item as a clickable link:
Code:
        local message = format(MESSAGE_TEMPLATE, sourceName, GetSpellLink(spellID))
That looks fine, though you may want to include a fallback in case the link fails to be retrieved:

Code:
        local message = format(MESSAGE_TEMPLATE, sourceName, 
                GetSpellLink(spellID) or spellName)
Originally Posted by Rakenaid View Post
When using the command /can rw to announce to Raid Warning I get the following error:
Code:
Addon:Print("Raid warning announcements " .. (db.raidWarning and "ON" or "OFF"))
Originally Posted by Rakenaid View Post
2) Portals messages should be sent on SPELL_CAST_SUCCESS in case the person cancels the cast
Just change SPELL_CAST_START to SPELL_CAST_SUCCESS. I didn't have time to actually go test, but I can't think of any reason why a spell that fires a START event wouldn't also fire a SUCCESS event.

Originally Posted by Rakenaid View Post
Noodle Carts still seem to be an issue, but will look into it after I can fix the previous issues
Most likely you're using the wrong spell IDs. Try using a print in your combat log event handler to find the right ones:

Code:
function Addon:COMBAT_LOG_EVENT_UNFILTERED(_, combatEvent, _, sourceGUID, sourceName, sourceFlags, _, destGUID, destName, destFlags, _, spellID, spellName)
    if strfind(spellName, "Noodle Cart") then print(sourceName, destName, spellID, spellName) end
    if not announceEvents[combatEvent] or not announceSpells[spellID] or bit.band(sourceGUID, FILTER_GROUP) == 0 then return end
Then go use a Noodle Cart (or wait for someone nearby to use one) and change the spell ID in your table to match the one that was printed.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
03-22-14, 06:48 AM   #13
Tactica
Not Amused
 
Tactica's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2010
Posts: 96
Got it working with everything including the noodle carts!

Now the only "issue" I have is there is a period after the spelllink. Is there anyway to remove that period and change "creates" to "has created"?

>>>Rakenaid creates [item].<<<
to
>>>Rakenaid has created [item]<<<

Everything else seems to work, I will test more today in lfd/lfr/bgs.

EDIT:
Works in LFD/LFR/PVP however the player must /can party in order to announce to raid/pvp. Is there any way the addon can autodetect if the player is in a party/Instance/Raid/BG? That way the addon will continue announcing unless commanded otherwise

EDIT:
Also noticed that the addon loads in an "off" state. I tested in a party of two with portals, and nothing printed until I sent the command /can on. Would like to load the addon as ON upon login. I will look at the code later and see if I can fix that. It would be nice if the /can /cann responded with an "Announcer State: ON/OFF like the old code or better yet "Announcer State: ON/OFF to Party/RW".

EDIT:
Attempted to add the Traveler's Tundra Mammoth, confirmed spellid but no message. Would be nice since I see so many using this mount for repair in lieu of jeeves nowadays.

Last edited by Tactica : 03-22-14 at 04:59 PM.
  Reply With Quote
03-22-14, 05:44 PM   #14
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by Rakenaid View Post
Now the only "issue" I have is there is a period after the spelllink. Is there anyway to remove that period and change "creates" to "has created"?
Just change:
Code:
local MESSAGE_TEMPLATE = ">>> " .. TRADESKILL_LOG_THIRDPERSON .. " <<<"
to:
Code:
local MESSAGE_TEMPLATE = ">>> %s has created %s <<<"
Since it's no longer using a predefined global string, you'll have to add translations later if you want your addon to be useful for non-English players.

Originally Posted by Rakenaid View Post
Works in LFD/LFR/PVP however the player must /can party in order to announce to raid/pvp. Is there any way the addon can autodetect if the player is in a party/Instance/Raid/BG? That way the addon will continue announcing unless commanded otherwise
It already checks for LFD/LFR/PVP first and, if the player is in one of those types of instances, sends to the INSTANCE_CHAT channel. Otherwise, if the player is in a raid and did not enable the "party only" option, it announces to the RAID channel. Otherwise, if the player is in a group, it announces to the PARTY channel. If you're seeing some other behavior, or want some other behavior, please be more specific.

Originally Posted by Rakenaid View Post
Also noticed that the addon loads in an "off" state. I tested in a party of two with portals, and nothing printed until I sent the command /can on. Would like to load the addon as ON upon login.
Oh, yeah, I forgot about that. Replace whatever was in your TOC file's SavedVariables line with just "ConjuredAnnouncerDB". The settings are now stored all in a table, instead of in individual variables.

However, the default state should be "on", but only if you're in a group; it should automatically start listening to combat events if it's enabled when you join a group. If you want it to listen to combat events even while solo, remove the IsInGroup check from the GROUP_ROSTER_UPDATE event handler.

Originally Posted by Rakenaid View Post
It would be nice if the /can /cann responded with an "Announcer State: ON/OFF like the old code or better yet "Announcer State: ON/OFF to Party/RW".
Code:
        Addon:Print(Current state is " .. (db.enable and "|cff7fff7fON|" or "|cff7f7f7fOFF|r"))
        print("    Use /can or /cann with the following commands:")
        print("  |cffffff7f on |r- enable announcements")
        print("  |cffffff7f off |r- disable announcements")
        print("  |cffffff7f party |r- announce only to your party in a raid " .. (db.party and "(|cff7fff7fON|)" or "(|cff7f7f7fOFF|r)"))
        print("  |cffffff7f rw |r- announce to raid warning when possible " .. (db.rw and "(|cff7fff7fON|)" or "(|cff7f7f7fOFF|r)"))
        print("  |cffffff7f help |r- shows this list of commands")
It will include the current enabled state on the first line, and the current party/rw settings on their specific lines.

Originally Posted by Rakenaid View Post
Attempted to add the Traveler's Tundra Mammoth, confirmed spellid but no message. Would be nice since I see so many using this mount for repair in lieu of jeeves nowadays.
It's probably using a different event. Add the combat event to the debug print:

Code:
if strfind(spellName, "Tundra Mammoth") then print(combatEvent, sourceName, destName, spellID, spellName) end
and then add that to the list of combat events for the addon to respond to.

I've updated the code in my last post to incorporate most of these changes; it doesn't include the debug print for finding spell IDs, and it still only activates while in a group.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.

Last edited by Phanx : 03-22-14 at 05:49 PM.
  Reply With Quote
03-22-14, 06:39 PM   #15
Tactica
Not Amused
 
Tactica's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2010
Posts: 96
Thanks Phanx for all the help...

Originally Posted by Phanx View Post
Code:
        Addon:Print(Current state is " .. (db.enable and "|cff7fff7fON|" or "|cff7f7f7fOFF|r"))
        print("    Use /can or /cann with the following commands:")
        print("  |cffffff7f on |r- enable announcements")
        print("  |cffffff7f off |r- disable announcements")
        print("  |cffffff7f party |r- announce only to your party in a raid " .. (db.party and "(|cff7fff7fON|)" or "(|cff7f7f7fOFF|r)"))
        print("  |cffffff7f rw |r- announce to raid warning when possible " .. (db.rw and "(|cff7fff7fON|)" or "(|cff7f7f7fOFF|r)"))
        print("  |cffffff7f help |r- shows this list of commands")

Code:
function Addon:COMBAT_LOG_EVENT_UNFILTERED(_, combatEvent, _, sourceGUID, sourceName, sourceFlags, _, destGUID, destName, destFlags, _, spellID, spellName)
        if strfind(spellName, "Traveler's Tundra Mammoth") then print(combatEvent, sourceName, destName, spellID, spellName) end
		if not announceEvents[combatEvent] or not announceSpells[spellID] or bit.band(sourceGUID, FILTER_GROUP) == 0 then return end
This returns an error: expected ) near state. Not a pressing issue but will work on it. Currently loading and rewriting. Will post/edit findings.
This didn't print anything for me. Will reference the other strfind later.

Last edited by Tactica : 03-22-14 at 06:56 PM.
  Reply With Quote
03-22-14, 06:46 PM   #16
Dridzt
A Pyroguard Emberseer
 
Dridzt's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2005
Posts: 1,360
Originally Posted by Rakenaid View Post
Thanks Phanx for all the help...



This returns an error: expected ) near state. Not a pressing issue but will work on it. Currently loading and rewriting. Will post/edit findings.
Addon:Print("Current state is " .. (db.enable and "|cff7fff7fON|" or "|cff7f7f7fOFF|r")
  Reply With Quote
03-22-14, 07:09 PM   #17
Tactica
Not Amused
 
Tactica's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2010
Posts: 96
Originally Posted by Dridzt View Post
Addon:Print("Current state is " .. (db.enable and "|cff7fff7fON|" or "|cff7f7f7fOFF|r")
You mean :
Code:
 Addon:Print("Current state is " .. (db.enable and "|cff7fff7fON|" or "|cff7f7f7fOFF|r"))
REMAINING ISSUES:

1) Addon loads and upon /can returns that its state is ON when in fact it is not. When /can OFF is performed it returns Announcements OFF, but when I /can to check the state it declares it as ON.

2) the strng debug doesn't seem to work with the Traveler's Tundra Mammoth

Last edited by Tactica : 03-22-14 at 08:04 PM.
  Reply With Quote
03-22-14, 09:44 PM   #18
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by Rakenaid View Post
1) Addon loads and upon /can returns that its state is ON when in fact it is not. When /can OFF is performed it returns Announcements OFF, but when I /can to check the state it declares it as ON.
a) Are you in a group when you log in? If not, then "on" does not mean "watching for combat events to announce", it just means it will start doing that once you join a group. Since it doesn't announce to SAY or YELL, there is no point in having it watch the combat log (a fairly expensive activity) while you're not in a group. (And on second thought, none of the things it's announcing are things that happen in combat, so you can save a bunch of CPU time by unregistering in combat, too. I'll update the code and post a new version.)

b) Did you change the SavedVariables line in your TOC, and restart WoW?

Originally Posted by Rakenaid View Post
2) the strng debug doesn't seem to work with the Traveler's Tundra Mammoth
Go somewhere secluded (so as not to be spammed by other people's combat log activity) and type "/etrace", and then get on your mammoth. Look in the event trace window at the COMBAT_LOG_EVENT_UNFILTERED events, and find the one relevant to mounting your mammoth, then post it here if you need help incorporating it into the addon. I don't have one on the account I'm currently playing, so I can't check it myself.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
03-23-14, 10:00 AM   #19
Tactica
Not Amused
 
Tactica's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2010
Posts: 96
Originally Posted by Phanx View Post
a) Are you in a group when you log in? If not, then "on" does not mean "watching for combat events to announce", it just means it will start doing that once you join a group.


b) Did you change the SavedVariables line in your TOC, and restart WoW?



Go somewhere secluded (so as not to be spammed by other people's combat log activity) and type "/etrace", and then get on your mammoth. Look in the event trace window at the COMBAT_LOG_EVENT_UNFILTERED events, and find the one relevant to mounting your mammoth, then post it here if you need help incorporating it into the addon. I don't have one on the account I'm currently playing, so I can't check it myself.
Not in a group when I log in (of course) however even when I invite or am invited, or put in LFD/LFR, unless I send the command "/can on" nothing will print.

Checked toc and found "## SavedVariablesPerCharacter" and replaced that with "## SavedVariables: ConjuredAnnouncerDB" Restarted/reloaded and no change with the issue of have to command /can on after entering a group to get the announcements to work.

I personally don't have a mammoth either however a guildie helped me confirm the horde spell id was in fact correct: 61447.

Last edited by Tactica : 03-23-14 at 11:23 AM.
  Reply With Quote
03-23-14, 07:21 PM   #20
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by Rakenaid View Post
I personally don't have a mammoth either however a guildie helped me confirm the horde spell id was in fact correct: 61447.
Yes, that's why I wanted the entire event trace; most likely, the problem is that summoning a mammoth triggers a different sub-event than the ones you're listening for, and you need to add the additional sub-event to the "announceEvents" table.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » Class colors in message output

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off