Thread Tools Display Modes
01-09-10, 08:38 PM   #1
opismahname
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 23
First Addon - need help

Hey there, I'm making my first AddOn that will be a real simple one. The thing i want this AddOn to do is to print "Rigtheous Fury is now activated" in the chat window when you cast Righteous Fury.

I've been reading alot about how to do something like this but still can't get it...

The code I am doing is like this (i know, i suck at this, but it's like my first time):
Code:
local frame = CreateFrame("FRAME", "RFFrame");
frame:RegisterEvent("UNIT_AURA_PLAYER_RIGHTEOUS FURY");
local function eventHandler(self, event, ...)
 print("Rigtheous Fury is now activated " .. event);
end
frame:SetScript("OnEvent", eventHandler);
I know that this isn't right at all, but don't know what to do

Really need help...
  Reply With Quote
01-09-10, 09:00 PM   #2
Akryn
A Firelord
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 479
You are pretty close:

"UNIT_AURA_PLAYER_RIGHTEOUS FURY" is not an event. "UNIT_AURA" is, and that's all you should put there.

Therefore, in your OnEvent function, you need to check for...
1. Is this event firing for the player
2. If so, does the player currently have the aura.
3. If so, did the player not have it the last time I checked -- to prevent the addon from spamming every time you gain/loose an aura while that one is active.

The way to do #1 is to check the event's arg1, which is the unit the event fired for e.g.
Code:
if ... == "player" then
The way to do #2 is with UnitAura e.g.
Code:
UnitAura("player", "Righteous Fury")
The way to do #3 is to save the result of each check in a variable, and check it before announcing.
  Reply With Quote
01-09-10, 09:15 PM   #3
opismahname
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 23
Originally Posted by Akryn View Post
You are pretty close:

"UNIT_AURA_PLAYER_RIGHTEOUS FURY" is not an event. "UNIT_AURA" is, and that's all you should put there.

Therefore, in your OnEvent function, you need to check for...
1. Is this event firing for the player
2. If so, does the player currently have the aura.
3. If so, did the player not have it the last time I checked -- to prevent the addon from spamming every time you gain/loose an aura while that one is active.

The way to do #1 is to check the event's arg1, which is the unit the event fired for e.g.
Code:
if ... == "player" then
The way to do #2 is with UnitAura e.g.
Code:
UnitAura("player", "Righteous Fury")
The way to do #3 is to save the result of each check in a variable, and check it before announcing.
Thanks for answering!
Don't really know how to do this work but something like this?
Code:
local frame = CreateFrame("FRAME", "RFFrame");
frame:RegisterEvent("UNIT_AURA");
local function eventHandler(self, event, ...)
 print("Rigtheous Fury is now activated " .. event);
end
frame:SetScript("OnEvent *something here?*", eventHandler);
Or could you post how the entire code would be?
  Reply With Quote
01-09-10, 09:25 PM   #4
Akryn
A Firelord
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 479
Originally Posted by opismahname View Post
Or could you post how the entire code would be?
I would be happy to if you'd like; although wouldn't that invalidate the point of trying to make your own addon?

Otherwise:

What you want to do is put some checks in your OnEvent function itself, the function that you call eventHandler.
Code:
frame:SetScript("OnEvent", eventHandler)
and
Code:
frame:RegisterEvent("UNIT_AURA");
are both already correct as they are. You need to put some logic in eventHandler to detect the three things I mentioned above:
Code:
local function eventHandler(self, event, ...)
--some stuff goes here
--your existing code
end
  Reply With Quote
01-09-10, 09:56 PM   #5
opismahname
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 23
Hmm... Think I at least get a little bit of what you wrote.

Will it be like this?

Code:
local frame = CreateFrame("FRAME", "RFFrame");
frame:RegisterEvent("UNIT_AURA");
local function eventHandler(self, event, ...)
 print("Rigtheous Fury is now activated " .. event);
end
frame:SetScript("OnEvent", eventHandler);
if Rigtheous Fury (or is it supposed to be...?) == "player" then
**Didnt't get "--your existing code, or do you mean everything that i already have written?"**
end
Haven't coded like this or something before so I am really bad at this :P
  Reply With Quote
01-09-10, 10:17 PM   #6
Akryn
A Firelord
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 479
What I mean is, that what you need to add is inside the function e.g.
Code:
local frame = CreateFrame("FRAME", "RFFrame");
frame:RegisterEvent("UNIT_AURA");
local function eventHandler(self, event, ...)
 --ADD YOUR CODE HERE
 print("Rigtheous Fury is now activated " .. event);
end
frame:SetScript("OnEvent", eventHandler);
Given what you've posted so far, you might want to start with something like http://www.wowwiki.com/AddOn_program...l/Introduction
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » First Addon - need help


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