Quantcast Need some help about UNIT_POWER - WoWInterface
Thread Tools Display Modes
11-03-14, 09:39 AM   #1
devilArt
A Cyclonian
 
devilArt's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 43
Need some help about UNIT_POWER

edit: so my question is how can i make low mana alert only plays when I'm on mage/warlock/priest/paladin, and disable low mana alert when I'm on dk/rouge/warrior/hunter?

--------------------------------------------------------------------

I use this code to play a alert sound when I'm low health or mana
but how can I disable low mana alert when I'm playing DK?


Lua Code:
  1. local lowHealth = .2
  2. local lowMana   = .3
  3.  
  4. local playedHp, playedMp
  5. local f = CreateFrame("Frame")
  6. f:SetScript("OnEvent", function(self, event, unit, pType)
  7.     if unit ~= "player" then return end
  8.     if event == "UNIT_HEALTH" or event == "UNIT_MAXHEALTH" then
  9.         if UnitHealth("player") / UnitHealthMax("player") < lowHealth then
  10.             if not playedHp then
  11.                 playedHp = true
  12.                 PlaySoundFile("Interface\\AddOns\\media\\LowHealth.ogg")
  13.             end
  14.         else
  15.             playedHp = false
  16.         end
  17.     elseif event == "UNIT_POWER" or event == "UNIT_MAXPOWER" and pType == "MANA" then
  18.         if UnitPower("player") / UnitPowerMax("player") < lowMana then
  19.             if not playedMp then
  20.                 playedMp = true
  21.                 PlaySoundFile("Interface\\AddOns\\media\\LowMana.ogg")
  22.             end
  23.         else
  24.             playedMp = false
  25.         end
  26.     end
  27. end)
  28.  
  29. f:RegisterEvent("UNIT_HEALTH")
  30. f:RegisterEvent("UNIT_POWER")
  31. f:RegisterEvent("UNIT_MAXHEALTH")
  32. f:RegisterEvent("UNIT_MAXPOWER")

Last edited by devilArt : 11-03-14 at 11:39 AM.
  Reply With Quote
11-03-14, 10:01 AM   #2
Choonstertwo
A Chromatic Dragonspawn
 
Choonstertwo's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2011
Posts: 194
Edit: Disregard this post. I can't read.

Put this at the top of your code:
lua Code:
  1. local _, class = UnitClass("player")
  2. if class == "DEATHKNIGHT" then return end

This stops the code from doing anything if the player is a DK.

Last edited by Choonstertwo : 11-03-14 at 10:06 AM.
  Reply With Quote
11-03-14, 10:04 AM   #3
Rilgamon
Premium Member
 
Rilgamon's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 757
Not sure about the priorities of and/or ... but I'd guess you need brackets around the or ...

Lua Code:
  1. elseif (event == "UNIT_POWER" or event == "UNIT_MAXPOWER") and pType == "MANA" then
__________________
The cataclysm broke the world ... and the pandas could not fix it!
  Reply With Quote
11-03-14, 10:20 AM   #4
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by Rilgamon View Post
Not sure about the priorities of and/or ... but I'd guess you need brackets around the or ...
There's actually no need to check the events on that line, since the frame is only listening for 4 events and the other 2 were already checked.
__________________
Author/maintainer of Grid, PhanxChat, oUF_Phanx, and many more.
Troubleshoot an addonTurn any code into an addonMore addon resources
Need help with your code? Post all of your actual code! Attach or paste your files.
Please don’t PM me about addon bugs or code questions. Post a comment or forum thread instead!
  Reply With Quote
11-03-14, 11:07 AM   #5
sirann
A Flamescale Wyrmkin
Join Date: Mar 2007
Posts: 142
Wouldn't it be better to RegisterUnitEvent('event', 'player') so you can remove that if check at the top as well?
  Reply With Quote
11-03-14, 11:48 AM   #6
devilArt
A Cyclonian
 
devilArt's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 43
Originally Posted by Choonstertwo View Post
Edit: Disregard this post. I can't read.

Put this at the top of your code:
lua Code:
  1. local _, class = UnitClass("player")
  2. if class == "DEATHKNIGHT" then return end

This stops the code from doing anything if the player is a DK.

thank you, I figured it out
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Need some help about UNIT_POWER

Thread Tools
Display Modes

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