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:
--Friendly/Enemy Nameplate Size--
local f=CreateFrame("frame")
--Personal Nameplate Size--
f.SELF_NAMEPLATE_WIDTH = 100 --Percentage relative to default width.
f.SELF_NAMEPLATE_HEIGHT = 100 --Percentage relative to default height.
f.SNW = 110*(f.SELF_NAMEPLATE_WIDTH/100)
f.SNH = 45*(f.SELF_NAMEPLATE_HEIGHT/100)
--Enemy Nameplate Size--
f.ENEMY_NAMEPLATE_WIDTH = 85 --Percentage relative to default width.
f.ENEMY_NAMEPLATE_HEIGHT = 100 --Percentage relative to default height.
f.ENW = 110*(f.ENEMY_NAMEPLATE_WIDTH/100)
f.ENH = 45*(f.ENEMY_NAMEPLATE_HEIGHT/100)
--Friendly Nameplate Size--
f.FRIENDLY_NAMEPLATE_WIDTH = 85 --Percentage relative to default width.
f.FRIENDLY_NAMEPLATE_HEIGHT = 100 --Percentage relative to default height.
f.FNW = 110*(f.FRIENDLY_NAMEPLATE_WIDTH/100)
f.FNH = 45*(f.FRIENDLY_NAMEPLATE_HEIGHT/100)
f:RegisterEvent("PLAYER_LOGIN")
f:RegisterEvent("PLAYER_REGEN_ENABLED")
f:RegisterEvent("NAME_PLATE_UNIT_ADDED")
f:SetScript("OnEvent",function(self,event,unit)
if not InCombatLockdown() then
if unit then
if UnitIsUnit(unit,"player") then
C_NamePlate.GetNamePlateForUnit(unit).UnitFrame:SetScale(self.SNH/45) --
elseif UnitCanAttack(unit,"player") then
C_NamePlate.GetNamePlateForUnit(unit).UnitFrame:SetScale(self.ENH/45) --
else
C_NamePlate.GetNamePlateForUnit(unit).UnitFrame:SetScale(self.FNH/45) --
end
end
C_NamePlate.SetNamePlateSelfSize(((self.SNH/45/2)*2.44444)/1.22222*self.SNW,45)
C_NamePlate.SetNamePlateEnemySize(((self.ENH/45/2)*2.44444)/1.22222*self.ENW,45)
C_NamePlate.SetNamePlateFriendlySize(((self.FNH/45/2)*2.44444)/1.22222*self.FNW,45)
end
end)