WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Need some help about UNIT_POWER (https://www.wowinterface.com/forums/showthread.php?t=50359)

devilArt 11-03-14 09:39 AM

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")

Choonstertwo 11-03-14 10:01 AM

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.

Rilgamon 11-03-14 10:04 AM

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

Phanx 11-03-14 10:20 AM

Quote:

Originally Posted by Rilgamon (Post 299500)
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.

sirann 11-03-14 11:07 AM

Wouldn't it be better to RegisterUnitEvent('event', 'player') so you can remove that if check at the top as well?

devilArt 11-03-14 11:48 AM

Quote:

Originally Posted by Choonstertwo (Post 299499)
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 :D


All times are GMT -6. The time now is 03:01 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI