Jump to content


LuaTexts - The new DogTags


  • Please log in to reply
234 replies to this topic

#41 Shefki

Shefki

    Von Kaiser

  • Members
  • 38 posts

Posted 18 June 2009 - 11:13 PM

crefam = UnitCreatureFamily(unit)
if crefam
"Unkown" or crefam
"Not Specified" then return "" else return "%s",crefam end



See my tag above. WoW API never actually returns Unknown that's a DogTag thing. Don't bother to return "" LuaTexts already handles that for you. Makes the code cleaner to just return nothing.

#42 Zeelian

Zeelian

    Glass Joe

  • Members
  • 14 posts

Posted 19 June 2009 - 12:19 AM

thanks shefki!

edit: can anyone tell me how to append a space to a %s value?



"Rare, Elite, Boss indicator: Nothing special here."

i guess u want text... but frame borders work well for this


Aye, want it as text since i use Roth border texture, and that won't take colors to well.


Shefki, huge thanks! I will test these out right away!

Did some digging and managed to get the class color in there, seems this old dog can actually learn some minor tricks still.

local r,g,b = ClassColor(unit)
return '|cff%02x%02x%02x%s|r ',r,g,b,string.sub(Name(unit),1,9)


One more, how would i do to make a missing HP text?
Raid health text showing X.xk when full, missing amount when not full, hidden when dead or offline.

Guessing i need some maths done with HP(unit) and MaxHP(unit).

#43 Shefki

Shefki

    Von Kaiser

  • Members
  • 38 posts

Posted 19 June 2009 - 01:23 AM

Well they're not all done yet. Still got some more stuuff to work on.

#44 Zeelian

Zeelian

    Glass Joe

  • Members
  • 14 posts

Posted 19 June 2009 - 01:49 AM

Well they're not all done yet. Still got some more stuuff to work on.


Has given me a more familiar base to start figuring out the code around. Its hard for me to try to figure it out from tags i don't use my self, but with familiar tags im starting to understand some of the basics.

#45 Dankz

Dankz

    Von Kaiser

  • Members
  • 58 posts

Posted 19 June 2009 - 02:18 AM

thanks Shefki,

Hex/base10 ARRRGHG. To be clear %02x means you are giving it numbers and 0xFF means you are giving it hex?? I'm not quite clear with how to input it as hex, although it isn't hard to input as base10.

I know I need two loops for HARMFUL and HELPFUL. There is only going to be one loop, HARMFUL in the final version. In the test form it just won't find some things it is looking for because they aren't relevant.

For people who are interested (prevent further questions) here is an image of the tag in action, and the code I am ending up using:

if not UnitIsFriend(unit,'player') then
local i = 1
local ttw,dam,hit,crit,wisdom= false,false,false,false,false
local tr,tg,tb = 255,00,00
local dr,dg,db = 255,00,00
local hr,hg,hb = 255,00,00
local cr,cg,cb = 255,00,00
local wr,wg,wb = 255,00,00
while true do
 local name,_,icon = UnitAura(unit,i,"HARMFUL")
 if not name then
   break
 elseif name == "Thunder Clap" then
   ttw = true
 elseif name == "Infected Wounds" then
   ttw = true
 elseif name == "Icy Touch" then
   ttw = true
 elseif name == "Earth and Moon" then
   dam = true
 elseif name == "Ebon Plague" then
   dam = true
 elseif name == "Curse of Elements" then
   dam = true
 elseif name == "Misery" then
   hit = true
 elseif name == "Faerie Fire" then
   hit = true
 elseif name == "Totem of Wrath" then
   crit = true
 elseif name == "Master Poisoner" then
   crit = true
 elseif name == "Heart of the Crusader" then
   crit = true
 elseif name == "Judgment of Wisdom" then
   wisdom = true
 end
 i = i + 1
end
if ttw then
 tr,tg,tb = 00,255,00
end
if dam then
 dr,dg,db = 00,255,00
end
if hit then
 hr,hg,hb = 00,255,00
end
if crit then
 cr,cg,cb = 00,255,00
end
if wisdom then
 wr,wg,wb = 00,255,00
end
return "|cff%02x%02x%02xT|r   |n|cff%02x%02x%02xD|r   |n|cff%02x%02x%02xH|r   |n|cff%02x%02x%02xC|r   |n|cff%02x%02x%02xW|r   " 

,tr,tg,tb,dr,dg,db,hr,hg,hb,cr,cg,cb,wr,wg,wb
end

PS: Hidden debuffs are evil (ie Judgment of the Just)


What would be the trick to make this horizontal instead of vertical?

And some of the Text is wrong is should be Improved Faerie Fire instead of Faerie Fire and Curse of the Elements not Curse of Elements.

#46 ctrlfrk

ctrlfrk

    Glass Joe

  • Members
  • 8 posts

Posted 19 June 2009 - 03:26 AM

What would be the trick to make this horizontal instead of vertical?


Remove the '|n's from the return string so that it looks like:

return "|cff%02x%02x%02xT|r|cff%02x%02x%02xD|r|cff%02x%02x%02xH|r|cff%02x%02x%02xC|r|cff%02x%02x%02xW|r" ,tr,tg,tb,dr,dg,db,hr,hg,hb,cr,cg,cb,wr,wg,wb

More useful information about escape codes can be found at the wowwiki page.

Edit: Chances are you can remove all but the last |r as well, no point in resetting the colour if you're just going to change it again.

#47 Dendrek

Dendrek

    Von Kaiser

  • Members
  • 29 posts

Posted 19 June 2009 - 08:05 AM

Two simple questions:
How do you get power color? PowerColor(unit) doesn't seem to work.
How do you format numbers to be separated by commas? E.g. 2000000 -> 2,000,000.

#48 rakkarage

rakkarage

    Glass Joe

  • Members
  • 6 posts

Posted 19 June 2009 - 05:07 PM

Classification(unit)+' ' or ''


does not work...

Classification(unit) and ' ' or ''


seems to work but not if i reverse it?

' ' and Classification(unit) or ''


ya idk what i am doing... i guess the [or ''] is for error handling not formatting?

is there some kinda append or prepend or trim methods i can use

thanks

#49 effexor

effexor

    Glass Joe

  • Members
  • 5 posts

Posted 19 June 2009 - 07:18 PM

Ok I am a beginner and I want to learn how to do this....my question is I enabled the LuaText module but where do I actually put in the code, in the interface or in the LUA files outside the game?

Nevermind I figured it out.

#50 Shefki

Shefki

    Von Kaiser

  • Members
  • 38 posts

Posted 19 June 2009 - 08:35 PM

does not work...



seems to work but not if i reverse it?



ya idk what i am doing... i guess the [or ''] is for error handling not formatting?

is there some kinda append or prepend or trim methods i can use

thanks


+ is an mathematical operator, it's not useful on strings in Lua.

Lua doesn't have a proper ternary operator. You can get away with:
something and value_for_true or value_for_false

But if value_for_true actually evaluates to false then that won't work either. e.g.
something and false or true

Has to be written:
not something and true or false

You can do concatenation with .. e.g.
x = ' '..' '
Would set x to two spaces.

However, I'd suggestion that you avoid doing this. Consider the following expression:
a = a .. b

This is adding the string b onto the end of the a string. Lua doesn't just expand the a string and add the contents of b. Rather it makes new string consisting of a followed by b and replaces the old a. This means the old a has to be garbage collected and causes memory churn.

Now I'm not suggesting that you never ever do something like this. Sometimes there's just no good way to achieve what you want without doint a concatenation. For the purposes of formatting I'd suggest you put your spaces in format strings.

local classification = Classification(unit)
if classification then
  return "%s %s",foo(unit),classification
else
  return "%s",classification
end

Alternatively you can do something like this:
local classification = Classification(unit)
return "%s%s%s",foo(unit),classification and ' ' or '',classification

By returning the strings separated out like this and letting the Blizzard code put them together you actually save a lot of memory churn. This is why LuaTexts doesn't just expect you to provide a single completed string but rather the format string and arguments to pass through to SetFormattedText().

#51 Shefki

Shefki

    Von Kaiser

  • Members
  • 38 posts

Posted 19 June 2009 - 08:42 PM

Two simple questions:
How do you get power color? PowerColor(unit) doesn't seem to work.


PowerColor doesn't take a unit argument it takes the name of the power.
local _,power_name = UnitPowerType(unit)
local r,g,b = PowerColor(power_name)

How do you format numbers to be separated by commas? E.g. 2000000 -> 2,000,000.


I need to add a helper SeperateDigits to do this like in DogTags. You can do what this guy did for the time being:
WowAce Forums - View Single Post - PitBull 4.0

Edit: Most recent push will have SeparateDigits now.

#52 Hotan

Hotan

    Piston Honda

  • Members
  • 135 posts

Posted 20 June 2009 - 12:02 AM

So I just updated and I got the following error, which wasn't there before:
[2009/06/19 16:52:56-589-x1]: PitBull4_LuaTexts:Party - L:Lua:Class caused the following error::
bad argument #6 to 'SetFormattedText' (string expected, got nil):
PitBull4-r20090619205137\Modules\LuaTexts\LuaTexts.lua:639: in function <...erface\AddOns\PitBull4\Modules\LuaTexts\LuaTexts.lua:595>
PitBull4-r20090619205137\Modules\LuaTexts\LuaTexts.lua:1135: in function `AddFontString'
PitBull4-r20090619205137\ModuleHandling\TextProviderModule.lua:116: in function `UpdateFrame'
PitBull4-r20090619205137\ModuleHandling\Module.lua:271: in function `Update'
PitBull4-r20090619205137\UnitFrame.lua:527: in function `Update'
PitBull4-r20090619205137\UnitFrame.lua:553: in function `UpdateGUID'
PitBull4-r20090619205137\UnitFrame.lua:243: in function <Interface\AddOns\PitBull4\UnitFrame.lua:239>
<in C code>: in function `Show'
Interface\FrameXML\SecureTemplates.lua:748: in function <Interface\FrameXML\SecureTemplates.lua:660>:
Interface\FrameXML\SecureTemplates.lua:955: in function `SecureGroupHeader_Update':
Interface\FrameXML\SecureTemplates.lua:541: in function <Interface\FrameXML\SecureTemplates.lua:539>:

  ---
Here is "Lua:Class" within my "Party-L" layout
local dr,dg,db = DifficultyColor(unit)
local form = DruidForm(unit)
local clas = Class(unit)
if clas=='Priest' then
local i = 1
while true do
 local name,_,icon = UnitAura(unit,i,"HELPFUL")
 if not name then
   break
 elseif name == "Shadowform" then
   form = "Sh"
 end
 i = i + 1
end
end
if UnitIsPlayer(unit) then
  local cr,cg,cb = ClassColor(unit)
  if form then
    return "|cff%02x%02x%02x%s|r |cff%02x%02x%02x%s|r |cff%02x%02x%02x(%s)|r "
                 ,255,204,0, SmartRace(unit),cr,cg,cb,clas,cr,cg,cb,form or ''
  else
    return "|cff%02x%02x%02x%s|r |cff%02x%02x%02x%s|r"
                 ,255,204,0, SmartRace(unit),cr,cg,cb,clas or ''
  end
else
    return "|cff%02x%02x%02x%s|r "
                 ,255,204,0,SmartRace(unit) or ''
end
Does anybody see an error there?
correlation =/= causation

#53 Aximous

Aximous

    Von Kaiser

  • Members
  • 82 posts

Posted 20 June 2009 - 12:13 AM

4th line missing a 's' in 'class'

I'd need some help with converting this monster, if it's possible at all:
[ThickOutline][Level:Hide(Level(unit="player")):DifficultyColor " " (if ((Abbreviate(Name) ~= Name) and (Length(Name) > 21)) then
    if IsPlayer then
        Abbreviate(Name):Substring(1, (Length(Abbreviate(Name)) - 1)):Replace("", "."):Substring(2):Append(" "):Upper:ClassColor Name:Replace(" ", "                            "):Substring(-15, -1):Replace(" ", ""):Truncate(21, nil):Upper:ClassColor
    else
        Abbreviate(Name):Substring(1, (Length(Abbreviate(Name)) - 1)):Replace("", "."):Substring(2):Append(" "):Upper Name:Replace(" ", "                            "):Substring(-15, -1):Replace(" ", ""):Truncate(21, nil):Upper
    end
elseif IsPlayer then
    Name:Truncate(21, nil):Upper:ClassColor
else
    Name:Truncate(21, nil):Upper
end)]


#54 Hotan

Hotan

    Piston Honda

  • Members
  • 135 posts

Posted 20 June 2009 - 12:22 AM

4th line missing a 's' in 'class'

heh, that is actually on purpose, I defined Class(unit) as clas, as confusing as it is (I should probably change that).

Regarding your tag conversion, I will try and work on it post-raid tonight. On the other hand, I probably will just pass out.
correlation =/= causation

#55 Aximous

Aximous

    Von Kaiser

  • Members
  • 82 posts

Posted 20 June 2009 - 12:44 AM

Ah indeed I missed that declaration somehow, other than that I couldn't find anything that could be a problem, about the tag I myself don't even have the courage to try translating that knowing that how much time I put in creating the dogtag.

#56 Hotan

Hotan

    Piston Honda

  • Members
  • 135 posts

Posted 20 June 2009 - 12:50 AM

Aximous: Could you describe the tag, in English, so it is easier to decode the DogTag?
correlation =/= causation

#57 Hotan

Hotan

    Piston Honda

  • Members
  • 135 posts

Posted 20 June 2009 - 06:27 AM

I wrote a tag with GetPetTimeRemaining() and it works fantastically (although my formatting method is probably not optimal:
ptime = GetPetTimeRemaining()

if ptime then

 return '%s',floor(ptime/100+.5)/10

end
However, I can't figure out which event to use (I know I will have to add it). I looked through the WoWWiki pet events, and nothing seemed logical. Any ideas?
correlation =/= causation

#58 Shefki

Shefki

    Von Kaiser

  • Members
  • 38 posts

Posted 20 June 2009 - 06:38 AM

Yup it's a bug where I got lazy. I'll get it fixed.


Fixed in the next push. You'll have to reselect the default text form the dropdown as changes to the text defaults don't update the current code in use.

#59 miLl3niUm

miLl3niUm

    Glass Joe

  • Members
  • 4 posts

Posted 20 June 2009 - 09:19 AM

Hello, I would like some conversions:

Druid mana bar: When I use Lua:Power:Mini from the presets it shows my energy instead of mana. DogTag code:
[if not IsMana then
    DruidMP:VeryShort
end]

And this is my NumTargeting code which showed how many people are targetting me or my target:
[if NumTargeting > 0 then
    NumTargeting
end]
Shefki already gave me this code but it only works for my target. For myself, it's a bit buggy, when some people target me, it doesn't change the value or when noone is targetting me sometimes it shows 1.
local prefix,num,size = "raid",0,GetNumRaidMembers()
local size = GetNumRaidMembers()
if size <= 0 then
  prefix = "party"
  size = GetNumPartyMembers() 
end
for u=1,size do
  if UnitIsUnit(prefix..u.."target", unit) then
    num = num + 1
  end
end
if num > 0 then
  return "%d", num
end


#60 Shefki

Shefki

    Von Kaiser

  • Members
  • 38 posts

Posted 20 June 2009 - 11:49 AM

Hello, I would like some conversions:

Druid mana bar: When I use Lua:Power:Mini from the presets it shows my energy instead of mana. DogTag code:

[if not IsMana then
    DruidMP:VeryShort
end]


if UnitPowerType(unit) ~= 0 then
  return VeryShort(Power(unit,0))
end

Shefki already gave me this code but it only works for my target. For myself, it's a bit buggy, when some people target me, it doesn't change the value or when noone is targetting me sometimes it shows 1.


Setup a UNIT_TARGET event with the All checkbox checked.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users