Thread Tools Display Modes
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: 540
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.
  Reply With Quote
06-09-11, 03:57 PM   #2
Nibelheim
local roygbi-
 
Nibelheim's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 1,600
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)
  Reply With Quote
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: 540
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
  Reply With Quote
06-09-11, 07:29 PM   #4
Nibelheim
local roygbi-
 
Nibelheim's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 1,600
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 %.
  Reply With Quote
06-09-11, 07:46 PM   #5
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
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

  Reply With Quote
06-09-11, 07:47 PM   #6
Nibelheim
local roygbi-
 
Nibelheim's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 1,600
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
  Reply With Quote

WoWInterface » 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