Hi guys,
today i need your help
I need in my addon an slash command to de- and activate the scanning of my addon.
Can anyone help please? Thanks a lot!!!
Lua Code:
NPCSilencerData = {}
-- Default Settings
NPCSilencerData.Enabled = nil
NPCSILENCER_DEBUG = "Debug"
NPCSILENCER_ERROR = "Error"
NPCSILENCER_ISNOWLOADED = "is now loaded!"
NPCSILENCER_TITLE = "NPC-Silencer"
NPCSILENCER_VERSION = "50400.244"
function npc_silencerFrame_OnLoad(self)
DEFAULT_CHAT_FRAME:AddMessage("|cffff2020NPC-Silencer |rVersion "..NPCSILENCER_VERSION.." loaded.", 1, 1, 1, 1, 10)
DEFAULT_CHAT_FRAME:AddMessage("Please report non silenced npc's at [url]http://www.wowinterface.com[/url] - Please tell us the city and npcname like 'Topper McNapp in Stormwind', so we can add them to the next version. Thanks for your help!", 1, 1, 1, 1, 10)
self:RegisterEvent("ADDON_LOADED")
self:RegisterEvent("PLAYER_ENTERING_WORLD")
end
local tip = CreateFrame("GameTooltip")
tip.txt = tip:CreateFontString()
tip:AddFontStrings(tip.txt, tip:CreateFontString())
function tip:name(id)
tip:SetOwner(WorldFrame, "ANCHOR_NONE")
tip:SetHyperlink(("unit:0xF53%05X00000000"):format(id))
return tip:IsShown() and tip.txt:GetText()
end
-- the events we wish to apply our filter on
local events =
{
"CHAT_MSG_MONSTER_EMOTE",
"CHAT_MSG_MONSTER_PARTY",
"CHAT_MSG_MONSTER_SAY",
"CHAT_MSG_MONSTER_WHISPER",
"CHAT_MSG_MONSTER_YELL",
}
local database =
{
["2318"] = 1,
}
local ignore = {}
local rescan = {}
local function scanTable(tbl)
for npcid, _ in pairs(tbl) do
local npcname = tip:name(npcid)
if npcname then
ignore[npcname] = 1
rescan[npcid] = nil
else
rescan[npcid] = 1
end
end
end
scanTable(database)
local function filter(self, event, msg, sender, ...)
scanTable(rescan) -- we scan leftovers on filter triggers
return ignore[sender] and true or false
end
for _, event in pairs(events) do
ChatFrame_AddMessageEventFilter(event, filter)
end