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"); Really need help... |
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 Code:
UnitAura("player", "Righteous Fury") |
Quote:
Don't really know how to do this work but something like this? Code:
local frame = CreateFrame("FRAME", "RFFrame"); |
Quote:
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) Code:
frame:RegisterEvent("UNIT_AURA"); Code:
local function eventHandler(self, event, ...) |
Hmm... Think I at least get a little bit of what you wrote.
Will it be like this? Code:
local frame = CreateFrame("FRAME", "RFFrame"); |
What I mean is, that what you need to add is inside the function e.g.
Code:
local frame = CreateFrame("FRAME", "RFFrame"); |
Have been reading that tutorial before, and I created the HelloWorld addon :P
Just don't know what i should put in --ADD YOUR CODE HERE, but I know that the code i put in here will get the addon working and that. |
First what you would need to do is check if the given unit by UNIT_AURA is 'player'. This event runs pretty often, and for each unit.
lua Code:
Using return will skip out of the function stopping any processing of code. It's just a way of avoiding too many nested if then end's. Then you know it's the player that gained or lost a buff. You want to see if the player has gained righteous fury. To see that, we use UnitBuff: lua Code:
lua Code:
But what will happen, is that will fire off every time you get or loose an aura, resulting in chat spam. So we solve that with a variable called 'hasrf': lua Code:
|
Thanks for all answers.
I tried this code, but isn't working: Code:
local frame = CreateFrame("FRAME", "RFFrame"); And some other questions too... if i want to create a frame that shows "RF is not active", and when its active it shows "RF is active", in a frame like WinterTimer has, that is showing all the time, do i need to do this in the xml file, and is it hard? Second question, what program are you guys coding in? Cause im just using the WordPad xD |
You're missing an end in the code block above.
|
Quote:
Can the reason why it doesnt work be because i use Prat instead of the default chat frame? |
No, you need to close your function.
|
Quote:
Code:
local hasrf |
Woow, this is much harder then i excpected.
Code:
local frame = CreateFrame("FRAME", "RFFrame"); |
Quote:
To be a bit more illustrative, look at what your current code looks like indented: lua Code:
does that make the problem more clear? |
Code:
1. |
Right, now you've got that part correct. Now you just need to clean up your extra function (which was probably accidentally left there).
After that, there's only one more problem with this code: lua Code:
...and that is that "active" is declared in the wrong place. You need to check whether the player has the buff every time the function runs, not just when your addon loads. Is that enough information for you to figure out what to change? |
Quote:
|
Quote:
|
Quote:
|
All times are GMT -6. The time now is 08:50 PM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI