|
12-19-10, 03:40 PM | #1 |
Stuf Unit LUA help
I have this for my target name but I was hoping someone could help me with adding level and class color to the string.
function(unit) local name = UnitName(unit) if (name and string.len(name) > 10) then name = string.gsub(name, "([^%s]+) ", function(s) return string.sub(s,1,1) .. "." end) end return name end This code works fine as is but I can figure out how to add class color to the text or the level to it either. thanks much! |
|
12-19-10, 04:09 PM | #2 |
Try this - it's based on portions of the "Target Name" text I use in my StUF uf's. This leaves the level uncolored, but colors the name by class.
Code:
function(unit) local name, level = UnitName(unit), UnitLevel(unit) local clcolor = RAID_CLASS_COLORS[select(2, UnitClass(unit))] if (name and string.len(name) > 10) then name = string.gsub(name, "([^%s]+) ", function(s) return string.sub(s,1,1) .. "." end) end return "%s |cff%02x%02x%02x%s|r", level, clcolor.r*255, clcolor.g*255, clcolor.b*255, name end
__________________
-- Taryble Last edited by Taryble : 12-20-10 at 12:24 AM. |
|
12-19-10, 05:26 PM | #3 |
Just a quick question....Maybe i should start a new topic but it is directly related to what this post is about...What is the advantage of using LUA code to display name versus using the tags that exist in STUF already?
__________________
Don't you let regret take place
of the dreams you have to chase... |
|
12-19-10, 06:13 PM | #4 | |
BTW Worked fine but I have a weird thing with the name...between the level and the name I am getting an extra character - like on mob target its a "d" and on players it's an "5" and if I target myself, its a little 'o"(without quote marks). c/p'd twice and still same results..any clue? Last edited by Porsha : 12-19-10 at 06:18 PM. |
||
12-20-10, 12:23 AM | #5 |
Yeah, 3 tiny typo's in the "return" line.
Change all of the *256 to *255. My bad. I'm going to edit the original post as well.
__________________
-- Taryble |
|
12-20-10, 12:35 AM | #6 | |
For example, this is what I use for my text1 Code:
function(unit, cache, textframe) local cc = RAID_CLASS_COLORS[select(2, UnitClass("player"))] if UnitExists(unit) then cc = RAID_CLASS_COLORS[select(2, UnitClass(unit))] end local curhp, maxhp = UnitHealth(unit), UnitHealthMax(unit) if curhp ~= maxhp then local perchp, diffhp = 100 * curhp / maxhp, maxhp - curhp return "|cff%02x%02x%02x%.0f|r%% | |cffff0000-%s|r",cc.r*255,cc.g*255,cc.b*255,perchp,diffhp else local name = UnitName("player") if UnitExists(unit) then name = UnitName(unit) end return "|cff%02x%02x%02x%s|r",cc.r*255,cc.g*255,cc.b*255,string.gsub(name, '%s?(.)%S+%s', '%1. ') end end What this mainly does, however, is it gives you a class-colored name. Multiple-word names ("Angry Guardsman") gives an abbreviated version ("A. Guardsman"). However, if you are not at full HP, it shows an HP Deficit text, a pipe, and then HP Percent. The only part of that, really, that I needed to use custom Lua for was the abbreviation of the names. However, because of that, I had to write the rest in Lua as well. Here's a more interesting text that I use (my "Power" text). Code:
function(unit, cache, textframe) local powtype, maxmp, curmp = UnitPowerType(unit), UnitPowerMax(unit), UnitPower(unit) local cc = PowerBarColor[powtype] local permp = 100*curmp/maxmp if (powtype == 1 or powtype == 3) then local _, class = UnitClass(unit) if (class == "DRUID" and unit == "player") then local maxdmp, curdmp, ccd = UnitPowerMax(unit,0), UnitPower(unit,0), PowerBarColor[0] if curdmp ~= maxdmp then return "|cff%02x%02x%02x%.0f|r%% | |cff%02x%02x%02x%s|r",ccd.r*255,ccd.g*255,ccd.b*255,100*curdmp/maxdmp,cc.r*255,cc.g*255,cc.b*255,curmp else return "|cff%02x%02x%02x%s|r",cc.r*255,cc.g*255,cc.b*255,curmp end else return "|cff%02x%02x%02x%s|r",cc.r*255,cc.g*255,cc.b*255,curmp end elseif curmp ~= maxmp then return "|cff%02x%02x%02x%.0f|r%%",cc.r*255,cc.g*255,cc.b*255,permp elseif powtype == 0 then return "|cff%02x%02x%02x%s|r",cc.r*255,cc.g*255,cc.b*255,maxmp end end If you're anything else, it shows your percentage of power - but if you're at full power, it just shows your maximum power. (ie, 99% OR 78532, for example). And, yes, all you Lua coders out there, please feel free to take a look at it and give me advice on how to make it better. I haven't really done any programming since 1997, and Lua wasn't very common back then, so this is all sorta tossed together with half-remembered scraps of programming theory and style.
__________________
-- Taryble |
||
12-20-10, 06:37 PM | #7 |
You are a doll! I am totally hijacking those for mine as they are tons more effiecent space wise than mine now - I have my power/hp on mourseover cause I havent had the room to "fit it all in" so thank you so much for sharing!
Funny how I looked /goggle for some threads on STUF LUA I could jack but found none (even the one on EJ was locked/outdated cause all my old codes no longer work with STUF any more) and the thread on the old WoW forums is gone now since Cata. So thanks again and I'll be sure if I find more to post them in hopes they help some out. OH - These below were taken from maybe Fuji or (dang I cant remember the name but they did a Paladin UI with vertical coding) these are UNTESTED for the most part but someone may know how to get the to work again....I'm sure its simple wording or something but I dont use them any more so...I will separate them with --------- BLOCK OF TEXT INC!! Code:
function(unit, cache) local str1 = '' local str2 = '' local str3 = '' local str4 = '' local str5 = '' local _, partyMaster, _ = GetLootMethod() if UnitAffectingCombat("player") == 1 then str1 = 'C' end if IsRaidLeader("player")==1 then str2 = 'L' end if UnitIsPVP("player") == 1 then str3 = 'P' end if partyMaster == 0 then str5 = '+' end if IsResting("player") == 1 then str4 = 'R' end return '|cffff4500%s|r |cffffff00%s|r |cffff9900%s|r |cff00ff00%s|r |cffffffff%s|r ', str1,str2,str3,str4,str5 end PET: Code:
function(unit, cache, textframe) local name = UnitName( unit ) if name ~= nil then local strLen = strlen( name ) local tmp = '' local outStr = '' if strLen > 14 then strLen = 14 end for i = 1, strLen, 1 do tmp = strsub( name, i, i ) if i == 1 then outStr = outStr..tmp else outStr = outStr..'\n'..tmp end end return '%s', outStr end end PET HAPPY: Code:
function(unit, cache, textframe) local happiness,_ = GetPetHappiness(unit) if happiness == 1 then return "|cffff2400*|r" elseif happiness == 2 then return "|cffFFD700*|r" elseif happiness == 3 then return "|cff238E23*|r" end end COMBO POINTS: Code:
function(unit, cache, textframe) local comboPoints = GetComboPoints(unit) local outStr = '' if comboPoints ~= 0 then for i = 1, comboPoints, 1 do outStr = outStr .. '*\n' end return '|cffFFFF00%s|r', outStr end end function(unit, cache, textframe) local comboPoints = GetComboPoints(unit) local outStr = '' if comboPoints ~= 0 then for i = 1, comboPoints, 1 do outStr = outStr .. '*' end return '|cffFFFF00%s|r', outStr end end STRING STATES: Code:
function(unit, cache) local str1 = '' local str2 = '' local str3 = '' local str4 = '' local str5 = '' local cr1 = '' local cr2 = '' local cr3 = '' local cr4 = '' local cr5 = '' local _, partyMaster, _ = GetLootMethod() if UnitAffectingCombat("player") == 1 then str1 = 'C' cr1 = '\n' end if IsRaidLeader("player")==1 then str2 = 'L' cr2 = '\n' end if UnitIsPVP("player") == 1 then str3 = 'P' cr3 = '\n' end if partyMaster == 0 then str5 = '+' cr5 = '\n' end if IsResting("player") == 1 then str4 = 'R' cr4 = '\n' end return '|cffff4500%s|r%s|cffffff00%s|r%s|cffff9900%s|r%s|cff00ff00%s|r%s|cffffffff%s|r%s', str1, cr1, str2, cr2, str3, cr3, str4, cr4, str5, cr5 end -------------------------------- Code:
function(unit, cache, textframe) local name = UnitName( unit ) if name ~= nil then local strLen = strlen( name ) local tmp = '' local outStr = '' if strLen > 14 then strLen = 14 end for i = 1, strLen, 1 do tmp = strsub( name, i, i ) if i == 1 then outStr = outStr..tmp else outStr = outStr..'\n'..tmp end end return '%s', outStr end end HEALTH STRING: Code:
function(unit, cache, textframe) local curHealth = UnitHealth( unit ) local maxHealth = UnitHealthMax( unit ) local healthPercent = floor( ( curHealth / maxHealth ) * 100 ) local healthStr = tostring( healthPercent ) local strLen = strlen( healthStr ) local isEnemy = UnitIsEnemy( "Paloladin", unit ) local isDead = UnitIsDead(unit) local tmp = '' local outStr = '' if isDead == nil then for i = 1, strLen, 1 do tmp = strsub( healthStr, i, i ) if i == 1 then outStr = outStr..tmp else outStr = outStr..'\n'..tmp end end else outStr = '*\nD\nE\nA\nD\n*' end if isEnemy == nil then return '%s', outStr else return '|cffFF4500%s|r', outStr end end ----------------------------- Vertical name: Code:
function(unit, cache, textframe) local name = UnitName( unit ) if name ~= nil then local strLen = strlen( name ) local tmp = '' local outStr = '' if strLen > 14 then strLen = 14 end for i = 1, strLen, 1 do tmp = strsub( name, i, i ) if i == 1 then outStr = outStr..tmp else outStr = outStr..'\n'..tmp end end return '%s', outStr end end ---------------------------------- health vertical: Code:
function(unit, cache, textframe) local curHealth = UnitHealth( unit ) local maxHealth = UnitHealthMax( unit ) local healthPercent = floor( ( curHealth / maxHealth ) * 100 ) local healthStr = tostring( healthPercent ) local strLen = strlen( healthStr ) local isEnemy = UnitIsEnemy( "Paloladin", unit ) local isDead = UnitIsDead(unit) local tmp = '' local outStr = '' if isDead == nil then for i = 1, strLen, 1 do tmp = strsub( healthStr, i, i ) if i == 1 then outStr = outStr..tmp else outStr = outStr..'\n'..tmp end end else outStr = '*\nD\nE\nA\nD\n*' end if isEnemy == nil then return '%s', outStr else return '|cffFF4500%s|r', outStr end end Last edited by Porsha : 12-21-10 at 10:50 PM. Reason: added whitespace back in -Seerah |
|
12-20-10, 08:54 PM | #8 |
*ahem* code blocks are your friend
carry on. |
|
WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » Stuf Unit LUA help |
«
Previous Thread
|
Next Thread
»
|
Display Modes |
Switch to Linear Mode |
Hybrid Mode |
Switch to Threaded Mode |
|
|