Quantcast PitBull4 Lua texts - Colored health and power? - WoWInterface
 
Thread Tools Display Modes
06-20-11, 10:51 PM   #1
jeffy162
A Pyroguard Emberseer
 
jeffy162's Avatar
AddOn Author - Click to view addons
Join Date: May 2009
Posts: 2,349
PitBull4 Lua texts - Colored health and power?

I'm using PitBull4 for my unit frames, and I've been trying to figure out how to get the health text to be health colored and the power text the color of the characters power using PB4's Lua texts. I've tried a few things, but only get errors. I found an example somewhere to color my characters' level by class, but can't seem to find anything about health color or power color.

What I'm using at the moment:

Class colored level:
Code:
Outline()
if UnitIsPlayer(unit) then
local cr,cg,cb = ClassColor(unit)
return "|cff%02x%02x%02x%s|r",cr,cg,cb,Level(unit)
end
Health (which is always bright green, but I want the color to change as the health goes down, if possible):
Code:
Outline()
return "|cff00ff00%s|r",HP(unit)
Power (which I'd like to be power colored):
Code:
Outline()
return "%s",Power(unit)
The characters' name is just fine in white, and this is what I use for that:
Code:
Outline()
return '%s %s%s%s',Name(unit),Angle(AFK(unit) or DND(unit))
I have posted a similar question on the WoWAce PitBull forum (Post), but I am posting it here, also, to try to get a "broader audience", as it were. Hopefully, someone can help me with this problem.

Last edited by jeffy162 : 06-20-11 at 10:54 PM.
  Reply With Quote
06-20-11, 11:03 PM   #2
Nibelheim
local roygbi-
 
Nibelheim's Avatar
Featured
Join Date: Jan 2010
Posts: 1,600
Some examples:

Power (supports Druid Mana and Alt Power types)
Code:
local color
local pType, pToken, altR, altG, altB = UnitPowerType(unit)
local pCur, pMax, pCurMana, pMaxMana = Power(unit), MaxPower(unit), Power(unit, 0), MaxPower(unit, 0)

if (pMax > 0) then
  if PitBull4.PowerColors[pToken] then
    color = PitBull4.PowerColors[pToken]
  else
    if (not altR) then
      color = PitBull4.PowerColors["MANA"]
    else
      color = {[1] = altR, [2] = altG, [3] = altB}
    end
  end
  
  if (pToken ~= "MANA") then
    if (pMaxMana > 0) then
      local DManaColor = PitBull4.PowerColors["MANA"]
      return "|cff%02x%02x%02x%s |cff%02x%02x%02x%s", color[1]*255, color[2]*255, color[3]*255, Short(pCur, true), DManaColor[1]*255, DManaColor[2]*255, DManaColor[3]*255, Short(pCurMana, true)
    end
  else
    return "|cff%02x%02x%02x%s", color[1]*255, color[2]*255, color[3]*255, Short(pCur, true)
  end
end


Health (green to red)
Code:
local cur, max = HP(unit), MaxHP(unit)
local PerHP = cur/max
local hr, hg, hb

if (PerHP < 0.5) then
  hr = 255
  hg = 255 * PerHP * 2
  hb = 0
else
  hr = 255 * (1 - ((PerHP - 0.5) * 2))
  hg = 255
  hb = 0
end

return "|cff%02x%02x%02x%s",hr,hg,hb,Short(cur,true)

Last edited by Nibelheim : 06-21-11 at 01:12 AM.
  Reply With Quote
06-20-11, 11:55 PM   #3
jeffy162
A Pyroguard Emberseer
 
jeffy162's Avatar
AddOn Author - Click to view addons
Join Date: May 2009
Posts: 2,349
Thank you very much for your help, Nibelheim, I appreciate it.

The health text code works perfectly. The power text code, however, is another matter. I copied it and pasted it directly into PB4, and got this error through !BugGrabber.lua in my SavedVariables:

["message"] = {
"<string>:\"PitBull4_LuaTexts:Orctales:Lua:Power\":5: ambiguous syntax (function call x new statement) near '('\nPitBull4-v4.0.0-beta28\\ModuleHandling\\TextProviderModule.lua:118: in function `UpdateFrame'\nPitBull4-v4.0.0-beta28\\ModuleHandling\\TextProviderModule.lua:150: in function `ForceTextUpdate'\nPitBull4_LuaTexts-v4.0.0-beta28\\LuaTexts.lua:1436: in function <Interface\\AddOns\\PitBull4_LuaTexts\\LuaTexts.lua:1432>\nPitBull4_LuaTexts-v4.0.0-beta28\\LuaTexts.lua:1506: in function <Interface\\AddOns\\PitBull4_LuaTexts\\LuaTexts.lua:1502>\n(tail call): ?:\n<in C code>: ?\n<string>:\"safecall Dispatcher[2]\":9: in function <[string \"safecall Dispatcher[2]\"]:5>\n(tail call): ?:\nAceConfigDialog-3.0-54:798: in function <...nfig-3.0\\AceConfigDialog-3.0\\AceConfigDialog-3.0.lua:613>\n(tail call): ?:\n<in C code>: ?\n<string>:\"safecall Dispatcher[3]\":9: in function <[string \"safecall Dispatcher[3]\"]:5>\n(tail call): ?:\nAceGUI-3.0-33 (Ace3):314: in function `Fire'\n...AceGUI-3.0\\widgets\\AceGUIWidg", -- [1]
"et-MultiLineEditBox.lua:44: in function <...AceGUI-3.0\\widgets\\AceGUIWidget-MultiLineEditBox.lua:41>:\n", -- [2]
},
["type"] = "error",
["time"] = "2011/06/21 01:21:16",
["session"] = 4214,
["counter"] = 2,
I hope it makes sense to you, since it's like trying to read martian to me.

I'm not sure if it makes a difference, but PB4 uses another module for alternate power. There is nothing about alternate power in the "Events" drop down menu, but I am unsure if that would have caused a problem since, to my uneducated eyes, it appears to be written in such a way that it doesn't matter if it checks for that and finds it not there.

Anyway, thank you again. I really appreciate your help.

Last edited by jeffy162 : 06-20-11 at 11:59 PM.
  Reply With Quote
06-21-11, 12:18 AM   #4
Nibelheim
local roygbi-
 
Nibelheim's Avatar
Featured
Join Date: Jan 2010
Posts: 1,600
Let's try something a bit simpler first, see if we can narrow down the error. I can't login to WoW these days, so dry coding can be a pain.

Code:
local color
local pType, pToken, altR, altG, altB = UnitPowerType(unit)
local pCur, pMax = Power(unit), MaxPower(unit)

if (pMax > 0) then
  if PitBull4.PowerColors[pToken] then
    color = PitBull4.PowerColors[pToken]
  else
    if (altR == nil) then
      color = PitBull4.PowerColors["MANA"]
    else
      color = {[1] = altR, [2] = altG, [3] = altB}
    end
  end
  
  return "|cff%02x%02x%02x%s", color[1]*255, color[2]*255, color[3]*255, Short(pCur, true)
end
The only events you should need are:
UNIT_POWER
UNIT_DISPLAYPOWER
  Reply With Quote
06-21-11, 12:53 AM   #5
jeffy162
A Pyroguard Emberseer
 
jeffy162's Avatar
AddOn Author - Click to view addons
Join Date: May 2009
Posts: 2,349
Many thanks, Nibelheim!! Both texts are working correctly (as far as I can tell). I'll know more tomorrow when I wake up and can try it on some other power types on different characters. One thing, though: There is no "UNIT_DISPLAYPOWER" in my Events drop down menu. Not that it matters, since it is apparently working.

Here's my PB4 frames (with your text coloring) for my Warlock:
Click image for larger version

Name:	PB4-Orctales.jpg
Views:	359
Size:	31.7 KB
ID:	6273

As you can see, my goal was to make everything gray-scale, except for the health, power and level texts. The "green steps" on the left of the name are from an addon I'm sure you are familiar with: nibPointDisplay. They represent my shards, and I have them set to display as: 1 - red, 2 - 1red 1yellow, 3 - all green.

Again, many thanks. I do appreciate your help, and the fact that you can't even log on to check out your code speaks volumes about your Lua skills.
  Reply With Quote
06-21-11, 01:14 AM   #6
Nibelheim
local roygbi-
 
Nibelheim's Avatar
Featured
Join Date: Jan 2010
Posts: 1,600
Another attempt at full Power functionality. May work, may not
Code:
local color
local pType, pToken, altR, altG, altB = UnitPowerType(unit)
local pCur, pMax, pCurMana, pMaxMana = Power(unit), MaxPower(unit), Power(unit, 0), MaxPower(unit, 0)

if (pMax > 0) then
  if PitBull4.PowerColors[pToken] then
    color = PitBull4.PowerColors[pToken]
  else
    if (altR == nil) then
      color = PitBull4.PowerColors["MANA"]
    else
      color = {[1] = altR, [2] = altG, [3] = altB}
    end
  end
  
  if (pToken ~= "MANA") then
    if (pMaxMana > 0) then
      local DManaColor = PitBull4.PowerColors["MANA"]
      return "|cff%02x%02x%02x%s |cff%02x%02x%02x%s", color[1]*255, color[2]*255, color[3]*255, Short(pCur, true), DManaColor[1]*255, DManaColor[2]*255, DManaColor[3]*255, Short(pCurMana, true)
    end
  else
    return "|cff%02x%02x%02x%s", color[1]*255, color[2]*255, color[3]*255, Short(pCur, true)
  end
end
  Reply With Quote
03-08-16, 05:59 PM   #7
slayos
A Deviate Faerie Dragon
 
slayos's Avatar
Join Date: May 2015
Posts: 15
Diffrent text!

[quote=Nibelheim;239706]Some examples:

Power (supports Druid Mana and Alt Power types)
Code:
local color
local pType, pToken, altR, altG, altB = UnitPowerType(unit)
local pCur, pMax, pCurMana, pMaxMana = Power(unit), MaxPower(unit), Power(unit, 0), MaxPower(unit, 0)

if (pMax > 0) then
  if PitBull4.PowerColors[pToken] then
    color = PitBull4.PowerColors[pToken]
  else
    if (not altR) then
      color = PitBull4.PowerColors["MANA"]
    else
      color = {[1] = altR, [2] = altG, [3] = altB}
    end
  end
  
  if (pToken ~= "MANA") then
    if (pMaxMana > 0) then
      local DManaColor = PitBull4.PowerColors["MANA"]
      return "|cff%02x%02x%02x%s |cff%02x%02x%02x%s", color[1]*255, color[2]*255, color[3]*255, Short(pCur, true), DManaColor[1]*255, DManaColor[2]*255, DManaColor[3]*255, Short(pCurMana, true)
    end
  else
    return "|cff%02x%02x%02x%s", color[1]*255, color[2]*255, color[3]*255, Short(pCur, true)
  end
end

Is it possible to make this code show as "current insted of short" f.ex show mana aka power as 32000 insted of 32.0k ?

Last edited by slayos : 03-08-16 at 06:03 PM.
  Reply With Quote
03-09-16, 11:02 AM   #8
sirann
A Flamescale Wyrmkin
Join Date: Mar 2007
Posts: 142
I think swapping the two instances of "Short(pCur, true)" with "pCur" no quotes, and the one instance of "Short(pCurMana, true)" with "pCurMana" no quotes should work
  Reply With Quote
03-10-16, 11:41 AM   #9
slayos
A Deviate Faerie Dragon
 
slayos's Avatar
Join Date: May 2015
Posts: 15
Originally Posted by sirann View Post
I think swapping the two instances of "Short(pCur, true)" with "pCur" no quotes, and the one instance of "Short(pCurMana, true)" with "pCurMana" no quotes should work
it worked! thank you, i have an otther issue aswell if you'd like to help me out? here it goes!
local s = Status(unit)
if s then
return s
end
local s = Status(unit)
if s then
return s
end
local cur, max = HP(unit), MaxHP(unit)
if UnitIsFriend(unit,"player") then
local perc = Percent(cur,max)
if perc >= 76 then
return "|cff00d036%s%%|r", perc
elseif perc >= 26 then
return "|cfff19c08%s%%|r",perc
else
return "|cfff10808%s%%|r",perc
end
else
return "%s/%s",Short(cur,true),Short(max,true)
end
This code is displaying player health names like this "100%" with some nice coloring from green -> orange -> red depending on your health, but I want it to look like this "418500" with the coloring ofc., also displays bosses like this "17.2k/17.2k" with no coloring but that's fine, but whatt I want is it to display bosses like this "17200 | 100%", I really do appreciate in advance!

Last edited by slayos : 03-10-16 at 12:09 PM.
  Reply With Quote
03-10-16, 12:10 PM   #10
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,214
local perc = Percent(cur,max)

Would appear to be converting current health into a percentage of max so if you just change perc to cur as the return by:
Code:
	if perc >= 76 then
		return "|cff00d036%s%%|r", cur
	elseif perc >= 26 then
		return "|cfff19c08%s%%|r",cur
	else
		return "|cfff10808%s%%|r",cur
	end
You also have duplicate
Code:
local s = Status(unit)
if s then
    return s
end
Statements.

For the boss (this will change the display for any unfriendly target) you woulld need to substitute
Code:
else
	return "%s/%s",Short(cur,true),Short(max,true)
for
Code:
else
	return Percent(cur,max)
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 03-10-16 at 12:16 PM.
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » PitBull4 Lua texts - Colored health and 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