Thread Tools Display Modes
04-21-14, 08:05 PM   #21
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Found the problem; apparently if you don't include the color code and brackets WoW rejects the spell link. This works:

Code:
local spellLink = "|cff71d5ff|Hspell:"..spellID.."|h["..spellName.."]|h|r"
On a side note, you should really enable some kind of error display while working with addon code. This problem could have been solved hours ago -- not to mention all the poor Prairie Dogs that wouldn't have gotten knives thrown at them -- if you'd been able to post an error message.
__________________
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 : 04-21-14 at 08:13 PM.
  Reply With Quote
04-21-14, 09:39 PM   #22
Tactica
Not Amused
 
Tactica's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2010
Posts: 96
Originally Posted by Phanx View Post
On a side note, you should really enable some kind of error display while working with addon code. This problem could have been solved hours ago -- not to mention all the poor Prairie Dogs that wouldn't have gotten knives thrown at them -- if you'd been able to post an error message.
Indeed I did have BugGrabber however StoptheSpam was blocking it's announcements! So the code fires for the items however it still fires third person when I personally throw down I Jeeves, i.e. Tactica has created [Jeeves].

Thanks again for all this help Phanx. I will continue work on this tomorrow!

Last edited by Tactica : 04-21-14 at 09:45 PM.
  Reply With Quote
04-22-14, 08:06 AM   #23
Tactica
Not Amused
 
Tactica's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2010
Posts: 96
Hey Phanx I have a couple questions for clarification:

1) I have run the code through several online "testing" sites since it is patch day and keep getting:
attempt to call global 'CreateFrame' (a nil value)
This has occurred since the original re-write and doesn't seem to present a problem in game. I notice it within other codes too however is this avoidable?

2) The same issue with[quote] local PLAYER_NAME, PLAYER_SERVER = UnitFullName("player")
attempt to call global 'UnitFullName'
Changing the order of this seems to fix the error. Last night I still had issues getting the messagesSelf to fire when I cast rather than the messages. When the servers are up I will continue working on this but I was just curious about the global nil errors.

Thanks!

Can only figure that it is still firing local messages rather than messagesSelf due to something I am not seeing below.

EDIT: When broadcasting to Raid, Raid Warning or Party while in a raid it posts both the messagesSelf and messages resulting in a double post. However when converted back to a party only the messages announcement is made.

Code:
local PLAYER_NAME, PLAYER_SERVER = UnitFullName("player")

function Addon:AnnounceSpell(unit, spellID, spellName)
	print("AnnounceSpell", unit, spellID, spellName)
	local casterName, casterServer = UnitFullName(unit)
	local spellLink = "|cff71d5ff|Hspell:"..spellID.."|h["..spellName.."]|h|r"

	local message
	if casterName == PLAYER_NAME and casterServer == PLAYER_SERVER then
		message = format(messagesSelf[ spells[spellID] ], spellLink)
	else
		message = format(messages[ spells[spellID] ], casterName, spellLink)
	end

	local now = GetTime()
	if (lastAnnounced[message] or 0) > (now - 5) then return print("Too soon!") end
	lastAnnounced[message] = now

	local channel
	if db.raidWarning and IsInRaid() and (UnitIsGroupLeader("player") or UnitIsGroupAssistant("player")) then
		channel = "RAID_WARNING"
	elseif IsInGroup(LE_PARTY_CATEGORY_INSTANCE) then
		channel = "INSTANCE_CHAT"
	elseif IsInRaid() and not db.partyInRaid then
		channel = "RAID"
	elseif IsInGroup() then
		channel = "PARTY"
	else
		-- nobody to announce to, quit
		return print("So ronery!")
	end

	print("SendChatMessage", channel, message)
	SendChatMessage(message, channel)
end

Last edited by Tactica : 04-22-14 at 04:34 PM.
  Reply With Quote
04-22-14, 05:14 PM   #24
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Those errors are meaningless; they only serve to indicate that whatever online "testing" tool you're using does not support the WoW API, which makes it pretty much useless for WoW addon development. You should be seeing the same complaint from it about every other API function you're calling, too.

The duplication likely stems from the fact that while you're in a raid, UNIT_SPELLCAST_SUCCEEDED will fire for your spellcasts twice -- once for the "player" unit, and once for whichever "raidN" unit belongs to you.

This should solve that problem, along with the potential for the same problem happening if you're targeting yourself or another player when they cast a tracked spell:

Code:
-- Put this at the top with the other variable declarations (eg. "lastAnnounced"):
local ignoreUnits = { target = true }

-- Modify these functions as indicated:
function Addon:GROUP_ROSTER_UPDATE()
	print("GROUP_ROSTER_UPDATE", db.enabled and IsInGroup())
	if db.enabled and IsInGroup() then
		self:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED")
		ignoreUnits.player = IsInRaid()
	else
		self:UnregisterEvent("UNIT_SPELLCAST_SUCCEEDED")
	end
end

function Addon:UNIT_SPELLCAST_SUCCEEDED(unit, spellName, _, _, spellID)
	if spells[spellID] and not ignoreUnits[unit] then
		print("UNIT_SPELLCAST_SUCCEEDED", unit, spellName, spellID)
		self:AnnounceSpell(unit, spellID, spellName)
	end
end
__________________
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
04-22-14, 05:26 PM   #25
Tactica
Not Amused
 
Tactica's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2010
Posts: 96
This did fix the double posting while in a raid group. Announcements fire but while in a party (not raid) the messagesSelf don't fire. Everything works perfect except for party messageself announcements.
  Reply With Quote
04-22-14, 06:15 PM   #26
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Does it show the messages version for your own spells while in a party, or nothing at all?

Change the debug print in the GROUP_ROSTER_UPDATE function to this:
Code:
print("GROUP_ROSTER_UPDATE", db.enabled and IsInGroup(), IsInRaid())
... and let me know what it says when you join a party. Also, does it show the UNIT_SPELLCAST_SUCCEEDED debug print while you're in a party, or not?
__________________
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
04-22-14, 06:30 PM   #27
Tactica
Not Amused
 
Tactica's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2010
Posts: 96
When joining a group:
GROUP_ROSTER_UPDATE true false

When leaving a group:
GROUP_ROSTER_UPDATE false false
Also, does it show the UNIT_SPELLCAST_SUCCEEDED debug print while you're in a party, or not?
It does show while in a party:
GroupRosterUpdate true false
UNIT_SPELLCAST_SUCCEEDED player Portal: Orgimmar 11417
AnnounceSpell player 11417
SendChatMessage PARTY {rt1} Tactica has opened a [Portal: Orgrimmar] {rt1}
While in a raid:
GroupRosterUpdate true true
UNIT_SPELLCAST_SUCCEEDED raid1 Portal: Orgimmar 11417
AnnounceSpell raid1 player 11417
SendChatMessage RAID I have opened a [Portal: Orgrimmar]
Yes it shows the local messages version of the portals that I cast:

Tactica has opened a [Portal: Orgrimmar]
But in a raid group the announcement fires properly:

I have opened a [Portal: Orgrimmar]
Added the debug line and will do some rep farm in the meantime!

Last edited by Tactica : 04-23-14 at 12:04 AM. Reason: raid1 player
  Reply With Quote
04-22-14, 09:37 PM   #28
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
WTF... "raid1player" is not a real unit token, how on earth is that happening?!

In any case, it occurred to me that now that you're just passing the unit token to the announce function, there's a better way to check whether the unit is yourself:

Code:
function Addon:AnnounceSpell(unit, spellID, spellName)
	print("AnnounceSpell", unit, spellID, spellName)
	local spellLink = "|cff71d5ff|Hspell:"..spellID.."|h["..spellName.."]|h|r"

	local message
	if UnitIsUnit("player", unit) then
		message = format(messagesSelf[ spells[spellID] ], spellLink)
	else
		message = format(messages[ spells[spellID] ], (UnitName(unit)), spellLink)
	end
Then you can get rid of the PLAYER_NAME and PLAYER_SERVER variables entirely, as well as the "ignoreUnits" 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
04-22-14, 10:17 PM   #29
Tactica
Not Amused
 
Tactica's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2010
Posts: 96
Originally Posted by Phanx View Post
WTF... "raid1player" is not a real unit token, how on earth is that happening?
That would be a mere typo since I copied the debug prints from chat manually.

EDIT: Seems to be working now. Will test more tomorrow.

EDIT: One last question and idea. While running a random someone popped a Weighted Lantern. Was wondering how could I incorporate a spell id announcement to print just to the chat frame?

EDIT: Confirmed everything is a go! Thanks so much Phanx. I know I'm an idiot when it comes to this but I consider this practice towards my learning lua.

Thanks for the help!

Last edited by Tactica : 04-23-14 at 01:19 PM.
  Reply With Quote
04-25-14, 11:35 AM   #30
Tactica
Not Amused
 
Tactica's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2010
Posts: 96
I have been trying to add a print announcement if one is solo, and a /command to print if in a group/raid . I am at a loss...not sure which function to use to use here.

1)Should I use GetNumGroupMembers() or keep IsInGroup() to check if I am solo.
2) How would I call for the "channel" to print?
3) Would db.enabled or Addon:GROUP_ROSTER_UPDATE() be needed in the slashcommand function?

Code:
local channel
	if db.raidWarning and IsInRaid() and (UnitIsGroupLeader("player") or UnitIsGroupAssistant("player")) then
		channel = "RAID_WARNING"
	elseif IsInGroup(LE_PARTY_CATEGORY_INSTANCE) then
		channel = "INSTANCE_CHAT"
	elseif IsInRaid() and not db.partyInRaid then
		channel = "RAID"
	elseif IsInGroup() then
		channel = "PARTY"
	elseif GetNumPartyMembers() == 0 then
		channel = "SAY" --used for testing, should be print in the end
	else
		-- nobody to announce to, quit
		return
	end
	SendChatMessage(message, channel)
end
elseif not IsInGroup()?

SlashCommands
Code:
elseif command == "print" then
Addon:Print("Now printing announcements")
else
Sorry guys I am just starting learning lua from scratch and just got the book...sry to be such a pain
  Reply With Quote
04-25-14, 05:26 PM   #31
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
IsInGroup() accomplishes the same thing as GetNumGroupMembers() > 0 but without the additional comparison operator, so there's no reason to use the latter method.

However, the code you posted already includes a "not in group" condition -- that's the part where it currently just returns out, assuming you don't want to announce while solo. Just add your print there:

Code:
	elseif IsInGroup() then
		channel = "PARTY"
	else
		-- nobody to announce to, quit
		if db.printSolo then
			self:Print(message)
		end
		return
	end
	SendChatMessage(message, channel)
end
Code:
	elseif command == "rw" then
		db.raidWarning = not db.raidWarning
		Addon:Print("Raid warning announcements " .. (db.raidWarning and ON or OFF))
	elseif command == "solo" then
		db.printSolo = not db.printSolo
		Addon:Print("Solo announcements " .. (db.printSolo and ON or OFF))
	else
		Addon:Print("Current state is " .. (db.enabled and ON or OFF))
		print("  Use /can with the following commands:")
		print("  |cffffff7fon|r - enable announcements")
		print("  |cffffff7foff|r - disable announcements")
		print("  |cffffff7fparty|r - announce only to |cff87cefa/party|r in a raid (" .. (db.partyInRaid and ON or OFF) .. ")")
		print("  |cffffff7frw|r - announce to raid warning when possible (" .. (db.raidWarning and ON or OFF) .. ")")
		print("  |cffffff7fsolo|r - announce to self when solo (" .. (db.printSolo and ON or OFF) .. ")")
	end
__________________
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
04-25-14, 07:04 PM   #32
Tactica
Not Amused
 
Tactica's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2010
Posts: 96
Could you detail or link a reference to more details regarding these db functions? I understand their purpose but not their creation.
Originally Posted by Phanx View Post
... assuming you don't want to announce while solo. Just add your print there:
Correct, (my wording was confusing) just the ability to print while in a gorup without announcing so I can see the items cast without spamming the group.
Code:
	elseif IsInGroup() then
		channel = "PARTY"
	else if db.printSolo then		
		self:print(message)
	end
		return
	end
	SendChatMessage(message, channel)
end
Added without error (me thinks using Sublime Text 2 with WoWLua) but I'm not getting a print message under any condition (party, raid, solo, db.enabled/disabled or db.printSolo.

I can't thank you enough for all this help Phanx. Usually people would flame by now...

Last edited by Tactica : 04-25-14 at 07:14 PM.
  Reply With Quote
04-26-14, 08:02 AM   #33
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by Tactica View Post
Could you detail or link a reference to more details regarding these db functions? I understand their purpose but not their creation.
What do you mean by "db functions"?

Originally Posted by Tactica View Post
Correct, (my wording was confusing) just the ability to print while in a gorup without announcing so I can see the items cast without spamming the group.
Yes, that's what the code I posted will do.

What you posted, however, is not a good way to write this -- while it's technically no different than what I wrote, the way you've formatted makes it extremely difficult to read (note that the "end" is on the same level as the next "end" even though it should be one level in) and on first glance looks like a syntax error (since "elseif" is one word). Use linebreaks and consistent indentation to avoid confusion:

Code:
	elseif IsInGroup() then
		channel = "PARTY"
	else -- this stays where it was
		if db.printSolo then -- this block is added INSIDE the "else...end" block
			self:print(message)
		end -- and it also ENDS inside the "else...end" block
		return -- this is on the SAME level as the "end" above it
	end
	SendChatMessage(message, channel)
end
Originally Posted by Tactica View Post
Added without error ... but I'm not getting a print message under any condition (party, raid, solo, db.enabled/disabled or db.printSolo.
Are you sure about that "without error" part? Unless you've changed the code from what was last posted, "self:Print" needs to be written with a capital "P" -- not "selfrint" with a lowercase "p". Lua is case-sensitive, so "Print" and "print" are not the same thing. In fact, if you really hate yourself, you can name all your variables like "aaa", "Aaa", "aAa", "aaA", "AAa", "AaA", "aAA", "AAA" and it will work, because those are all (as far as Lua is concerned) totally different, but I wouldn't recommend it.
__________________
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
04-26-14, 09:01 AM   #34
Tactica
Not Amused
 
Tactica's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2010
Posts: 96
Red face

Originally Posted by Phanx View Post
Yes, that's what the code I posted will do.

Code:
	elseif IsInGroup() then
		channel = "PARTY"
	else -- this stays where it was
		if db.printSolo then -- this block is added INSIDE the "else...end" block
			self:print(message)
		end -- and it also ENDS inside the "else...end" block
		return -- this is on the SAME level as the "end" above it
	end
	SendChatMessage(message, channel)
end
Are you sure about that "without error" part? Unless you've changed the code from what was last posted, "self:Print" needs to be written with a capital "P" -- not "selfrint" with a lowercase "p".
Changed selfrint(message) to self:Print(message) but still no prints coming up under any condition, no errors. I check to make sure everything matched.../cry:
Code:
	elseif IsInGroup() then
		channel = "PARTY"
	else 		
		if db.printSolo then -- this block is added INSIDE the "else...end" block
			self:Print(message)
		end -- and it also ENDS inside the "else...end" block
		return
	end
	SendChatMessage(message, channel)
end
Originally Posted by Phanx View Post
What do you mean by "db functions"?
db.raidWarning, db.partyInRaid, db.printSolo, where are they derived from?
  Reply With Quote
04-26-14, 10:27 PM   #35
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
"db.printSolo" is a table lookup. "db" is a local alias for your global saved variables table, and "printSolo" is a key whose value the lookup retrieves. If you have never typed "/can solo" then that value is nil because no such key exists. When you type "/can solo", the value of "db.printSolo" is set to "not db.printSolo".

In Lua, "nil" and "false" are both equivalent to "no" and everything else is equivalent to "yes", so the first time you type this command, "not db.printSolo" is really "not nil" which turns "no" into "yes" and sets "db.printSolo" to "true". In the future, it simply toggles between "true" and "false" each time you type it, and that value is stored in your saved variables.

As a result of how this works, you only need to include default values for settings whose values aren't booleans (eg. they are strings or numbers) or settings whose boolean values you want to be "true" by default.

This is also why you shouldn't bother checking "if value == true" or "if value ~= nil" unless you actually care that the value is "true" instead of just "any extant value" or "nil" instead of "nil or false" -- just checking "if value" and "if not value" will yield the same results and is faster.

I need to go run some errands, but I'll look at the actual code when I get back.
__________________
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
04-27-14, 06:04 AM   #36
Tactica
Not Amused
 
Tactica's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2010
Posts: 96
Originally Posted by Phanx View Post
"db.printSolo" is a table lookup. "db" is a local alias for your global saved variables table, and "printSolo" is a key whose value the lookup retrieves.
Thanks! Will do more reading since I did not know where to start looking regarding that in the WoWAPI.
  Reply With Quote
04-27-14, 10:28 PM   #37
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
You probably won't find much on that topic in anything WoW-specific, as tables are simply part of the Lua programming language, like functions and variables.

http://www.lua.org/pil/2.5.html
http://lua-users.org/wiki/TablesTutorial
__________________
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
04-27-14, 11:10 PM   #38
Tactica
Not Amused
 
Tactica's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2010
Posts: 96
Originally Posted by Phanx View Post
You probably won't find much on that topic in anything WoW-specific, as tables are simply part of the Lua programming language, like functions and variables.
Thanks for the links!

Originally Posted by Phanx View Post
I need to go run some errands, but I'll look at the actual code when I get back.
Still no print messages. Everything else is peachy:
Code:
local messages = {
	["FEAST"]  = "{rt1} %s has cooked %s",
	["MOUNT"]  = "%s has cast %s",
	["PORTAL"] = "{rt1} %s has opened a %s {rt1}",
	["REPAIR"] = "{rt1} %s has placed %s {rt1}",
	["SPELL"]  = "{rt1} %s has created %s {rt1}",
	["SOULWELL"] = "{rt1} %s has cast %s {rt1}",
	["TABLE"] = "{rt1} %s has cast %s {rt1}",
	["LIGHTWELL"] = "{rt1} %s has cast %s {rt1}",
}

local messagesSelf = {
	["FEAST"]  = "%s here!",
	["MOUNT"]  = "%s here!",
	["PORTAL"] = "%s here!",
	["REPAIR"] = "%s here!",
	["SPELL"]  = "%s here!",
	["SOULWELL"] = "%s here!",
	["TABLE"] = "Mage cookies here!",
	["LIGHTWELL"] = "%s here!",
}

local spells = {
	-- ENGINEERING/PROFESSION ITEMS
	[67826]  = "SPELL", -- Jeeves
	[54711]  = "SPELL", -- Scrapbot
	[22700]  = "SPELL", -- Field Repair Bot 74A
	[44389]  = "SPELL", -- Field Repair Bot 110G
	[127129] = "SPELL", -- Blingtron 4000
	[126459] = "SPELL", -- Blingtron 4000
	[54710]  = "SPELL", -- MOLL-E
	[126462] = "SPELL", -- Thermal Anvil

	-- SPELLS
	[92824]  = "SPELL", -- Ritual of Refreshment
	[43987]  = "SPELL", -- Refreshment Portal
	[698]    = "SPELL", -- Ritual of Summoning
	[29893]  = "SOULWELL", -- Ritual of Souls (Soulwell)
	[126135] = "LIGHTWELL", -- Lightwell
	[724]    = "LIGHTWELL", -- Lightwell (Glyphed)

	-- MOUNTS (for testing prposes)
	[75973]  = "MOUNT", -- X-53 Touring Rocket

	-- GUILD MISC
	[83958]  = "SPELL", -- Mobile Banking
	[92396]  = "SPELL", -- Guild Page (Horde)
	[92395]  = "SPELL", -- Guild Page (Alliance)
	[92398]  = "SPELL", -- Guild Herald (Horde)
	[92397]  = "SPELL", -- Guild Herald (Alliance)
	[90633]  = "SPELL", -- Battle Standard of Coordination
	[90631]  = "SPELL", -- Battle Standard of Coordination

  --VANITY/TCG ITEMS/MISC
	[42753]  = "FEAST", -- Goblin Gumbo Kettle
	[45103]  = "FEAST", -- Romantic Picnic Basket

	--CAULDRONS
	[92649]  = "FEAST", -- Cauldron of Battle
	[92712]  = "FEAST", -- Big Cauldron of Battle
	[41458]  = "FEAST", -- Cauldron of Major Arcane Protection
	[41500]  = "FEAST", -- Cauldron of Major Fire Protection
	[41501]  = "FEAST", -- Cauldron of Major Frost Protection

	--FEASTS/BANQUETS/NOODLE CARTS
	[104958] = "FEAST", -- Pandaren Banquet
	[126492] = "FEAST", -- Banquet of the Grill
	[126494] = "FEAST", -- Great Banquet of the Grill
	[126501] = "FEAST", -- Banquet of the Oven
	[126502] = "FEAST", -- Great Banquet of the Oven
	[126504] = "FEAST", -- Great Banquet of the Brew
	[126498] = "FEAST", -- Great Banquet of the Pot
	[126500] = "FEAST", -- Great Banquet of the Steamer
	[126496] = "FEAST", -- Great Banquet of the Wok
	[105193] = "FEAST", -- Great Pandaren Banquet
	[126503] = "FEAST", -- Banquet of the Brew
	[126497] = "FEAST", -- Banquet of the Pot
	[126499] = "FEAST", -- Banquet of the Steamer
	[126495] = "FEAST", -- Banquet of the Wok
	[87915]  = "FEAST", -- Goblin Barbecue Feast
	[87916]  = "FEAST", -- Goblin Barbecue Feast
	[87644]  = "FEAST", -- Seafood Magnifique Feast
	[87643]  = "FEAST", -- Broiled Dragon Feast
	[146936] = "FEAST", -- Noodle Cart
	[146933] = "FEAST", -- Noodle Cart
	[146937] = "FEAST", -- Deluxe Noodle Cart
	[145169] = "FEAST", -- Deluxe Noodle Cart
	[146938] = "FEAST", -- Pandaren Treasure Noodle Cart
	[57426]  = "FEAST", -- Fish Feast
	[57301]  = "FEAST", -- Great Feast

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

------------------------------------------------------------------------
-- VARIABLES

local ADDON_NAME, namespace = ...
local db
local lastAnnounced = {}

------------------------------------------------------------------------
-- ADDON

local Addon = CreateFrame("Frame", ADDON_NAME)
Addon:SetScript("OnEvent", function(self, event, ...) return self[event](self, ...) end)
Addon:RegisterEvent("ADDON_LOADED")

function Addon:Print(message)
	DEFAULT_CHAT_FRAME:AddMessage("|cff7f7fff[Conjured Announcer]|r " .. message)
end

function Addon:AnnounceSpell(unit, spellID, spellName)
	local spellLink = "|cff71d5ff|Hspell:"..spellID.."|h["..spellName.."]|h|r"

	local message
	if UnitIsUnit("player", unit) then
		message = format(messagesSelf[ spells[spellID] ], spellLink)
	else
		message = format(messages[ spells[spellID] ], (UnitName(unit)), spellLink)
	end

	local now = GetTime()
	if (lastAnnounced[message] or 0) > (now - 5) then return end
	lastAnnounced[message] = now

	local channel
	if db.raidWarning and IsInRaid() and (UnitIsGroupLeader("player") or UnitIsGroupAssistant("player")) then
		channel = "RAID_WARNING"
	elseif IsInGroup(LE_PARTY_CATEGORY_INSTANCE) then
		channel = "INSTANCE_CHAT"
	elseif IsInRaid() and not db.partyInRaid then
		channel = "RAID"
	elseif IsInGroup() then
		channel = "PARTY"
	else if db.printSolo then		
		self:print(message)
	end
		return
	end
	SendChatMessage(message, channel)
end

------------------------------------------------------------------------
-- EVENT HANDLERS

function Addon:ADDON_LOADED(name)
	if name ~= ADDON_NAME then return end
	if not ConjuredAnnouncerDB then
		ConjuredAnnouncerDB = {
			enabled = true,
			partyInRaid = false,	
			raidWarning = true,
		}
		self:Print("Welcome! Type /can for options.")
	end
	db = ConjuredAnnouncerDB
	self:RegisterEvent("GROUP_ROSTER_UPDATE")
end

function Addon:GROUP_ROSTER_UPDATE()
	if db.enabled and IsInGroup() then
		self:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED")
	else
		self:UnregisterEvent("UNIT_SPELLCAST_SUCCEEDED")
	end
end

function Addon:UNIT_SPELLCAST_SUCCEEDED(unit, spellName, _, _, spellID)
	if spells[spellID] then
		self:AnnounceSpell(unit, spellID, spellName)
	end
end

------------------------------------------------------------------------
-- SLASH COMMAND

local ON = "|cff7fff7fON|"
local OFF = "|cff7f7f7fOFF|r"

SLASH_CONJUREDANNOUNCER1 = "/can"

SlashCmdList["CONJUREDANNOUNCER"] = function(input)
	local command, args = strsplit(" ", input or "", 2)
	command = strlower(command)
	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 "|cff87cefa/party only|r" or "|cffff0000/ra|r") .. " while in a raid group.")
	elseif command == "rw" then
		db.raidWarning = not db.raidWarning
		Addon:Print("Raid warning announcements " .. (db.raidWarning and ON or OFF))
	elseif command == "print" then
		db.printSolo = not db.printSolo
		Addon:Print("Print solo announcements " .. (db.printSolo and ON or OFF))
	else	
		Addon:Print("Current state is " .. (db.enabled and ON or OFF))
		print("  Use /can with the following commands:")
		print("  |cffffff7fon|r - enable announcements")
		print("  |cffffff7foff|r - disable announcements")
		print("  |cffffff7fparty|r - announce only to |cff87cefa/party|r in a raid (" .. (db.partyInRaid and ON or OFF) .. ")")
		print("  |cffffff7frw|r - announce to raid warning when possible (" .. (db.raidWarning and ON or OFF) .. ")")
		print("  |cffffff7fprint|r - print announcements when solo (" .. (db.printSolo and ON or OFF) .. ")")
	end
end
  Reply With Quote
04-28-14, 04:18 AM   #39
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Found the problem; I forgot to change the UNIT_SPELLCAST_SUCCEEDED register/unregister check to also check for the new option. Also fixed/improved a few other things. Additions and changes are marked with "ADDED" and "CHANGED" comments.

http://www.wowace.com/paste/9868/
__________________
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
04-28-14, 06:35 AM   #40
Tactica
Not Amused
 
Tactica's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2010
Posts: 96
Originally Posted by Phanx View Post
Found the problem; I forgot to change the UNIT_SPELLCAST_SUCCEEDED register/unregister check to also check for the new option. Also fixed/improved a few other things. Additions and changes are marked with "ADDED" and "CHANGED" comments.

http://www.wowace.com/paste/9868/
Thanks!
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » Message output based on local spell


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