Thread Tools Display Modes
09-19-13, 02:38 AM   #1
Broessel01
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: May 2008
Posts: 15
implementing slash commands for (de)activating

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:
  1. NPCSilencerData = {}
  2.  
  3. -- Default Settings
  4. NPCSilencerData.Enabled = nil
  5. NPCSILENCER_DEBUG = "Debug"
  6. NPCSILENCER_ERROR = "Error"
  7. NPCSILENCER_ISNOWLOADED = "is now loaded!"
  8. NPCSILENCER_TITLE = "NPC-Silencer"
  9. NPCSILENCER_VERSION = "50400.244"
  10.  
  11. function npc_silencerFrame_OnLoad(self)
  12.     DEFAULT_CHAT_FRAME:AddMessage("|cffff2020NPC-Silencer |rVersion "..NPCSILENCER_VERSION.." loaded.", 1, 1, 1, 1, 10)
  13.     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)
  14.  
  15.     self:RegisterEvent("ADDON_LOADED")
  16.     self:RegisterEvent("PLAYER_ENTERING_WORLD")
  17. end
  18.  
  19.     local tip = CreateFrame("GameTooltip")
  20.     tip.txt = tip:CreateFontString()
  21.     tip:AddFontStrings(tip.txt, tip:CreateFontString())
  22.     function tip:name(id)
  23.     tip:SetOwner(WorldFrame, "ANCHOR_NONE")
  24.     tip:SetHyperlink(("unit:0xF53%05X00000000"):format(id))
  25.     return tip:IsShown() and tip.txt:GetText()
  26.     end
  27.  
  28.     -- the events we wish to apply our filter on
  29.     local events =
  30.         {
  31.             "CHAT_MSG_MONSTER_EMOTE",
  32.             "CHAT_MSG_MONSTER_PARTY",
  33.             "CHAT_MSG_MONSTER_SAY",
  34.             "CHAT_MSG_MONSTER_WHISPER",
  35.             "CHAT_MSG_MONSTER_YELL",
  36.         }
  37.  
  38.     local database =
  39.     {
  40.  
  41.     ["2318"] = 1,
  42.  
  43.     }
  44.  
  45.  
  46.     local ignore = {}
  47.     local rescan = {}
  48.  
  49.     local function scanTable(tbl)
  50.         for npcid, _ in pairs(tbl) do
  51.             local npcname = tip:name(npcid)
  52.             if npcname then
  53.                 ignore[npcname] = 1
  54.                 rescan[npcid] = nil
  55.             else
  56.                 rescan[npcid] = 1
  57.             end
  58.         end
  59.     end
  60.  
  61.     scanTable(database)
  62.  
  63.     local function filter(self, event, msg, sender, ...)
  64.         scanTable(rescan) -- we scan leftovers on filter triggers
  65.         return ignore[sender] and true or false
  66.     end
  67.  
  68.     for _, event in pairs(events) do
  69.         ChatFrame_AddMessageEventFilter(event, filter)
  70.     end
  Reply With Quote
09-19-13, 02:09 PM   #2
Tim
A Rage Talon Dragon Guard
 
Tim's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2008
Posts: 309
Here's a very basic way to accomplish what you want..

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"
    local NPCS_Enabled = true
     
    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 http://www.wowinterface.com - 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, ...)
            if not NPCS_Enabled then return end
            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

        SlashCmdList.SCAN = function()
        if NPCS_Enabled then
            NPCS_Enabled = false
            print("NPCSilencer Scanning: OFF.")
        else
            NPCS_Enabled = true
            print("NPCSilencer Scanning: ON.")
        end
        end
        SLASH_SCAN1 = "/npcs"
__________________
AddOns: Tim @ WoWInterface
Battle Tag: Mysterio#11164
Current PC Setup: PCPartPicker List
  Reply With Quote
09-20-13, 02:46 AM   #3
Broessel01
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: May 2008
Posts: 15
Hi Tim,

thanks for your help!
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » implementing slash commands for (de)activating


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