Thread Tools Display Modes
11-01-12, 02:57 PM   #1
Wowguy25
A Deviate Faerie Dragon
Join Date: Nov 2012
Posts: 17
Need help with a simple lua string

I need a lua string for my unit frames that does the following:

"Level" + [level] + [elite] + [classification OR class]

So basically it would produce something like this: "Level 90 Priest" (for a player) or "Level 90 elite humanoid" (for a mob). Everything should be in white text except the "elite" in red.

I found a similar string in pitbull unit frames but it has some extra things that I don't know how to get rid of. Every attempt to edit these strings just results in an error for me because I am an ignorant clutz

Here it is:

local dr,dg,db = DifficultyColor(unit)
local form = DruidForm(unit)
local classification = Classification(unit)
if UnitIsPlayer(unit) or (not UnitIsFriend(unit,"player") and not IsPet(unit)) then
local cr,cg,cb = ClassColor(unit)
if form then
return "%s%s|cff%02x%02x%02x%s|r |cff%02x%02x%02x%s|r (%s) %s",classification or '',classification and ' ' or '',dr,dg,db,Level(unit),cr,cg,cb,Class(unit),form,SmartRace(unit) or ''
else
return "%s%s|cff%02x%02x%02x%s|r |cff%02x%02x%02x%s|r %s",classification or '',classification and ' ' or '',dr,dg,db,Level(unit),cr,cg,cb,Class(unit),SmartRace(unit) or ''
end
else
if form then
return "%s%s|cff%02x%02x%02x%s|r (%s) %s",classification or '',classification and ' ' or '',dr,dg,db,Level(unit),form,SmartRace(unit) or ''
else
return "%s%s|cff%02x%02x%02x%s|r %s",classification or '',classification and ' ' or '',dr,dg,db,Level(unit),SmartRace(unit) or ''
end
end


If anyone could edit this string for me or make a new one from scratch I would be eternally grateful
  Reply With Quote
11-01-12, 03:56 PM   #2
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,877
Which unit frames are you using? Most UF addons that I've seen have replacement string variables (tokens) that would do what you are wanting.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
11-01-12, 03:59 PM   #3
Wowguy25
A Deviate Faerie Dragon
Join Date: Nov 2012
Posts: 17
I am using pitbull 4.
  Reply With Quote
11-01-12, 04:10 PM   #4
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,877
I'm not Pitbull literate but I would suggest either checking the documentation for a list of replacement variables or in the setup see if there is someway of displaying the list (like a button) near the string you want to change.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
11-01-12, 04:22 PM   #5
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
I have not used PitBull in many years, and have never used its current tagging library LuaTexts, so this is totally untested. Let me know if it doesn't work the way you want, or at all.

Code:
if UnitIsPlayer(unit) then
	return "Level %d %s", Level(unit), Class(unit)
else
	local classification = Classification(unit)
	if classification == "Elite" then
		return "Level %d |cffff3333%s|r %s", Level(unit), classification, SmartRace(unit)
	else
		return "Level %d %s", Level(unit), SmartRace(unit)
	end
end
I'd also suggest a couple of things:

(1) Color the level by difficulty.

(2) Include other classifications (like Rare, Rare Elite, and Boss) instead of only Elite.

(3) Include something to indicate whether a non-player unit is player-controlled (like pets).

If you want to make any of those changes, let me know and I'll post adjusted code.

Also, for future reference, please use [code] tags around your code to preserve indentation (you are using indentation, right?) and prevent long lines from wrapping. Without proper formatting, your code is just an unreadable blob.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
11-01-12, 04:24 PM   #6
Wowguy25
A Deviate Faerie Dragon
Join Date: Nov 2012
Posts: 17
I don't think there is anything like that. Here is a screenshot of what it looks like:

http://i.imgur.com/FpIuz.png
  Reply With Quote
11-01-12, 04:37 PM   #7
Wowguy25
A Deviate Faerie Dragon
Join Date: Nov 2012
Posts: 17
Originally Posted by Phanx View Post
I have not used PitBull in many years, and have never used its current tagging library LuaTexts, so this is totally untested. Let me know if it doesn't work the way you want, or at all.

Code:
if UnitIsPlayer(unit) then
	return "Level %d %s", Level(unit), Class(unit)
else
	local classification = Classification(unit)
	if classification == "Elite" then
		return "Level %d |cffff3333%s|r %s", Level(unit), classification, SmartRace(unit)
	else
		return "Level %d %s", Level(unit), SmartRace(unit)
	end
end
I'd also suggest a couple of things:

(1) Color the level by difficulty.

(2) Include other classifications (like Rare, Rare Elite, and Boss) instead of only Elite.

(3) Include something to indicate whether a non-player unit is player-controlled (like pets).

If you want to make any of those changes, let me know and I'll post adjusted code.

Also, for future reference, please use [code] tags around your code to preserve indentation (you are using indentation, right?) and prevent long lines from wrapping. Without proper formatting, your code is just an unreadable blob.
Oh, that works! Thank you so much! <3

Oh and you have a fair point there so I will take number 2 from the menu please Don't care for the others though I don't think it's necessary and like to keep it clean and simple.

Sorry about the code tag I did not know that was possible. I'll use that in the future

Edit:

Oh wow I just noticed it says you are the author/maintainer of grid. While I have you here I would like to ask if there is any way to make grid sort properly by raid1 raid2 or party1 party2 etc. rather than randomly. And if not, is there any way such an option could be implemented? I'm asking because I want to use weakauras to tie into target id's like raid1 or party1 in order to make some prettier and more versatile indicators for my grid.

Last edited by Wowguy25 : 11-01-12 at 05:22 PM.
  Reply With Quote
11-01-12, 11:04 PM   #8
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by Wowguy25 View Post
I will take number 2 from the menu please
This will show Elite in red (ff3333), Rare in teal (33ffff), and Boss in yellow (ffff66). Feel free to change the colors.

Code:
if UnitIsPlayer(unit) then
	return "Level %d %s", Level(unit), Class(unit)
else
	local classification = Classification(unit)
	if classification == "elite" then
		return "Level %d |cffff3333Elite|r %s", Level(unit), SmartRace(unit)
	elseif classification == "rare" then
		return "Level %d |cff33ffffRare|r %s", Level(unit), SmartRace(unit)
	elseif classification == "rareelite" then
		return "Level %d |cff33ffffRare|r |cffff3333Elite|r %s", Level(unit), SmartRace(unit)
	elseif classification == "worldboss" then
		return "Level %d |cffffff66Boss|r %s", Level(unit), SmartRace(unit)
	else
		return "Level %d %s", Level(unit), SmartRace(unit)
	end
end
Originally Posted by Wowguy25 View Post
... make grid sort properly by raid1 raid2 or party1 party2 etc. rather than randomly.
Grid never sorts groups randomly. Depending on which layout you are using, groups can be sorted:

(a) by index -- player, party1, party2, party3, party4 -- in the By Group 5 layout,
(b) by group, and then alphabetically by name within each group, in the other By Group layouts,
(c) by class (with pure melee classes, then classes that can be either melee or ranged, and pure ranged classes last), and then alphabetically by name within each class, in the By Class layouts.

If you want to change how groups are sorted, feel free to modify (or add) the sortMethod key in the layout's table in GridLayoutLayouts.lua, or use a layout plugin to create and customize layouts in-game.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
11-04-12, 03:36 PM   #9
Wowguy25
A Deviate Faerie Dragon
Join Date: Nov 2012
Posts: 17
Originally Posted by Phanx View Post
This will show Elite in red (ff3333), Rare in teal (33ffff), and Boss in yellow (ffff66). Feel free to change the colors.

Code:
if UnitIsPlayer(unit) then
	return "Level %d %s", Level(unit), Class(unit)
else
	local classification = Classification(unit)
	if classification == "elite" then
		return "Level %d |cffff3333Elite|r %s", Level(unit), SmartRace(unit)
	elseif classification == "rare" then
		return "Level %d |cff33ffffRare|r %s", Level(unit), SmartRace(unit)
	elseif classification == "rareelite" then
		return "Level %d |cff33ffffRare|r |cffff3333Elite|r %s", Level(unit), SmartRace(unit)
	elseif classification == "worldboss" then
		return "Level %d |cffffff66Boss|r %s", Level(unit), SmartRace(unit)
	else
		return "Level %d %s", Level(unit), SmartRace(unit)
	end
end


Grid never sorts groups randomly. Depending on which layout you are using, groups can be sorted:

(a) by index -- player, party1, party2, party3, party4 -- in the By Group 5 layout,
(b) by group, and then alphabetically by name within each group, in the other By Group layouts,
(c) by class (with pure melee classes, then classes that can be either melee or ranged, and pure ranged classes last), and then alphabetically by name within each class, in the By Class layouts.

If you want to change how groups are sorted, feel free to modify (or add) the sortMethod key in the layout's table in GridLayoutLayouts.lua, or use a layout plugin to create and customize layouts in-game.
Thank you. I got the grid thing to work which I'm very happy about! <3

However there seems to be some problem with your lua code. I tried it a bit and it works on players and npc's in dalaran. But on Rhonin and Vereesa I only get {err}. I'm assuming they are elites. Any ideas?
  Reply With Quote
11-04-12, 10:38 PM   #10
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Without a more verbose error message or knowing anything about how LuaTexts works internally, I'd have to assume that it's because those NPCs show a level of ?? instead of a number. Try replacing all of the %d tokens in NPC format strings with %s so they won't fail on non-numeric values.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
11-05-12, 06:29 AM   #11
Wowguy25
A Deviate Faerie Dragon
Join Date: Nov 2012
Posts: 17
Originally Posted by Phanx View Post
Without a more verbose error message or knowing anything about how LuaTexts works internally, I'd have to assume that it's because those NPCs show a level of ?? instead of a number. Try replacing all of the %d tokens in NPC format strings with %s so they won't fail on non-numeric values.
That did it! I don't know what I would do without knowledgeable helpful heroes like you! <3 Well, I'd be sitting around with a crappy UI I guess Thanks!
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Need help with a simple lua string


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