WoW:Hooking outgoing chat messages

From AddOn Studio
Revision as of 21:10, 7 June 2005 by WoWWiki>Preiter
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

To modify outgoing chat messages we are going to hook the ChatEdit_ParseText function.

You probably want to do this in an OnLoad function. Sea screws up the normal function hooking process, so you need to do it differently depending on whether Sea is installed or not.

  -- Make these variable global to the whole lua file
  local oldChatEdit_ParseText;
  local seaPresent = (Sea ~= nil);
  -- Place this code in the OnLoad function
  if (seaPresent) then
     Sea.util.hook("ChatEdit_ParseText","My_ParseText","after");
  else
     oldChatEdit_ParseText = ChatEdit_ParseText;
     ChatEdit_ParseText = My_ParseText;
  end;

My_ParseTest is going to get called now instead of ChatEdit_ParseText. It should look something like:

  function My_ParseText(chatEntry, send)
     -- if Sea is not installed, call the original function first. If Sea
     -- is installed it does this step for you. The original function will
     -- process any slash commands for you, so all that's left is chat messages
     if (~seaPresent) then
        oldChatEdit_ParseText(chatEntry, send);
     end
     --
     -- This function actually gets called every time the user hits a key. But the
     -- send flag will only be set when he hits return to send the message.
     if (send == 1) then
        local text = chatEntry:GetText(); -- Here's how you get the original text
        local newText = text;             -- here's where you can modify the text to your liking
        chatEntry:SetText( newText );     -- send the new text back to the UI
     end
  end