Thread Tools Display Modes
12-27-08, 11:25 PM   #1
aussiexile
A Deviate Faerie Dragon
Join Date: Dec 2008
Posts: 14
need help with ChatFrame_AddMessageEventFilter();

im trying to set up a simple filter so that if something is said in chat a response is given....now i can get that to work but the response shows up 4 times.....i would like it to just show once

This is the code im using
Code:
function myChatFilter(msg)
  if strfind(msg, "Test Msg") then
    SendChatMessage("Test Successful", "GUILD");
  end
end

ChatFrame_AddMessageEventFilter("CHAT_MSG_GUILD", myChatFilter);
any help would be awesome thanx

Aussiexile
  Reply With Quote
12-28-08, 06:10 PM   #2
Bangerz
A Fallenroot Satyr
 
Bangerz's Avatar
AddOn Author - Click to view addons
Join Date: May 2008
Posts: 27
ChatFrame_AddMessageEventFilter is called for every frame the message would appear in. So if you have 4 chat tabs with guild chat showing, it will be called 4 times.

Other chat addons can also potentially cause this, depending on how they work.

If you actually want to send a chat message in reply to seeing the trigger text, I would simply register CHAT_MSG_GUILD as an event, then use an event handler.
  Reply With Quote
12-28-08, 09:12 PM   #3
aussiexile
A Deviate Faerie Dragon
Join Date: Dec 2008
Posts: 14
how would i register it as an event? and then search for the trigger?

lol sorry for the inane questions but im very new to this and cant seem to find any good tutorials

**EDIT**

ok i got the register event part now i just need to search the text part lol

Last edited by aussiexile : 12-28-08 at 09:27 PM.
  Reply With Quote
12-28-08, 09:28 PM   #4
Bangerz
A Fallenroot Satyr
 
Bangerz's Avatar
AddOn Author - Click to view addons
Join Date: May 2008
Posts: 27
Inside your 'on enable' or 'on load' function. This registers the guild chat event, then sets up a script to call MyModName.EVENT on any registered event.

Code:
MyModName:RegisterEvent("CHAT_MSG_GUILD")
MyModName:SetScript("OnEvent", function(this, event, ...) MyModName[event](...) end)
This is your event handler:

Code:
function MyModName.CHAT_MSG_GUILD(msg, senderName, language)

   if strfind(msg, "Test Msg") then
          SendChatMessage("Test Successful", "GUILD");
   end

end
There's plenty of other ways to do this, but this way the mod requires only itself and you can easily add more events.

Last edited by Bangerz : 12-28-08 at 09:31 PM.
  Reply With Quote
12-28-08, 09:35 PM   #5
aussiexile
A Deviate Faerie Dragon
Join Date: Dec 2008
Posts: 14
do i copy the OnLoad stuff word for word (replaceing MyModName of course) or in the setScript part do i replace event with the event name?
  Reply With Quote
12-28-08, 09:57 PM   #6
aussiexile
A Deviate Faerie Dragon
Join Date: Dec 2008
Posts: 14
this is what i have so far:

XML
Code:
<Ui blah blah blah"> 
   <Script file="MyAddon.lua"/> 

   <Frame name="Addon" visible="true" parent="UIParent"> 
      <Scripts> 
         <OnLoad> 
            this:RegisterEvent("VARIABLES_LOADED"); 
            this:RegisterEvent("CHAT_MSG_GUILD")
            this:SetScript("OnEvent", function(this, event, ...) MyAddon[event](...) end)
         </OnLoad> 
         <OnEvent> 
            if (event == "VARIABLES_LOADED") then 
               Addon_OnLoad(); 
            end 
         </OnEvent> 
      </Scripts> 
   </Frame> 
</Ui>
LUA
Code:
dataArray = {}
    dataArray[0] = "Test 1"
    dataArray[1] = "Test 2"
    dataArray[2] = "Test 3"
    dataArray[3] = "Test 4"
    dataArray[4] = "Test 5"

function Addon_OnLoad()
    if( DEFAULT_CHAT_FRAME ) then
        DEFAULT_CHAT_FRAME:AddMessage("My Addon Version 1 Loaded.");
    end
    UIErrorsFrame:AddMessage("My Addon Version 1 Loaded.", 1.0, 1.0, 1.0, 1.0, UIERRORS_HOLD_TIME);
    
    SlashCmdList["MYADDONCOMMAND"] = Addon_Handler;
    SLASH_MYADDONCOMMAND1 = "/MyAddon";

end

function Addon_Handler()
    SendChatMessage(dataArray[math.random(getn(dataArray))], "GUILD");
end

function MyAddon.CHAT_MSG_GUILD(msg, senderName, language)

    if strfind(msg, string.upper("TEST MSG")) then
        SendChatMessage("Test Successful", "GUILD");
    end

end
when i run WoW i get this error

(string"Addon:OnLoad"):3: Attempt to index global 'MyAddon' (a nil value)

Last edited by aussiexile : 12-28-08 at 10:00 PM.
  Reply With Quote
12-28-08, 10:19 PM   #7
Bangerz
A Fallenroot Satyr
 
Bangerz's Avatar
AddOn Author - Click to view addons
Join Date: May 2008
Posts: 27
Not sure what's going on in your XML there :P Why are you making a visible frame?

Earlier, I was referring to your addon.lua OnEnable or OnLoad function, rather than your XML.

So in your XML you'd have
Code:
<Frame name="MyAddonName" hidden="true" parent="UIParent"> 
     <Scripts> 
        <OnLoad> 
                  MyAddonName:OnLoad()
        </OnLoad>  
     </Scripts> 
</Frame>


And in your .lua
Code:
function MyAddonName:OnLoad()

     MyModName:RegisterEvent("CHAT_MSG_GUILD")
     MyModName:SetScript("OnEvent", function(this, event, ...) MyModName[event](...) end)

end

function MyModName.CHAT_MSG_GUILD(msg, senderName, language)

   if strfind(msg, "Test Msg") then
          SendChatMessage("Test Successful", "GUILD");
   end

end

Originally Posted by aussiexile View Post
do i copy the OnLoad stuff word for word (replaceing MyModName of course) or in the setScript part do i replace event with the event name?
No, don't replace it. You could replace this entire function, but this way allows you to easily create new functions for each event.

Last edited by Bangerz : 12-28-08 at 10:34 PM.
  Reply With Quote
12-28-08, 10:21 PM   #8
aussiexile
A Deviate Faerie Dragon
Join Date: Dec 2008
Posts: 14
lol i was copying some tutorial.....but didnt continue with the buttons and back ground and such lol

ok...current iteration...


XML
Code:
<Ui xmlns="http://www.blizzard.com/wow/ui/"   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   xsi:schemaLocation="http://www.blizzard.com/wow/ui/"> 
    <Script file="AutoGratz.lua"/> 
    
    <Scripts> 
        <OnLoad> 
            AutoGratz:OnLoad()
        </OnLoad>
    </Scripts> 
</Ui>
LUA
Code:
dataArray = {}
    dataArray[0] = "Well Done...Well Done Indeed"
    dataArray[1] = "Good show old chap"
    dataArray[2] = "I say, that was jolly well done"
    dataArray[3] = "Spiffing job mate!"
    dataArray[4] = "Absolutely Spiffing"
    dataArray[5] = "Top Notch Effort!"
    dataArray[6] = "Marvelous Absolutley Marvelous"
    dataArray[7] = "Gratz!!"


function AutoGratz:OnLoad()
    
    AutoGratz:RegisterEvent("CHAT_MSG_GUILD")
    AutoGratz:SetScript("OnEvent", function(this, event, ...) AutoGratz[event](...) end)
    
    if( DEFAULT_CHAT_FRAME ) then
        DEFAULT_CHAT_FRAME:AddMessage("Gratz Loaded.");
    end
    UIErrorsFrame:AddMessage("Gratz Loaded.", 1.0, 1.0, 1.0, 1.0, UIERRORS_HOLD_TIME);
    
    SlashCmdList["GRATZCOMMAND"] = Gratz_Handler;
    SLASH_GRATZCOMMAND1 = "/Gratz";

end

function Gratz_Handler()
    SendChatMessage(dataArray[math.random(getn(dataArray))], "GUILD");
end

function AutoGratz.CHAT_MSG_GUILD(msg, senderName, language)

    if strfind(msg, string.upper("TEST MSG")) then
        SendChatMessage("Test Successful", "GUILD");
    end

end
and no dice....doesnt run

Last edited by aussiexile : 12-28-08 at 10:35 PM.
  Reply With Quote
12-28-08, 10:46 PM   #9
Bangerz
A Fallenroot Satyr
 
Bangerz's Avatar
AddOn Author - Click to view addons
Join Date: May 2008
Posts: 27
Put your scripts tag in the XML inside a frame, like I pasted above.

Remove the if( DEFAULT_CHAT_FRAME ) then ... end

That should then load and work.

Then you should prefix your data tables, as you are defining them as globals.
  Reply With Quote
12-28-08, 10:52 PM   #10
aussiexile
A Deviate Faerie Dragon
Join Date: Dec 2008
Posts: 14
prefix the DataArray????

if so with what sorry lol

XML
Code:
<Ui xmlns="http://www.blizzard.com/wow/ui/"   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   xsi:schemaLocation="http://www.blizzard.com/wow/ui/"> 
    <Script file="AutoGratz.lua"/> 

    <Frame name="AutoGratz" hidden="true" parent="UIParent">
        <Scripts> 
            <OnLoad> 
                AutoGratz:OnLoad()
            </OnLoad>
        </Scripts> 
    </Frame>
</Ui>
Lua
Code:
dataArray = {}
    dataArray[0] = "Well Done...Well Done Indeed"
    dataArray[1] = "Good show old chap"
    dataArray[2] = "I say, that was jolly well done"
    dataArray[3] = "Spiffing job mate!"
    dataArray[4] = "Absolutely Spiffing"
    dataArray[5] = "Top Notch Effort!"
    dataArray[6] = "Marvelous Absolutley Marvelous"
    dataArray[7] = "Gratz!!"


function AutoGratz:OnLoad()
    
    AutoGratz:RegisterEvent("CHAT_MSG_GUILD")
    AutoGratz:SetScript("OnEvent", function(this, event, ...) AutoGratz[event](...) end)
    
    UIErrorsFrame:AddMessage("Gratz Loaded.", 1.0, 1.0, 1.0, 1.0, UIERRORS_HOLD_TIME);
    
    SlashCmdList["GRATZCOMMAND"] = Gratz_Handler;
    SLASH_GRATZCOMMAND1 = "/Gratz";

end

function Gratz_Handler()
    SendChatMessage(dataArray[math.random(getn(dataArray))], "GUILD");
end

function AutoGratz.CHAT_MSG_GUILD(msg, senderName, language)

    if strfind(msg, string.upper("TEST MSG")) then
        SendChatMessage("Test Successful", "GUILD");
    end

end
Still not working lol

and BTW thanx for all the help

Last edited by aussiexile : 12-28-08 at 11:02 PM.
  Reply With Quote
12-28-08, 11:55 PM   #11
Bangerz
A Fallenroot Satyr
 
Bangerz's Avatar
AddOn Author - Click to view addons
Join Date: May 2008
Posts: 27
Okay the whole mod should look like this :P

AutoGratz.toc

Code:
## Interface: 30000
## Title: AutoGratz
## Notes: Gives a random gratz message to Gchat
## Author: aussiexile
## Version: 1
## SavedVariables: AutoGratzDB

AutoGratz.xml
AutoGratz.lua
AutoGratz.xml

Code:
<Ui xmlns="http://www.blizzard.com/wow/ui/"   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   xsi:schemaLocation="http://www.blizzard.com/wow/ui/"> 
    <Script file="AutoGratz.lua"/> 

    <Frame name="AutoGratz" hidden="true" parent="UIParent">
        <Scripts> 
            <OnLoad> 
                AutoGratz:OnLoad()
            </OnLoad>
        </Scripts> 
    </Frame>
</Ui>
AutoGratz.lua
Code:
AutoGratz = CreateFrame("frame")

AutogratzdataArray = {}
    AutogratzdataArray[0] = "Well Done...Well Done Indeed"
    AutogratzdataArray[1] = "Good show old chap"
    AutogratzdataArray[2] = "I say, that was jolly well done"
    AutogratzdataArray[3] = "Spiffing job mate!"
    AutogratzdataArray[4] = "Absolutely Spiffing"
    AutogratzdataArray[5] = "Top Notch Effort!"
    AutogratzdataArray[6] = "Marvelous Absolutley Marvelous"
    AutogratzdataArray[7] = "Gratz!!"


function AutoGratz:OnLoad()

    AutoGratz:RegisterEvent("CHAT_MSG_GUILD")
    AutoGratz:SetScript("OnEvent", function(this, event, ...) AutoGratz[event](...) end)

    DEFAULT_CHAT_FRAME:AddMessage("Gratz Loaded.")

    SlashCmdList["GRATZCOMMAND"] = Gratz_Handler;
    SLASH_GRATZCOMMAND1 = "/Gratz";

end

function Gratz_Handler()
    SendChatMessage(AutogratzdataArray[math.random(getn(AutogratzdataArray))], "GUILD");
end

function AutoGratz.CHAT_MSG_GUILD(msg, senderName, language)

    if strfind(msg, string.upper("TEST MSG")) then
        SendChatMessage("Test Successful", "GUILD");
    end

end
  Reply With Quote
12-29-08, 12:52 AM   #12
aussiexile
A Deviate Faerie Dragon
Join Date: Dec 2008
Posts: 14
Works like a charm now

Thanx again for all the help......i know how painful it can be to explain something that should seem obvious :P

do u know of any good tutorial sites??

Aussiexile
  Reply With Quote
12-29-08, 01:09 AM   #13
aussiexile
A Deviate Faerie Dragon
Join Date: Dec 2008
Posts: 14
also is there a way to intercept System messages so i can filter achievement messages?
  Reply With Quote
12-29-08, 08:52 AM   #14
Psoewish
A Scalebane Royal Guard
 
Psoewish's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2008
Posts: 447
Originally Posted by aussiexile View Post
also is there a way to intercept System messages so i can filter achievement messages?
There should be, because I use an addon that does it.
I have no idea about how it works and all that, but maybe you can use this addon as a reference.
  Reply With Quote
12-29-08, 08:12 PM   #15
Bangerz
A Fallenroot Satyr
 
Bangerz's Avatar
AddOn Author - Click to view addons
Join Date: May 2008
Posts: 27
Hi again, it's CHAT_MSG_SYSTEM. There's also one for the 'achievment emotes'.

Check this site out:

WoWWiki
  Reply With Quote
12-29-08, 10:02 PM   #16
aussiexile
A Deviate Faerie Dragon
Join Date: Dec 2008
Posts: 14
thanx for all the help guys
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » need help with ChatFrame_AddMessageEventFilter();


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