Thread Tools Display Modes
08-07-08, 11:52 AM   #1
Fireproof213
A Cyclonian
 
Fireproof213's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 43
Thumbs down UNIT_MANA event help

first of all, I'm trying to code an addon that tells your party/raid when you are low/out of mana. Is there an event besides UNIT_MANA that I should use or is there a way that I can set it so that if UNIT_MANA equals let's say 20% mana then it announces that your at 20% mana? I know how to announce it just want to know if I can set it so that it does it at the right percentage not every time mana changes
  Reply With Quote
08-07-08, 02:49 PM   #2
kneeki
A Flamescale Wyrmkin
 
kneeki's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2006
Posts: 134
First off, if you use UNIT_MANA you're going to need to make sure that it's YOUR mana that's changing. arg1 will return the UnitID

Second, if you don't want it firing every time your mana changes (goes up or down) you need to set a threshold. Use UnitMana("player") & UnitManaMax("player") with a little math to return a percentage of mana that the player currently has.

Third, make sure you only announce the message once, using a local variable as 0 or 1 (to make it easy)

Finally, send the message using SendChatMessage()
  Reply With Quote
08-07-08, 04:27 PM   #3
Fireproof213
A Cyclonian
 
Fireproof213's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 43
Originally Posted by kneeki View Post
First off, if you use UNIT_MANA you're going to need to make sure that it's YOUR mana that's changing. arg1 will return the UnitID

Second, if you don't want it firing every time your mana changes (goes up or down) you need to set a threshold. Use UnitMana("player") & UnitManaMax("player") with a little math to return a percentage of mana that the player currently has.

Third, make sure you only announce the message once, using a local variable as 0 or 1 (to make it easy)

Finally, send the message using SendChatMessage()
Yea that second thing was what I needed. How do I set a threshold? I'm sorta new to this.
  Reply With Quote
08-07-08, 04:40 PM   #4
kneeki
A Flamescale Wyrmkin
 
kneeki's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2006
Posts: 134
The threshold is whatever you deem it to be. I'd assume 20% ?

if ((UnitMana("player") / UnitManaMax("player"))*100) < 20 then SendChatMessage("MESSAGE") end

[edit] Oops. Fixed if statement.
Also, that will spam on every UNIT_MANA that fires off. You're going to want it to only go off once. Hence, #3

Last edited by kneeki : 08-07-08 at 04:45 PM.
  Reply With Quote
08-07-08, 05:22 PM   #5
Fireproof213
A Cyclonian
 
Fireproof213's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 43
thanks much
  Reply With Quote
08-07-08, 05:32 PM   #6
Davnel
A Fallenroot Satyr
 
Davnel's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 24
also set an option so that you reset the local variable once your back at full mana (or prefered percentage) otherwise its only going to work once per load.
  Reply With Quote
08-08-08, 04:44 PM   #7
Fireproof213
A Cyclonian
 
Fireproof213's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 43
Originally Posted by Davnel View Post
also set an option so that you reset the local variable once your back at full mana (or prefered percentage) otherwise its only going to work once per load.
how would I go about doing that? I'm still really new to this.
  Reply With Quote
08-08-08, 06:36 PM   #8
Slakah
A Molten Giant
 
Slakah's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2007
Posts: 863
So you could do.

Code:
local f = CreateFrame("Frame")
f:RegisterEvent("UNIT_MANA")

local cycled

local OnEvent(f, unit)
	if unit == "player" then
		if (UnitMana("player") / UnitManaMax("player")) < 0.2 then
			if not cycled then
				<Do Something>
				cycled = true
			end
		else
			cycled = nil
		end
	end
end
f:SetScript("OnEvent", OnEvent)
Should work, might be a bit spammy and annoying especially if your going to be broadcasting it in raid chat.

Hope this helps.
  Reply With Quote
08-09-08, 10:28 AM   #9
Fireproof213
A Cyclonian
 
Fireproof213's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 43
Originally Posted by Slakah View Post
So you could do.

Code:
local f = CreateFrame("Frame")
f:RegisterEvent("UNIT_MANA")

local cycled

local OnEvent(f, unit)
	if unit == "player" then
		if (UnitMana("player") / UnitManaMax("player")) < 0.2 then
			if not cycled then
				<Do Something>
				cycled = true
			end
		else
			cycled = nil
		end
	end
end
f:SetScript("OnEvent", OnEvent)
Should work, might be a bit spammy and annoying especially if your going to be broadcasting it in raid chat.

Hope this helps.
thanks loads!
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » UNIT_MANA event 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