View Single Post
02-16-14, 12:40 PM   #26
ravagernl
Proceritate Corporis
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 1,176
Originally Posted by Nynaeve View Post
Would it be difficult to vary the portrait by level, insofar as, if you wanted to use those pictures for level 90, but the old forum avatar pictures for race&class at levels 1-59, 60-69, 70-79, 80-89 respectfully?
I took the liberty and batch converted the files to tga

Something like this could work:

lua Code:
  1. local UnitIsPlayer = UnitIsPlayer
  2. local UnitClass = UnitClass
  3. local UnitRace = UnitRace
  4. local UnitSex = UnitSex
  5. local UnitLevel = UnitLevel
  6. local SetPortraitTexture = SetPortraitTexture
  7.  
  8. local _
  9.  
  10. local lower = string.lower
  11. local format = string.format
  12. local template = [[avatars\%s-%s-%s-%d]]
  13.  
  14. local function UnitAvatar(texture, unit)
  15.     if UnitIsPlayer(unit) then
  16.         local race, class, sex, level, tex
  17.         _, class = UnitClass(unit)
  18.         _, race = UnitRace(unit)
  19.         if race == 'Scourge' then
  20.             race = 'Undead'
  21.         end
  22.         sex = UnitSex(unit) == 3 and 'female' or 'male'
  23.         level = UnitLevel(unit)
  24.  
  25.         -- in case we target someone with a question mark, then they are at least 10 levels higher
  26.         if not level or level < 1 then
  27.             level = UnitLevel('player') + 10;
  28.         end
  29.  
  30.         tex = lower(format(template, class, race, sex, level > 79 and 80 or level > 69 and 70 or level > 59 and 60 or 1))
  31.         texture:SetTexture(tex)
  32.         texture:SetTexCoord(0, 1, 0, 1)
  33.         -- In case we want round ones
  34.         -- SetPortraitToTexture(texture, tex)
  35.     else
  36.         SetPortraitTexture(texture, unit)
  37.         texture:SetTexCoord(0.15, 0.85, 0.15, 0.85)
  38.     end
  39. end
Attached Files
File Type: zip avatars.zip (1.90 MB, 422 views)
  Reply With Quote