View Single Post
01-10-10, 07:52 AM   #8
ravagernl
Proceritate Corporis
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 1,176
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:
  1. local unit = ... -- select the first argument from arguments passed
  2. if unit ~= 'player' then return end -- run code only for player unit

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:
  1. local active = UnitBuff('player', 'Righteous Fury')
  2. if active then
  3.     print('Righteous Fury has been activated')
  4. end
or even
lua Code:
  1. if UnitBuff('player', 'Righteous Fury') then
  2.     print('Righteous Fury has been activated')
  3. end

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:
  1. local active = UnitBuff('player', 'Righteous Fury')
  2. if not hasrf and active then -- we gained righteous fury as we did not have it before and it's active now
  3.     hasrf = true
  4.     print('Righteous Fury has been activated')
  5. elseif hasrf and not active then -- we lost righteous fury as we did have it before and it's no longer active now
  6.     hasrf = false
  7. end
Be sure to define 'hasrf' as a local variable outside your eventhandler function
  Reply With Quote