I'm trying to create a Lua Text in Pitbull 4 that will show the following:
Level Race Class Elite/Boss/Rare
But what I'm trying to do is for it to Display Class if it's a player OR Elite/Boss/Rare if it's an NPC and meets any of those criteria.
This is the code I currently have for Level and Race:
local dr,dg,db = DifficultyColor(unit)
return "|cff%02x%02x%02x%s%s|r %s",dr,dg,db,Level(unit),Classification(unit) and '+' or '',SmartRace(unit) or
And this is the code I have for Class OR Rare/Elite/Boss:
if UnitIsPlayer(unit) then
local cr,cg,cb = ClassColor(unit)
return "|cff%02x%02x%02x%s|r",cr,cg,cb,Class(unit)
end
local class = Classification(unit)
if class == "Boss" then
return "|cffff0000Boss|r"
elseif class == "Rare" then
return "|cffaaaaaaRare|r"
elseif class == "Elite" then
return "|cffffff00Elite|r"
end
I need to somehow combine the two but I have no idea how. Any help is greatly appreciated!
Forgot to mention that I want the level colored depending on level, and also class text colored by class. The Rare/Elite/Boss text also colored. Basically the way I already have it. All I want is to combine the two blocks of code. :D
local dr, dg, db = DifficultyColor(unit)
if UnitIsPlayer(unit) then
local cr, cg, cb = ClassColor(unit)
return "|cff%02x%02x%02x%s%s|r |cff%02x%02x%02x%s|r", dr, dg, db, Level(unit), cr, cg, cb, Class(unit)
end
local class = Classification(unit)
if class == "Boss" then
return "|cff%02x%02x%02x%s%s|r |cffff0000Boss|r", dr, dg, db, Level(unit)
elseif class == "Rare" then
return "|cff%02x%02x%02x%s%s|r |cffaaaaaaRare|r", dr, dg, db, Level(unit)
elseif class == "Elite" then
return "|cff%02x%02x%02x%s%s|r |cffffff00Elite|r", dr, dg, db, Level(unit)
end
return "|cff%02x%02x%02x%s%s|r", dr, dg, db, Level(unit)
And is there any way to right side align the different text parts? As you can see in the picture link above, the unit frame to the right have perfectly aligned to the health bar, where on the left unit frame the name is too far to the left.
On a third note, is there somehow to make different lengths for each bar, so i can for an example make the mana-bar shorter than the health-bar?
1) Post the LuaTexts code/string you're already using that you want to add the realm name to.
2) Anything related to text alignment or bar sizing is specific to whichever unit frame addon you're using, and cannot be affected by LuaTexts. LuaTexts is just a string formatting library to provide the actual text content. You'll need to ask those questions in the thread or download page for the specific addon you're using.
You helped me alot last time I played wow and I have used that and alot of copy paste to almost finish it but I am still having trouble with hostile and class coloring I can only produce Err what ever I try.
I played with what you posted a coupple of pages back but I dont have any exitsing code to use.
I would like class coloring for player and hostile colors for npc dont know about player pets but I do hate that blue color. I hope you can help out yet again
Hey Phanx I actually managed to cut 'n paste some code together that works for me but would like your help to perfect it
I am using classcolored Minehealth and would like to have percent on a new line but cant get it to work (n/) This also show dead with a timer I would like to move dead up to my name where I have my afk flags but would like to remove timers for bot afk and dead
health
Outline()
local s = Status(unit)
local cr,cg,cb = ClassColor(unit)
if s
then
return s
end
return "|cff%02x%02x%02x%s|r",cr,cg,cb, VeryShort(HP(unit),true)
name
Outline()
local cr,cg,cb
if not (UnitIsPlayer(unit)
or UnitPlayerControlled(unit))
then
cr,cg,cb = HostileColor(unit)
else
cr,cg,cb = ClassColor(unit)
end
return " |cff%02x%02x%02x%s|r |cffff0000%s|r |cffff0000%s|r",cr,cg,cb,Name(unit),Angle(AFK(unit) or DND(unit))
I am just using minipower but would like for it to disapear when empty
Outline()
local max = MaxPower(unit)
if max > 0 then
return VeryShort(Power(unit))
end
and lastly my class code I would like to include non elites in the class color tag too
Outline()
local dr,dg,db = ClassColor(unit)
local race = SmartRace(unit)
local r, g, b = DifficultyColor(unit)
local c = UnitClassification(unit)
if c == "worldboss"
then
return "|cff%02x%02x%02x%s|r %s |cff%02x%02x%02x%s|r ", r, g, b, Level(unit), "|cffff0000 Boss|r",dr,dg,db,race
elseif
c == "rareelite"
then
return "|cff%02x%02x%02x%s|r %s |cff%02x%02x%02x%s|r ", r, g, b, Level(unit), "|cffffcc00 Rare Elite|r",dr,dg,db,race
elseif
c == "rare"
then
return "|cff%02x%02x%02x%s|r %s |cff%02x%02x%02x%s|r ", r, g, b, Level(unit), "|cff999999 Rare|r",dr,dg,db,race
elseif
c == "elite"
then
return "|cff%02x%02x%02x%s|r %s |cff%02x%02x%02x%s|r ", r, g, b, Level(unit), "|cffffcc00 Elite|r",dr,dg,db,race
else
return "|cff%02x%02x%02x%s|r %s", r, g, b, Level(unit), race
end
This includes the status (dead etc) text in the afk/dnd string, and removes any timers:
Outline()
local cr, cg, cb
if UnitIsPlayer(unit) then
cr, cg, cb = ClassColor(unit)
else
cr, cg, cb = HostileColor(unit)
end
return " |cff%02x%02x%02x%s|r |cffff0000%s|r |cffff0000%s|r", cr, cg, cb, Name(unit), Angle(gsub(Status(unit) or AFK(unit) or DND(unit), " %(.-%)", ""))
Your power code already looks like it doesn't return anything for units with no power. If you want something else, please be more specific.
What exactly does "include non elites" mean? Units that are not bosses, rares, or elites don't have a classification. What do you want to be displayed, and what color do you want it displayed in?
Hey Phanx
Thank you for all the help I could never fix this alone.
Your name code just gives me "Err" text on pitbull
What exactly does "include non elites" mean? Units that are not bosses, rares, or elites don't have a classification. What do you want to be displayed, and what color do you want it displayed in?
I mean npc that are non elites gets the class string from what is meant to be for players
c == "elite"
then
return "|cff%02x%02x%02x%s|r %s |cff%02x%02x%02x%s|r ", r, g, b, Level(unit), "|cffffcc00 Elite|r",dr,dg,db,race
I have done it this way because I have my power bars for players by class and nps by hostility.
Many hours later I have finaly got this to work! so ignore the underline. The reason I havent deleted it, is so yo can see I am trying myself. Here is the result I wanted
Outline()
local dr,dg,db = ClassColor(unit)
local race = SmartRace(unit)
local r, g, b = DifficultyColor(unit)
local c = UnitClassification(unit)
if c == "worldboss"
then
return "|cff%02x%02x%02x%s|r %s |cff%02x%02x%02x%s|r ", r, g, b, Level(unit), "|cffff0000Boss|r",dr,dg,db,race
elseif
c == "rareelite"
then
return "|cff%02x%02x%02x%s|r %s |cff%02x%02x%02x%s|r ", r, g, b, Level(unit), "|cffffcc00Rare Elite|r",dr,dg,db,race
elseif
c == "rare"
then
return "|cff%02x%02x%02x%s|r %s |cff%02x%02x%02x%s|r ", r, g, b, Level(unit), "|cff999999Rare|r",dr,dg,db,race
elseif
c == "elite"
then
return "|cff%02x%02x%02x%s|r %s |cff%02x%02x%02x%s|r ", r, g, b, Level(unit), "|cffffcc00Elite|r",dr,dg,db,race
elseif
not (UnitIsPlayer(unit)
or UnitPlayerControlled(unit))
then
return "|cff%02x%02x%02x%s|r |cff%02x%02x%02x%s|r", r, g, b, Level(unit),dr,dg,db,race
else
return "|cff%02x%02x%02x%s|r %s", r, g, b, Level(unit),race
end
and i should have been more clear regarding the power code I have a DK and when he has no power I would like the 0 (zero) to go away
Hey again been playing some more got line brak working in pitbull so thank you for that.
been playing with class colored mini health and percent with class colored seperator it has been a pain but got it semi working but can you tell me why this works
Outline()
local cr,cg,cb
if not (UnitIsPlayer(unit)
or UnitPlayerControlled(unit))
then
cr,cg,cb = HostileColor(unit)
else
cr,cg,cb = ClassColor(unit)
end
return "|cff%02x%02x%02x%s/|r|cff%02x%02x%02x%s%%|r",cr,cg,cb, VeryShort(HP(unit),true),cr,cg,cb, Percent(HP(unit),MaxHP(unit))
but not this
local cr,cg,cb = ClassColor(unit)
end
return "|cff%02x%02x%02x%s/|r|cff%02x%02x%02x%s%%|r",cr,cg,cb, VeryShort(HP(unit),true),cr,cg,cb, Percent(HP(unit),MaxHP(unit))
This has gotten rather lenghty during the night sorry about that
Your code formatting habits are really painful... stop inserting random linebreaks in the middle of conditional statements. Also, these code snippets aren't macros, so there's no character limit; you don't have to mash everything together and use non-descriptive one-letter variable names.
Anyway:
For the level/class text, based on your code, I think the term you're looking for is "creature type" (eg. humanoid, beast, demon, elemental). In WoW terms, "classification" means rare/elite/boss, and nothing else.
To check whether you're dealing with a player unit, you don't need to check "is this unit controlled by player AND is it a player?" -- just check "is this unit a player?".
You can simplify things to:
Outline()
local dr, dg, db = DifficultyColor(unit)
if UnitIsPlayer(unit) then
return "|cff%02x%02x%02x%s|r %s", dr, dg, db, Level(unit), SmartRace(unit)
end
local classification = UnitClassification(unit)
if classification == "worldboss" then
classification = "|cffff0000 Boss|r"
elseif c == "rareelite" then
classification = "|cffffcc00 Rare Elite|r"
elseif c == "rare" then
classification = "|cff999999 Rare|r"
elseif c == "elite" then
classification = "|cffffcc00 Elite|r"
elseif not UnitIsPlayer(unit) then
classification = ""
end
local cr, cg, cb = ClassColor(unit)
return "|cff%02x%02x%02x%s|r%s |cff%02x%02x%02x%s|r", dr, dg, db, Level(unit), classification, cr, cg, cb, SmartRace(unit)
been playing with class colored mini health and percent with class colored seperator it has been a pain but got it semi working but can you tell me why this works ... but not this
Well, the obvious problem is that your second snippet has a random "end" keyword on the second line. I'd guess that LuaTexts is using safecall internally to catch and hide errors in user code snippets to prevent them from breaking the whole system, but this is definitely causing an error.
That said, you're also overcomplicating your first snippet with the player check. If the unit is a player, it's player-controlled by definition, so there's no need to check both, and if you only care that it's player-controlled (eg. a player OR a pet) then you don't need to check if it's a player first, since "player-controlled" already includes that case. Also, it's more sensible (and more efficient) to do "if X then A else B" instead of "if not X then B else A":
Outline()
local cr, cg, cb
if UnitPlayerControlled(unit) then
cr, cg, cb = ClassColor(unit)
else
cr, cg, cb = HostileColor(unit)
end
return "|cff%02x%02x%02x%s/|r|cff%02x%02x%02x%s%%|r", cr, cg, cb, VeryShort(HP(unit), true), cr, cg, cb, Percent(HP(unit), MaxHP(unit))
Change UnitPlayerControlled to UnitIsPlayer if you want this check to only include players, and exclude pets.
Your code formatting habits are really painful... stop inserting random linebreaks in the middle of conditional statements. Also, these code snippets aren't macros, so there's no character limit; you don't have to mash everything together and use non-descriptive one-letter variable names.
It assumes I have code habbits ;D
If it was unclear I have absolutely no understanding of lua or coding in general I have been searching google for days and hours to find something that does something similar to what I want I then use copy and paste until something works ;)
and the line breaks ehh was an attempt to clean up after notepad that for some reasen inserted 4 or 5 lines after a paste to wow (have gone over to ++)
ok to the problems at hand
just fyi I am using Pitbull if that helps
your name string with the time for status removed dont work it, I think its related to the "gsub"
Outline()
local cr, cg, cb
if UnitIsPlayer(unit) then
cr, cg, cb = ClassColor(unit)
else
cr, cg, cb = HostileColor(unit)
end
return " |cff%02x%02x%02x%s|r |cffff0000%s|r |cffff0000%s|r", cr, cg, cb, Name(unit), Angle(gsub(Status(unit) or AFK(unit) or DND(unit), " %(.-%)", ""))
here is the error message
Message: [string "PitBull4_LuaTexts:Normal:Lua:Name"] line 8:
bad argument #1 to 'gsub' (string expected, got nil)
and the level/class text, ignores the elite text so when its elites it just get the rreturn string but without clasification I have not tested on rares.
The power string works great on my dk but bugs out on everyone else
Outline()
local power = MaxPower(unit) > 0 and Power(unit)
return power > 0 and VeryShort(power) or nil
Message: PitBull4_LuaTexts:Normal:Lua:Power caused the following error:
bad argument #3 to 'SetFormattedText' (number expected, got no value)
and the level/class text, ignores the elite text so when its elites it just get the rreturn string but without clasification I have not tested on rares.
Change each instance of "c" to "classification" (eg. if c == "rare" then --> if classification == "rare" then).
If you want to use a fixed color, just hard-code that in the formatting string:
return '|cffc8b464%s|r', Name(unit)
To trim the name to a fixed number of characters, use the string.sub function:
local name = Name(unit)
local trimmed_name = string.sub(name, 1, 10)
Then include the dots in your formatting string:
return '|cffc8b464%s..|r', trimmed_name
However, note that string.sub is not Unicode-aware, so it can break the display of names with accented letters or Russian/Korean/Chinese characters, since string.sub will see each such character as 2 or 3 letters and may cut it off in the middle. To help avoid this, you may want to only apply the trimming to NPC names longer than 10 characters; while the basic string length function isn't Unicode aware, WoW provides a special version that is, so you can avoid trimming, say "Sömédüdé" which string.sub would count as 12 characters even though it's actually only 8. Checking the length first will also let you skip adding the ".." at the end if the name wasn't cut off.
local name = Name(unit)
if strlenutf8(name) <= 10 or UnitIsPlayer(unit) then
-- Player name, or short NPC name. Don't trim.
return '|cffc8b464%s|r', name
else
-- Long NPC name. Trim!
local trimmed_name = string.sub(name, 1, 10)
return '|cffc8b464%s..|r', trimmed_name
end
I am redoing my Pitbull config and I am running into a weird problem. I want a multiline display in my healthbar.
left:
Name
<Guild>
right:
CurHP/MaxHP
%HP
But I am unable to group 2 LuaTexts below one another or insert a linebreak into the return statement.
I tried to escape the linebreak with "\n", "\\n" and "|n" but neither of those seem to work. Inside the health bar I can only assign left, right, center, but not above or below.
I must be missing something really obvious.
Rollback Post to RevisionRollBack
To post a comment, please login or register a new account.
where i am using it at Pitbull 4.0 unit frames > Texts > Health. it shows my hp as mini which is like "550K" with the code i wrote before post :/
hmm should we try something like if hp > 0 Dead(unit) etc. : /
I'm trying to create a Lua Text in Pitbull 4 that will show the following:
Level Race Class Elite/Boss/Rare
But what I'm trying to do is for it to Display Class if it's a player OR Elite/Boss/Rare if it's an NPC and meets any of those criteria.
This is the code I currently have for Level and Race:
And this is the code I have for Class OR Rare/Elite/Boss:
I need to somehow combine the two but I have no idea how. Any help is greatly appreciated!
Forgot to mention that I want the level colored depending on level, and also class text colored by class. The Rare/Elite/Boss text also colored. Basically the way I already have it. All I want is to combine the two blocks of code. :D
If I'd like to add the realm name to the Lua:Class text, what should i then write? I've tried a bunch of different things, all resulting in errors.
It have to do with the realmName = GetRealmName() API or am I completely wrong?
https://www.dropbox.com/s/miymli0n1zdpgs5/Screenshot%202014-04-13%2005.58.16.png
And is there any way to right side align the different text parts? As you can see in the picture link above, the unit frame to the right have perfectly aligned to the health bar, where on the left unit frame the name is too far to the left.
On a third note, is there somehow to make different lengths for each bar, so i can for an example make the mana-bar shorter than the health-bar?
Thanks in advance :)
//Zloat
2) Anything related to text alignment or bar sizing is specific to whichever unit frame addon you're using, and cannot be affected by LuaTexts. LuaTexts is just a string formatting library to provide the actual text content. You'll need to ask those questions in the thread or download page for the specific addon you're using.
You helped me alot last time I played wow and I have used that and alot of copy paste to almost finish it but I am still having trouble with hostile and class coloring I can only produce Err what ever I try.
I played with what you posted a coupple of pages back but I dont have any exitsing code to use.
I would like class coloring for player and hostile colors for npc dont know about player pets but I do hate that blue color. I hope you can help out yet again
Ztrust
I am using classcolored Minehealth and would like to have percent on a new line but cant get it to work (n/) This also show dead with a timer I would like to move dead up to my name where I have my afk flags but would like to remove timers for bot afk and dead
health
name
I am just using minipower but would like for it to disapear when empty
and lastly my class code I would like to include non elites in the class color tag too
thank you hope you can help yet again
ztrust
If you don't want the dead text in the health text, just remove it:
This includes the status (dead etc) text in the afk/dnd string, and removes any timers:
Your power code already looks like it doesn't return anything for units with no power. If you want something else, please be more specific.
What exactly does "include non elites" mean? Units that are not bosses, rares, or elites don't have a classification. What do you want to be displayed, and what color do you want it displayed in?
Thank you for all the help I could never fix this alone.
Your name code just gives me "Err" text on pitbull
I mean npc that are non elites gets the class string from what is meant to be for players
vs. what I would like them to use
I have done it this way because I have my power bars for players by class and nps by hostility.
Many hours later I have finaly got this to work! so ignore the underline. The reason I havent deleted it, is so yo can see I am trying myself. Here is the result I wanted
and i should have been more clear regarding the power code I have a DK and when he has no power I would like the 0 (zero) to go away
Hey again been playing some more got line brak working in pitbull so thank you for that.
been playing with class colored mini health and percent with class colored seperator it has been a pain but got it semi working but can you tell me why this works
but not this
This has gotten rather lenghty during the night sorry about that
Anyway:
For the level/class text, based on your code, I think the term you're looking for is "creature type" (eg. humanoid, beast, demon, elemental). In WoW terms, "classification" means rare/elite/boss, and nothing else.
To check whether you're dealing with a player unit, you don't need to check "is this unit controlled by player AND is it a player?" -- just check "is this unit a player?".
You can simplify things to:
Well, the obvious problem is that your second snippet has a random "end" keyword on the second line. I'd guess that LuaTexts is using safecall internally to catch and hide errors in user code snippets to prevent them from breaking the whole system, but this is definitely causing an error.
That said, you're also overcomplicating your first snippet with the player check. If the unit is a player, it's player-controlled by definition, so there's no need to check both, and if you only care that it's player-controlled (eg. a player OR a pet) then you don't need to check if it's a player first, since "player-controlled" already includes that case. Also, it's more sensible (and more efficient) to do "if X then A else B" instead of "if not X then B else A":
Change UnitPlayerControlled to UnitIsPlayer if you want this check to only include players, and exclude pets.
I can stop reading this
It assumes I have code habbits ;D
If it was unclear I have absolutely no understanding of lua or coding in general I have been searching google for days and hours to find something that does something similar to what I want I then use copy and paste until something works ;)
and the line breaks ehh was an attempt to clean up after notepad that for some reasen inserted 4 or 5 lines after a paste to wow (have gone over to ++)
ok to the problems at hand
just fyi I am using Pitbull if that helps
your name string with the time for status removed dont work it, I think its related to the "gsub" here is the error message
and the level/class text, ignores the elite text so when its elites it just get the rreturn string but without clasification I have not tested on rares.
The power string works great on my dk but bugs out on everyone else
ok I think that was it
thanks again Ztrust
Add the green part:
DND(unit) or "", " %(.-%)", ""))
Change each instance of "c" to "classification" (eg. if c == "rare" then --> if classification == "rare" then).
That error seems to be in PitBull rather than in the LuaTexts snippet, but try this:
Is anyone maybe able to assist me?
I'd like names on Pitbull UFs to do the following:
Shadow Hunter Gar'ant to appear as Shadow Hun..
ie; truncate the name to say 10 characters and apply ".." at the end of the name.
I also have a LUA custom colour which I would like to apply to the name text but am not sure how to incorporate it into the string:
Any assistance would be most gratefully received!
Many thanks.
To trim the name to a fixed number of characters, use the string.sub function:
Then include the dots in your formatting string:
However, note that string.sub is not Unicode-aware, so it can break the display of names with accented letters or Russian/Korean/Chinese characters, since string.sub will see each such character as 2 or 3 letters and may cut it off in the middle. To help avoid this, you may want to only apply the trimming to NPC names longer than 10 characters; while the basic string length function isn't Unicode aware, WoW provides a special version that is, so you can avoid trimming, say "Sömédüdé" which string.sub would count as 12 characters even though it's actually only 8. Checking the length first will also let you skip adding the ".." at the end if the name wasn't cut off.
I am redoing my Pitbull config and I am running into a weird problem. I want a multiline display in my healthbar.
left:
Name
<Guild>
right:
CurHP/MaxHP
%HP
But I am unable to group 2 LuaTexts below one another or insert a linebreak into the return statement.
I tried to escape the linebreak with "\n", "\\n" and "|n" but neither of those seem to work. Inside the health bar I can only assign left, right, center, but not above or below.
I must be missing something really obvious.