Reply
Thread Tools Display Modes
Unread 06-09-11, 01:08 PM   #1
Lily.Petal
A Molten Giant
 
Lily.Petal's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2010
Posts: 537
Stuf + Threat + Power Text

I am currently wanting to make a small threat meter using Stuf's custom LUA text option.

All I want it to do is just show My current Threat% (without the % sign please) on my target, the color being Stuf's HP Red Color.

If someone could offer assistance, I would appreciate it greatly!

*~Lily.Petal~*

===============

For anyone who happens to search for similar effects for their own layouts, code will be listed below.

Link for other lua codes(provided by Cantises): Lua Stuf examples

This code makes your power into a percent(without the %); if you are using energy/mana, the text will only show if you are under 100% (otherwise hidden). If you use RunicPower or Rage, the text will not show up unless you are above 1%.
Code:
function(unit)
	local pCur, pMax = UnitPower(unit), UnitPowerMax(unit)
	if pMax > 0 then
		local _, pToken = UnitPowerType(unit)
		if pToken == "RAGE" or pToken == "RUNIC_POWER" then
			-- Warrior / Teddy Bear Druid / DK
			if pCur > 0 then 
				return "%d", pCur
			end
		elseif pToken == "ENERGY" then
			-- Rogue / Kitty Druid
			if pCur < pMax then
				return "%d", pCur
			end
		else
			-- Everything else
			local pPer = ceil((pCur / pMax)*100)
			if pPer < 100 then
				return "%d", pPer
			end
		end
	end
end
Colored by powertype:
Code:
function(unit)
	local pCur, pMax, mCur, mMax = UnitPower(unit), UnitPowerMax(unit), UnitPower(unit, 0), UnitPowerMax(unit, 0)
	if pMax > 0 then
		local pType, pToken = UnitPowerType(unit)
		local pColor = PowerBarColor[pType]
		if ( (pToken ~= "MANA") and (mMax > 0) ) then	-- Druid in Bear/Cat form
			local mColor = PowerBarColor[0]
			local mPer = ceil((mCur / mMax)*100)
			local ShowPower, ShowMana
			if ((pToken == "RAGE") and (pCur > 0)) or ((pToken == "ENERGY") and (pCur < pMax)) then 
				ShowPower = true
			end
			if mPer < 100 then
				ShowMana = true
			end
			if ShowPower and ShowMana then
				return "|cff%02x%02x%02x%s|r |cff%02x%02x%02x%s|r", pColor.r * 255, pColor.g * 255, pColor.b * 255, pCur, mColor.r * 255, mColor.g * 255, mColor.b * 255, mPer
			elseif ShowPower then
				return "|cff%02x%02x%02x%s|r", pColor.r * 255, pColor.g * 255, pColor.b * 255, pCur
			elseif ShowMana then
				return "|cff%02x%02x%02x%s|r", mColor.r * 255, mColor.g * 255, mColor.b * 255, mPer
			end
		elseif pToken == "RAGE" or pToken == "RUNIC_POWER" then		-- Warrior / DK
			if pCur > 0 then 
				return "|cff%02x%02x%02x%s|r", pColor.r * 255, pColor.g * 255, pColor.b * 255, pCur
			end
		elseif pToken == "ENERGY" then	-- Rogue
			if pCur < pMax then
				return "|cff%02x%02x%02x%s|r", pColor.r * 255, pColor.g * 255, pColor.b * 255, pCur
			end
		else	-- Everything else
			local pPer = ceil((pCur / pMax)*100)
			if pPer < 100 then
				return "|cff%02x%02x%02x%s|r", pColor.r * 255, pColor.g * 255, pColor.b * 255, pPer
			end
		end
	end
end
__________________

Aggro Color to KG Panels Borders - Nibelheim
Lua Based UI Hider - Nibelheim
Custom LUA PowerText - Stuf - Nibelheim, Seerah

Last edited by Lily.Petal : 06-12-11 at 10:34 PM.
Lily.Petal is offline   Reply With Quote
Unread 06-09-11, 03:57 PM   #2
Nibelheim
local roygbi-
 
Nibelheim's Avatar
Featured
Join Date: Jan 2010
Posts: 1,530
Originally Posted by Lily.Petal View Post
I am currently wanting to make a small threat meter using Stuf's custom LUA text option.

All I want it to do is just show My current Threat% (without the % sign please) on my target, the color being Stuf's HP Red Color.

If someone could offer assistance, I would appreciate it greatly!

*~Lily.Petal~*
To get an accurate % reading may be out of the scope of Lua Text, as you'd want a timer to keep threat information updated. There's a few threat events you can watch out for, but they only fire on major threat changes making them somewhat useless for watching threat closely. It may be possible to utilize Stufs own Target frame from within the Lua Text itself. A crude example being:

Code:
self.ttelapsed = 0
self:SetScript("OnUpdate", function(self, elapsed)
  self.ttelapsed = self.ttelapsed + elapsed
  if self.ttelapsed >= 0.5 then
    local _, _, threatpct, _, threatvalue = UnitDetailedThreatSituation(unitid, mobunitid)
    if threatvalue then
      return "|cffff0000%d|r", floor(threatpct)
    else
      return ""
    end
    self.ttelapsed = 0
  end
end)
Nibelheim is offline   Reply With Quote
Unread 06-09-11, 05:09 PM   #3
Lily.Petal
A Molten Giant
 
Lily.Petal's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2010
Posts: 537
Originally Posted by Nibelheim View Post
To get an accurate % reading may be out of the scope of Lua Text, as you'd want a timer to keep threat information updated. There's a few threat events you can watch out for, but they only fire on major threat changes making them somewhat useless for watching threat closely. It may be possible to utilize Stufs own Target frame from within the Lua Text itself. A crude example being:

SNIP
Thank you nib, I will have to try it out soon ^^
__________________

Aggro Color to KG Panels Borders - Nibelheim
Lua Based UI Hider - Nibelheim
Custom LUA PowerText - Stuf - Nibelheim, Seerah
Lily.Petal is offline   Reply With Quote
Unread 06-09-11, 07:29 PM   #4
Nibelheim
local roygbi-
 
Nibelheim's Avatar
Featured
Join Date: Jan 2010
Posts: 1,530
Originally Posted by Lily.Petal View Post
Thank you nib, I will have to try it out soon ^^
Well, it probably won't work, due to the way Lua Text functions operate. What may be best is to just make a kgPanel with appropriate events and OnUpdate routines, and set it's text to your threat %.
Nibelheim is offline   Reply With Quote
Unread 06-09-11, 07:46 PM   #5
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 9,615
LuaTexts can be set to run (a slightly throttled, iirc) OnUpdate if you check the "frequent updates" box.
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

Seerah is online now   Reply With Quote
Unread 06-09-11, 07:47 PM   #6
Nibelheim
local roygbi-
 
Nibelheim's Avatar
Featured
Join Date: Jan 2010
Posts: 1,530
Originally Posted by Seerah View Post
LuaTexts can be set to run (a slightly throttled, iirc) OnUpdate if you check the "frequent updates" box.
Ohh, nice. In that case, it's just a simple matter of:

Code:
local _, _, threatpct, _, threatvalue = UnitDetailedThreatSituation(unitid, mobunitid)
if threatvalue then
  return "|cffff0000%d|r", floor(threatpct)
else
  return ""
end
Nibelheim is offline   Reply With Quote
Unread 06-09-11, 09:44 PM   #7
Lily.Petal
A Molten Giant
 
Lily.Petal's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2010
Posts: 537
Originally Posted by Nibelheim View Post
Ohh, nice. In that case, it's just a simple matter of:

Code:
local _, _, threatpct, _, threatvalue = UnitDetailedThreatSituation(unitid, mobunitid)
if threatvalue then
  return "|cffff0000%d|r", floor(threatpct)
else
  return ""
end
hm.. I might need an explanation on how to put this in.

Do I need to change unitid to player?
__________________

Aggro Color to KG Panels Borders - Nibelheim
Lua Based UI Hider - Nibelheim
Custom LUA PowerText - Stuf - Nibelheim, Seerah
Lily.Petal is offline   Reply With Quote
Unread 06-09-11, 10:14 PM   #8
Nibelheim
local roygbi-
 
Nibelheim's Avatar
Featured
Join Date: Jan 2010
Posts: 1,530
Originally Posted by Lily.Petal View Post
hm.. I might need an explanation on how to put this in.

Do I need to change unitid to player?
Yep.

unitid = "player"
mobunitid = "target"
Nibelheim is offline   Reply With Quote
Unread 06-09-11, 10:56 PM   #9
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 9,615
If you put it in as a LuaText for your player frame, it will pass your "player" unitid to the function as the first(?) argument.
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

Seerah is online now   Reply With Quote
Unread 06-10-11, 03:46 AM   #10
Lily.Petal
A Molten Giant
 
Lily.Petal's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2010
Posts: 537
Thank you Nib and Seerah, was great help!

Hm having a different problem now, with all my classes I use:
[solid_if_mp99:Percmp]
For all my power bars; which isn't a problem, it works as intended for every class... But DK's & Warriors

Is there someway that I can have it show
[solid_if_mp99:Percmp] -- For all Classes but DK&Warriors
[solid_ifnot_mp99:Percmp] -- For only DK&Warriors
__________________

Aggro Color to KG Panels Borders - Nibelheim
Lua Based UI Hider - Nibelheim
Custom LUA PowerText - Stuf - Nibelheim, Seerah

Last edited by Lily.Petal : 06-10-11 at 03:54 AM.
Lily.Petal is offline   Reply With Quote
Unread 06-10-11, 04:05 AM   #11
Nibelheim
local roygbi-
 
Nibelheim's Avatar
Featured
Join Date: Jan 2010
Posts: 1,530
Originally Posted by Lily.Petal View Post
Thank you Nib and Seerah, was great help!

Hm having a different problem now, with all my classes I use:

For all my power bars; which isn't a problem, it works as intended for every class... But DK's & Warriors

Is there someway that I can have it show
I've never used Stuf, so I'm unfamiliar with those particular clauses or where they're used, however a simple if-then-else usually works for segregating different functionality for different classes. In this case, though, it may be better to determine what power type the unit is using.

Code:
local _, power_token = UnitPowerType(unit)  -- Lua Texts usually pass the unit arg, so leaving unit as is should work
if power_token == "RAGE" or power_token == "RUNIC_POWER" then
  -- Warrior / Teddy Bear Druid / DK
else
  -- Everything else
end

Last edited by Nibelheim : 06-10-11 at 04:12 AM.
Nibelheim is offline   Reply With Quote
Unread 06-10-11, 04:20 AM   #12
Lily.Petal
A Molten Giant
 
Lily.Petal's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2010
Posts: 537
Originally Posted by Nibelheim View Post
Code:
local _, power_token = UnitPowerType(unit)  -- Lua Texts usually pass the unit arg, so leaving unit as is should work
if power_token == "RAGE" or power_token == "RUNIC_POWER" then
  -- Warrior / Teddy Bear Druid / DK
else
  -- Everything else
end
I really need to learn LUA, time for me to use google to learn to put in the text :>

return ceil(Percent(MP(unit)))
hm...
__________________

Aggro Color to KG Panels Borders - Nibelheim
Lua Based UI Hider - Nibelheim
Custom LUA PowerText - Stuf - Nibelheim, Seerah

Last edited by Lily.Petal : 06-10-11 at 04:27 AM.
Lily.Petal is offline   Reply With Quote
Unread 06-10-11, 04:37 AM   #13
Lily.Petal
A Molten Giant
 
Lily.Petal's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2010
Posts: 537
Hm, using stuf it says when I switch to LUA:
Lua Code must have this format:
function(unit, cache, textframe) <some text> return 'text', ... end where 'cache' may be used as cache.infotag (see pattern help or core.lua) and "..." are optional arguments to SetFormattedText.
function(unit, cache, textframe) return 'text' end
__________________

Aggro Color to KG Panels Borders - Nibelheim
Lua Based UI Hider - Nibelheim
Custom LUA PowerText - Stuf - Nibelheim, Seerah
Lily.Petal is offline   Reply With Quote
Unread 06-10-11, 04:40 AM   #14
Nibelheim
local roygbi-
 
Nibelheim's Avatar
Featured
Join Date: Jan 2010
Posts: 1,530
What is it you're trying to achieve, exactly? Just showing the Power in standard format?
Nibelheim is offline   Reply With Quote
Unread 06-10-11, 04:45 AM   #15
Lily.Petal
A Molten Giant
 
Lily.Petal's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2010
Posts: 537
Originally Posted by Nibelheim View Post
What is it you're trying to achieve, exactly? Just showing the Power in standard format?
What I am trying to do is so that If I am any class that uses anything but Rage/RunicPower that it shows the MP value in CurMP% when it goes below 100%, but hides when greater than 99%(without the % sign).
And the opposite if they do use said powertypes, where if it's at 0% said text will hide.

Basically:
if power≤99% show if not DK/Bear/Warrior as CurMP%

and

if power≥1% show if DK/Bear/Warrior as CurMP%

Does this help? :<

EDIT: it's just REALLY annoying when I'm playing my DK/Warrior that I see a 0 in the middle of my power bar when I have no power at all.
__________________

Aggro Color to KG Panels Borders - Nibelheim
Lua Based UI Hider - Nibelheim
Custom LUA PowerText - Stuf - Nibelheim, Seerah

Last edited by Lily.Petal : 06-10-11 at 04:50 AM.
Lily.Petal is offline   Reply With Quote
Unread 06-10-11, 04:53 AM   #16
Nibelheim
local roygbi-
 
Nibelheim's Avatar
Featured
Join Date: Jan 2010
Posts: 1,530
Originally Posted by Lily.Petal View Post
What I am trying to do is so that If I am any class that uses anything but Rage/RunicPower that when I am at 100% Mana/Energy, the text doesn't show, and I would like it to be a Percent(without the % sign).

Basically:
if power≤99% show if not DK/Bear/Warrior as CurMP%

And basically the opposite if I am a DK/Bear/Warrior
if power≥1% show if DK/Bear/Warrior as CurMP%

Does this help? :<
Ahh. I like doing my Lua Texts with pure Lua. Some of my UI users reported strange power display issues when using Lua Text abbreviations.

Barebones:
Code:
local _, pToken = UnitPowerType(unit)
local pCur, pMax = Power(unit), MaxPower(unit)
if pMax > 0 then
	if pToken == "RAGE" or pToken == "RUNIC_POWER" then
		-- Warrior / Teddy Bear Druid / DK
		if pCur > 0 then
			return "%d", pCur
		end
	else
		-- Everything else
		local pPer = ceil(pCur / pMax)
		if pPer < 100 then
			return "%d", pPer
		end
	end
end
Nibelheim is offline   Reply With Quote
Unread 06-10-11, 04:57 AM   #17
Lily.Petal
A Molten Giant
 
Lily.Petal's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2010
Posts: 537
Do I still need to do something with:
Lua Code must have this format:
function(unit, cache, textframe) <some text> return 'text', ... end where 'cache' may be used as cache.infotag (see pattern help or core.lua) and "..." are optional arguments to SetFormattedText.
function(unit, cache, textframe) return 'text' end
By any chance? I entered it into the options and saved, put it on fast update and reloaded and is still not working. Gonna go insane :<

EDIT: let me try changing unit to "player"
EDIT2: ugh Dx darn you stuf... darn you... (didn't work)
__________________

Aggro Color to KG Panels Borders - Nibelheim
Lua Based UI Hider - Nibelheim
Custom LUA PowerText - Stuf - Nibelheim, Seerah

Last edited by Lily.Petal : 06-10-11 at 04:59 AM.
Lily.Petal is offline   Reply With Quote
Unread 06-10-11, 05:08 AM   #18
Nibelheim
local roygbi-
 
Nibelheim's Avatar
Featured
Join Date: Jan 2010
Posts: 1,530
Hmm, same error again? It must behave different to Pitbull's Lua Text. Maybe it needs an extra return.


Code:
local _, pToken = UnitPowerType(unit)
local pCur, pMax = Power(unit), MaxPower(unit)
if pMax > 0 then
	if pToken == "RAGE" or pToken == "RUNIC_POWER" then
		-- Warrior / Teddy Bear Druid / DK
		if pCur > 0 then
			return "%d", pCur
		end
	else
		-- Everything else
		local pPer = ceil(pCur / pMax)
		if pPer < 100 then
			return "%d", pPer
		end
	end
else
	return ""
end
Nibelheim is offline   Reply With Quote
Unread 06-10-11, 05:18 AM   #19
Lily.Petal
A Molten Giant
 
Lily.Petal's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2010
Posts: 537
Well it's not giving me an error, it's just not showing up at all. I don't really understand it.
__________________

Aggro Color to KG Panels Borders - Nibelheim
Lua Based UI Hider - Nibelheim
Custom LUA PowerText - Stuf - Nibelheim, Seerah
Lily.Petal is offline   Reply With Quote
Unread 06-10-11, 05:22 AM   #20
Nibelheim
local roygbi-
 
Nibelheim's Avatar
Featured
Join Date: Jan 2010
Posts: 1,530
Originally Posted by Lily.Petal View Post
Well it's not giving me an error, it's just not showing up at all. I don't really understand it.
Debug time! Hmm, I wonder if print works in Lua Text Is fast update ticked?

Code:
local _, pToken = UnitPowerType(unit)
local pCur, pMax = Power(unit), MaxPower(unit)

print(unit)
print(pCur)
print(pMax)

if pMax > 0 then
	if pToken == "RAGE" or pToken == "RUNIC_POWER" then
		-- Warrior / Teddy Bear Druid / DK
		if pCur > 0 then
			return "%d", pCur
		end
	else
		-- Everything else
		local pPer = ceil(pCur / pMax)
		if pPer < 100 then
			return "%d", pPer
		end
	end
else
	return ""
end
Nibelheim is offline   Reply With Quote
Reply

Go BackWoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » Stuf + Threat

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