Advertisement
Guest User

lua for hario style name plates

a guest
Sep 30th, 2012
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.53 KB | None | 0 0
  1.  
  2. NAME:
  3. local abbr = Name(unit)
  4. if abbr:len() > 20 and  abbr:find(" ") then
  5.   abbr = abbr:gsub("([^ ]+) +",
  6.     function(text)
  7.         return text:sub(1,1) .. ". "
  8.     end)
  9. elseif abbr:len() > 20 then
  10.     abbr = abbr:truncate(15)
  11. else
  12.     abbr = abbr
  13. end
  14.  
  15. return "%s", abbr
  16.  
  17.  
  18. PERCENT HP:
  19. local health_text = ""
  20. local c_health, m_health = HP(unit), MaxHP(unit)
  21. local p_health = Round(Percent(c_health, m_health), 1)
  22. local hr, hg, hb = 255, 255, 255
  23. local wr, wg, wb = 255, 150, 0
  24. local er, eg, eb = 255, 40, 25
  25. local ewr, ewg, ewb = 255, 100, 100
  26. local dr, db, db = 192, 192, 192
  27. local xr, xg, xb = 128, 128, 128
  28.  
  29. -- dead
  30. if Dead(unit) then
  31.     health_text = string.format("|cff%02x%02x%02x%s|r", xr, xg, xb, "XX")
  32. elseif IsOffline(unit) then
  33.     health_text = string.format("|cff%02x%02x%02x%s|r", dr, dg, db, "OL")
  34. elseif c_health == m_health then
  35.     health_text = ""
  36. else
  37.     -- normal
  38.     health_text = string.format("%i", p_health)
  39.  
  40.     -- execute
  41.     if ceil(p_health) <= 25 then
  42.         health_text = string.format("|cff%02x%02x%02x%i|r", er, eg, eb, p_health)
  43.     end
  44.  
  45.     -- 10% warnning (over 30% only)
  46.     if  ((floor(p_health) % 10) == 0) and p_health >= 40 then
  47.     health_text = string.format("|cff%02x%02x%02x%.1f|r", wr, wg, wb, p_health)
  48.     end
  49.    
  50.     -- 5% warning (under 35% only)
  51.     if  ((floor(p_health) % 5) == 0) and p_health <= 35 then
  52.         health_text = string.format("|cff%02x%02x%02x%.1f|r", wr, wg, wb, p_health)
  53.     end
  54.    
  55.     -- 5% warning under 25%
  56.     if  ((floor(p_health) % 5) == 0) and p_health <= 25 then
  57.         health_text = string.format("|cff%02x%02x%02x%.1f|r", ewr, ewg, ewb, p_health)
  58.     end
  59.    
  60. end
  61.  
  62. return health_text
  63.  
  64. STATS:
  65. local stats_string = ""
  66.  
  67. -- Build the power Display
  68. local power_names = {[1]="R", [2]="F", [3]="E", [6]="P"}
  69. local c_power, m_power = Power(unit), MaxPower(unit)
  70. local pr, pg, pb = PowerColor((select(2,UnitPowerType(unit))))
  71. local c_p_abbr, c_d_power = VeryShort(c_power)
  72. local m_p_abbr, m_d_power = VeryShort(m_power)
  73. local power_text = ""
  74.  
  75.  
  76. c_p_abbr = string.gsub(string.sub(string.format(c_p_abbr, 0), -1), "0", "")
  77. m_p_abbr = string.gsub(string.sub(string.format(m_p_abbr, 0), -1), "0", "")
  78.  
  79. local power_type_i, power_type = UnitPowerType(unit)
  80. local power_name = power_names[power_type_i]
  81.  
  82. local p_abbr = string.sub(power_type, 0, 1)
  83. if Dead(unit) or IsOffline(unit) or m_power <= 1 then
  84.     power_text = ""
  85. elseif power_name == "R" or power_name == "P" then
  86.     if c_power == 0 then
  87.         power_text = string.format("")
  88.     else
  89.         power_text = string.format("%i|cff%02x%02x%02x%s|r", c_d_power, pr, pg, pb, power_name)
  90.     end
  91. elseif power_name == "F" or power_name == "E" then
  92.         if c_power == m_power then
  93.         power_text = string.format("")
  94.     else
  95.         power_text = string.format("%i|cff%02x%02x%02x%s|r", c_d_power, pr, pg, pb, power_name)
  96.     end
  97. else
  98.     if c_power == m_power then
  99.         power_text = string.format("%i|cff%02x%02x%02x%s|r Mana", c_d_power, pr, pg, pb, c_p_abbr)
  100.     else
  101.         power_text = string.format("|cff%02x%02x%02x%i|r|cff%02x%02x%02x%s|r |cff%02x%02x%02x%s|r |cff%02x%02x%02x%i|r|cff%02x%02x%02x%s|r",
  102.             255, 255, 255, c_d_power,
  103.             pr, pg, pb, m_p_abbr,
  104.             128, 128, 128, "/",
  105.             255, 255, 255, m_d_power,
  106.             pr, pg, pb, m_p_abbr)
  107.     end    
  108. end
  109.  
  110. -- Build the current health display
  111. local health_text = ""
  112. local c_health, m_health = HP(unit), MaxHP(unit)
  113. local hr, hg, hb = 255, 255, 255
  114.  
  115. if Percent(c_health, m_health) < 90 then hr, hg, hb = 255, 243, 161 end
  116. if Percent(c_health, m_health) < 70 then hr, hg, hb = 250, 195, 124 end
  117. if Percent(c_health, m_health) < 50 then hr, hg, hb = 252, 107, 56 end
  118. if Percent(c_health, m_health) < 25 then hr, hg, hb = 251, 15, 15 end
  119.  
  120. local c_h_abbr, c_d_health = VeryShort(c_health)
  121. local m_h_abbr, m_d_health = VeryShort(m_health)
  122. c_h_abbr = string.gsub(string.sub(string.format(c_h_abbr, 0), -1), "0", "")
  123. m_h_abbr = string.gsub(string.sub(string.format(m_h_abbr, 0), -1), "0", "")
  124.  
  125.  if Dead(unit) then
  126.      health_text = string.format("|cff%02x%02x%02x%s|r", 128, 128, 128, Dead(unit))
  127. elseif IsOffline(unit) then
  128.     health_text = string.format("|cff%02x%02x%02x%s|r", 96, 96, 96, Offline(unit))
  129. elseif c_health < m_health then
  130.     health_text = string.format("%i%s / %i%s Health", c_d_health, c_h_abbr, m_d_health, m_h_abbr)
  131.     health_text = string.format("|cff%02x%02x%02x%i|r|cff%02x%02x%02x%s|r |cff%02x%02x%02x%s|r |cff%02x%02x%02x%i|r|cff%02x%02x%02x%s|r Health",
  132.         hr, hg, hb, c_d_health,
  133.         255, 255, 255, c_h_abbr,
  134.         128, 128, 128, "/",
  135.         hr, hg, hb, m_d_health,
  136.         255, 255, 255, m_h_abbr)
  137. elseif m_health > 5 then
  138.     health_text = string.format("|cff%02x%02x%02x%i|r|cff%02x%02x%02x%s|r Health",
  139.     hr, hg, hb, c_d_health,
  140.     50, 255, 50, c_h_abbr)
  141. else
  142.     health_text = ""
  143. end
  144.  
  145. -- Build the class / race / level string
  146. local cr, cg, cb = ClassColor(unit)
  147. local dr, dg, db = DifficultyColor(unit)
  148. local ar, ag, ab = HostileColor(unit)
  149. local class_race_level = string.format("|cff%02x%02x%02x%s|r |cff%02x%02x%02x%s|r |cff%02x%02x%02x%s|r",
  150.     dr, dg, db, Level(unit),
  151.     ar, ag, ab, SmartRace(unit),
  152.     cr, cg, cb, Class(unit))
  153.  
  154. if SmartRace(unit) == "Non-combat Pet" or SmartRace(unit) == "Critter" then
  155.     stats_string = string.format("|cff%02x%02x%02x%s|r\n \n \n", 128, 128, 128, SmartRace(unit))
  156. else
  157.     stats_string = class_race_level .. "\n" .. health_text .. "\n" .. power_text .. "\n"
  158. end
  159.  
  160. return stats_string
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement