Thread Tools Display Modes
08-28-08, 03:02 AM   #1
Inviticus
A Murloc Raider
Join Date: Jul 2008
Posts: 7
Help with first addon

Code:
wordCues = {"noob","nub","newb","retard","retards","loser","idiot","idiots","losers"}

function Frame1_OnLoad()
	this:RegisterEvent("CHAT_MSG_BATTLEGROUND");
end

function Frame1_OnEvent()
	local sender = arg2;
	local sentence = arg1;
	if ("CHAT_MSG_BATTLEGROUND" == event) then
	  for i=1,# db do
	    if (string.find(sentence, wordCues[i])) then
	      DEFAULT_CHAT_FRAME:AddMessage(sender .. ":" .. wordCues[i]);
	    end
	  end
	end
end
Any idea what's not working with this? Any help would be appreciated.
  Reply With Quote
08-28-08, 03:04 AM   #2
Inviticus
A Murloc Raider
Join Date: Jul 2008
Posts: 7
Also, what function is used to ignore a player? Thanks again for any help.
  Reply With Quote
08-28-08, 04:33 AM   #3
Mera
Retired of WoW, In ESO :)
 
Mera's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Apr 2008
Posts: 331
not "CHAT_MSG_BATTLEGROUND" == event but event == "CHAT_MSG_BATTLEGROUND"

not for i=1,# db do but for i=1,#wordCues do

else you're looking for AddIgnore
__________________
If you need to reach me I'm in ESO, @class101 or "Fathis Ules i"
addons: SpamBayes, BrokerCPU
projects: ThunderBayes
Mera[xeh]? - La CroisadeEcarlate (wow)
  Reply With Quote
08-28-08, 04:57 AM   #4
Slakah
A Molten Giant
 
Slakah's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2007
Posts: 863
not "CHAT_MSG_BATTLEGROUND" == event but event == "CHAT_MSG_BATTLEGROUND"
That would make no difference, although there's very little reason for doing so as from what I can see you haven't registered any other events.

instead of doing
Code:
for i = 1, #wordCues do
it would be better to use ipairs
e.g.
Code:
for i, v in ipairs(wordCues) do
	if string.find(sentence, v) then
		DEFAULT_CHAT_FRAME:AddMessage(sender .. ":" .. v)
	end
end
also a quick note it would be better to not use the globals this, event and argN's because they are going to be removed in Wrath of the Lich King . Instead of using an XML file you could create a frame using lua and then register an event this way.

Code:
local f = CreateFrame("Frame")
f:RegisterEvent("CHAT_MSG_BATTLEGROUND")
f:SetScript("OnEvent", function(f, event, sentence, sender)
	<Code Here>
end)
  Reply With Quote
08-28-08, 05:55 AM   #5
Mera
Retired of WoW, In ESO :)
 
Mera's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Apr 2008
Posts: 331
ha yes true I was thinking to = instead of == , but sure then its the same in both orders, I must really stop weed
__________________
If you need to reach me I'm in ESO, @class101 or "Fathis Ules i"
addons: SpamBayes, BrokerCPU
projects: ThunderBayes
Mera[xeh]? - La CroisadeEcarlate (wow)
  Reply With Quote
08-28-08, 06:26 AM   #6
ravagernl
Proceritate Corporis
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 1,176
Code:
local wordCues = {"noob","nub","newb","retard","retards","loser","idiot","idiots","losers"}

local f = CreateFrame("Frame")
f:RegisterEvent("CHAT_MSG_BATTLEGROUND")
f:SetScript("OnEvent", function(self, event, ...)
  	if self[event] then self[event](self, ...) end
end)

function f:PLAYER_ENTERING_WORLD(sentence, sender)
	for i, v in ipairs(wordCues) do
		if string.find(sentence, v) then
			DEFAULT_CHAT_FRAME:AddMessage(sender .. ":" .. v)
			AddIgnore(sender)
		end
	end
end
Drycoded, not tested so it may not work.
  Reply With Quote
08-28-08, 08:13 AM   #7
Inviticus
A Murloc Raider
Join Date: Jul 2008
Posts: 7
Wow, that was quick. Thanks, guys.
  Reply With Quote
08-28-08, 08:19 AM   #8
Inviticus
A Murloc Raider
Join Date: Jul 2008
Posts: 7
What's this line do, exactly? Just curious. I'm new to all of this.
Code:
if self[event] then self[event](self, ...) end
  Reply With Quote
08-28-08, 08:26 AM   #9
Tristanian
Andúril
Premium Member
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 279
Originally Posted by Inviticus View Post
What's this line do, exactly? Just curious. I'm new to all of this.
Code:
if self[event] then self[event](self, ...) end
It basically "maps" an event to a method that can be used by whichever 'self' registered the event (typically your frame).
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » Help with first 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