View Single Post
04-17-11, 02:16 AM   #9
Folji
A Flamescale Wyrmkin
 
Folji's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2009
Posts: 136
Originally Posted by SDPhantom View Post
I put together some code to do exactly what was described. It only operates on /say and it will attempt to use the emote slash command if it finds one that matches, otherwise, it'll send the emote out through the emote channel. Theoreticly, the slash command emotes support a target argument that lets you specify what UnitID to target. This option has been added in to this code as well.
lua Code:
  1. local Send=SendChatMessage;
  2. function SendChatMessage(msg,chan,...);
  3.     chan=chan:upper();--    Convert to make checks easier (channel is case-insensitive)
  4.     if chan=="SAY" then
  5. --      Strip all spaces around "*" and split into segments
  6.         local pieces={strsplit("*",msg:gsub("%s*%*%s*","%*"))};
  7.  
  8. --      Iterate through pieces
  9.         for i,j in ipairs(pieces) do
  10.             if #j>0 then--  Don't do anything if string is empty
  11.                 if i%2>0 then-- Evaluates to 1 if say, 0 if emote
  12.                     Send(j,chan);
  13.                 else
  14. --                  Try to separate command and args
  15.                     local cmd,arg=j:match("(%S+) (.+)");
  16.                     if not cmd then cmd=j; end
  17.  
  18. --                  This is tricky, we need to check if the emote slash command exists
  19.                     local token;
  20.                     local tokencheck,tokenid=EMOTE1_TOKEN,1;
  21.                     while tokencheck do
  22.                         local cmdcheck,cmdid=_G["EMOTE"..tokenid.."_CMD1"],1;
  23.                         while cmdcheck do
  24.                             local slashcmd=cmdcheck:sub(2):lower();--   Skip the slash for the emote command
  25.                             if slashcmd==cmd:lower() then-- Command matches, token found
  26.                                 token=tokencheck;
  27.                                 break;
  28.                             end
  29.  
  30. --                          Increment command
  31.                             cmdcheck,cmdid=_G["EMOTE"..tokenid.."_CMD"..(cmdid+1)],cmdid+1;
  32.                         end
  33.  
  34. --                      Break if token found
  35.                         if token then break; end
  36.  
  37. --                      Increment token
  38.                         tokencheck,tokenid=_G["EMOTE"..(tokenid+1)"_TOKEN",tokenid+1;
  39.                     end
  40.  
  41.                     if token then
  42.                         DoEmote(token,arg);--   Performs the same emote operation as supported by chat
  43.                     else
  44.                         Send(j,"EMOTE");
  45.                     end
  46.                 end
  47.             end
  48.         end
  49.     else
  50.         Send(msg,chan,...);
  51.     end
  52. end
So basically, I could take that code, put it in a .lua file, write a .toc file for it, put them in a folder and place it in the AddOns folder, and it'll work right out of the box? (Though it'd probably be better if someone who knows their way around the stuff does it, so that more people than just myself can benefit from it. )
  Reply With Quote