View Single Post
01-22-22, 09:10 PM   #11
Kanegasi
A Molten Giant
 
Kanegasi's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2007
Posts: 666
There's an issue with having this code happen every time you leave combat. You're creating three frames that listen to the same event every time. Eventually, over the course of a play session, you will have dozens, eventually hundreds, of triggers that lag your game every time a new nameplate appears.

Also, what is the purpose of the one second delays?

I reorganized your code so that only one frame is used. I'm assuming you want the SetScales to happen only when a nameplate appears and the three SetSizes to happen at login or end of combat. InCombatLockdown() reports true/false the status of UI combat protection, which turns on just a frame or so after PLAYER_REGEN_DISABLED and off a frame or so before PLAYER_REGEN_ENABLED.

Lua Code:
  1. --Friendly/Enemy Nameplate Size--
  2. local f=CreateFrame("frame")
  3.  
  4. --Personal Nameplate Size--
  5. f.SELF_NAMEPLATE_WIDTH = 100 --Percentage relative to default width.
  6. f.SELF_NAMEPLATE_HEIGHT = 100 --Percentage relative to default height.
  7. f.SNW = 110*(f.SELF_NAMEPLATE_WIDTH/100)
  8. f.SNH = 45*(f.SELF_NAMEPLATE_HEIGHT/100)
  9.  
  10. --Enemy Nameplate Size--
  11. f.ENEMY_NAMEPLATE_WIDTH = 85 --Percentage relative to default width.
  12. f.ENEMY_NAMEPLATE_HEIGHT = 100 --Percentage relative to default height.
  13. f.ENW = 110*(f.ENEMY_NAMEPLATE_WIDTH/100)
  14. f.ENH = 45*(f.ENEMY_NAMEPLATE_HEIGHT/100)
  15.  
  16. --Friendly Nameplate Size--
  17. f.FRIENDLY_NAMEPLATE_WIDTH = 85 --Percentage relative to default width.
  18. f.FRIENDLY_NAMEPLATE_HEIGHT = 100 --Percentage relative to default height.
  19. f.FNW = 110*(f.FRIENDLY_NAMEPLATE_WIDTH/100)
  20. f.FNH = 45*(f.FRIENDLY_NAMEPLATE_HEIGHT/100)
  21.  
  22. f:RegisterEvent("PLAYER_LOGIN")
  23. f:RegisterEvent("PLAYER_REGEN_ENABLED")
  24. f:RegisterEvent("NAME_PLATE_UNIT_ADDED")
  25. f:SetScript("OnEvent",function(self,event,unit)
  26.     if not InCombatLockdown() then
  27.         if unit then
  28.             if UnitIsUnit(unit,"player") then
  29.                 C_NamePlate.GetNamePlateForUnit(unit).UnitFrame:SetScale(self.SNH/45) --
  30.             elseif UnitCanAttack(unit,"player") then
  31.                 C_NamePlate.GetNamePlateForUnit(unit).UnitFrame:SetScale(self.ENH/45) --
  32.             else
  33.                 C_NamePlate.GetNamePlateForUnit(unit).UnitFrame:SetScale(self.FNH/45) --
  34.             end
  35.         end
  36.         C_NamePlate.SetNamePlateSelfSize(((self.SNH/45/2)*2.44444)/1.22222*self.SNW,45)
  37.         C_NamePlate.SetNamePlateEnemySize(((self.ENH/45/2)*2.44444)/1.22222*self.ENW,45)
  38.         C_NamePlate.SetNamePlateFriendlySize(((self.FNH/45/2)*2.44444)/1.22222*self.FNW,45)
  39.     end
  40. end)

Last edited by Kanegasi : 01-22-22 at 11:43 PM. Reason: forgot to add frame reference to six variable usages and let the setsizes happen at every event
  Reply With Quote