WoW:Hooking outgoing chat messages: Difference between revisions

From AddOn Studio
Jump to navigation Jump to search
No edit summary
 
(sea dependency)
Line 1: Line 1:
This HOWTO uses the [[Sea]] Cosmos Library, please be sure you have it installed and listed as a dependency for any addon using this HOWTO.
To modify outgoing chat messages we are going to hook the  ChatEdit_ParseText function.
To modify outgoing chat messages we are going to hook the  ChatEdit_ParseText function.



Revision as of 05:47, 1 September 2005

This HOWTO uses the Sea Cosmos Library, please be sure you have it installed and listed as a dependency for any addon using this HOWTO.

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