Thread Tools Display Modes
11-16-10, 07:28 AM   #1
Dzib
A Deviate Faerie Dragon
Join Date: Nov 2010
Posts: 16
Transforming an existing addon

Hi

I'd like to make an addon which add the letters "rr" after each "r" detected in the chat (like someone who's rolling r's)
Being a total newbie in programming, I took an addon which adds an "o" after every consonant and tried to modify it.

Here's the original code:

Code:
function doRoevar(str)
	
	local endstr = ""; 
	local konsonanter = {"b","c","d","f","g","h","j","k","l","m","n","p","q","r","s","t","v","w","x","z"}; 
	local bokstvr = {}; 
	
	for i = 1,string.len(str) do

		bokstvr[i] = string.sub(str,i,i); 
		
		for t = 1,19 do 
		if (string.lower(bokstvr[i]) == konsonanter[t]) then 
			bokstvr[i] = bokstvr[i] .. "o" .. string.lower(bokstvr[i]); 
			end 
		end 

		endstr = endstr .. bokstvr[i]; 
		
	end 
	
	return endstr;		
		
end
And here's the code I've modified

Code:
function doRoevar(str)
	
	local endstr = ""; 
	local konsonanter = {"r"}; 
	local bokstvr = {}; 
	
	for i = 1,string.len(str) do

	bokstvr[i] = string.sub(str,i,i); 
		
		for t = 1,19 do 
		if (string.lower(bokstvr[i]) == konsonanter[t]) then 
			bokstvr[i] = bokstvr[i] .. "r" .. string.lower(bokstvr[i]); 
			end 
		end 

		endstr = endstr .. bokstvr[i]; 
		
	end 
	
	return endstr;		
		
end
I'm sur I could simplfy the function but I'm a bit afraid of blowing up eveything. Anyway, it works this way but the only thing I can't find out is how to activate the function only if I'm talking in the guild/say/yell chat???

Thanks
  Reply With Quote
11-16-10, 07:48 AM   #2
Nobgul
A Molten Giant
 
Nobgul's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 693
That can't be all the code, in order for us to help you could you provide the full code.
__________________
[SIGPIC][/SIGPIC]
  Reply With Quote
11-16-10, 08:03 AM   #3
Dzib
A Deviate Faerie Dragon
Join Date: Nov 2010
Posts: 16
Sorry, here's the full code:

Code:
function InitRoevar() 

	DEFAULT_CHAT_FRAME:AddMessage("|c00FF0000Rovarspraket |cFF00FF01loaded.\nTalk like a |c00FF0000rovare!"); 
	
	roevar_toggle = false;
	
	SLASH_ROEVARTOGGLE1 = "/rovar";
	SLASH_ROEVARTOGGLE2 = "/rtoggle";
	SLASH_ROEVARTOGGLE3 = "/rovartoggle";
	SlashCmdList["ROEVARTOGGLE"] = roevarToggle;
	
end 
	
local Rovar_OldSCM = SendChatMessage; 

function SendChatMessage(msg, system, language, chatnumber) 

	if (msg == "!roevar") then
		roevarToggle();
		msg = "";
	elseif (msg ~= "" and (string.find(msg, "%[") == nil)) then 
		if ( string.find(msg, "^%/") == nil ) then
			if (roevar_toggle == true) then
				msg = doRoevar(msg);
			end
		end
	end

	Rovar_OldSCM(msg, system, language, chatnumber); 
end 
	
function doRoevar(str)
	
	local endstr = ""; 
	local konsonanter = {"r"}; 
	local bokstvr = {}; 
	
	for i = 1,string.len(str) do

		bokstvr[i] = string.sub(str,i,i); 
		
		for t = 1,19 do 
		if (string.lower(bokstvr[i]) == konsonanter[t]) then 
			bokstvr[i] = bokstvr[i] .. "r" .. string.lower(bokstvr[i]); 
			end 
		end 

		endstr = endstr .. bokstvr[i]; 
		
	end 
	
	return endstr;		
		
end 

function roevarToggle(msg)
	if (msg == "" or msg == nil) then
		if (roevar_toggle == false) then
			roevar_toggle = true;
			DEFAULT_CHAT_FRAME:AddMessage("|c00FF0000Rovarspraket |c0000bbbbenabled."); 
		else
			roevar_toggle = false;
			DEFAULT_CHAT_FRAME:AddMessage("|c00FF0000Rovarspraket |c00FF00bbdisabled.");
		end 
	elseif (msg == "help") then
		DEFAULT_CHAT_FRAME:AddMessage("|cFF00FF01Toggle |c00FF0000Rovarspraket |cFF00FF01with /roevar, /rtoggle or /rovarspraket to talk like a pirate!\n|c00FF0000Rovarspraket |cFF00FF01is currently " .. (roevar_toggle and "|c0000bbbbenabled" or "|c00FF00bbdisabled") .. ".");
	end
	
end
  Reply With Quote
11-16-10, 08:10 AM   #4
Ailae
A Rage Talon Dragon Guard
 
Ailae's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2007
Posts: 318
Sorry to go off-topic, but I really laughed that someone made an addon for 'Rövarspråket'.

http://en.wikipedia.org/wiki/Rövarspråket

Guess we need one for Pig Latin now too.
__________________
Oh, the simulated horror!
  Reply With Quote
11-16-10, 11:22 AM   #5
Nobgul
A Molten Giant
 
Nobgul's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 693
Originally Posted by Ailae View Post
Sorry to go off-topic, but I really laughed that someone made an addon for 'Rövarspråket'.

http://en.wikipedia.org/wiki/Rövarspråket

Guess we need one for Pig Latin now too.
That is where he got this code from .

To the OP I vaguely remember someone else having a issue with a chat type program for role playing. I think they had to add a function for each of the other types of chat RAID PARTY.

I think you need to find the index of the trade channel first in order to do this. I will play with the code later.
__________________
[SIGPIC][/SIGPIC]
  Reply With Quote
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

WoWInterface » Developer Discussions » Lua/XML Help » Transforming an existing addon


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