View Single Post
11-16-10, 05:01 PM   #6
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
If all you want to do is double the letter "r", then your code is way more complicated than it needs to be. Try this:

Code:
local old = SendChatMessage

local new = function(message, ...)
	if message:len() > 0 and not message:match("^/") then
		message = message:replace("r", "rr"):replace("rrrr", "rr"):replace("R" "RR"):replace("RRRR", "RR")
	end
	old(message, ...)
end

SendChatMessage = new

SLASH_ADDONNAME1 = "/doubler"

SlashCmdList.ADDONNAME = function()
	if SendChatMessage == new then
		SendChatMessage = old
		DEFAULT_CHAT_FRAME:AddMessage("AddonName disabled.")
	else
		SendChatMessage = new
		DEFAULT_CHAT_FRAME:AddMessage("AddonName enabled.")
	end
end
It'll work for both lowercase and capital letters, and won't double any "r" that's already doubled (eg. if you type "arrange" it won't end up as "arrrrange").

Last edited by Phanx : 11-16-10 at 05:04 PM.
  Reply With Quote