View Single Post
01-22-22, 05:41 PM   #10
Zaqqari
A Deviate Faerie Dragon
Join Date: Aug 2019
Posts: 11
Sorry for re-posting, but I'm having another nameplate issue. I have a script that changes the width of nameplates, and it works as long as I'm not in combat when my interface is loaded. The nameplate settings are protected functions and cannot be modified in combat. A workaround for this might be to initiate the script whenever I leave combat in addition to when I load my interface for the first time. I'm trying to add PLAYER_LEAVE_COMBAT to PLAYER_LOGIN, but it's not working.

Lua Code:
  1. --Friendly/Enemy Nameplate Size--
  2. local f = CreateFrame("Frame")
  3. f:RegisterEvent("PLAYER_LOGIN")
  4. f:RegisterEvent("PLAYER_LEAVE_COMBAT")
  5. f:SetScript("OnEvent", function()
  6.    
  7.     nameplateSize()
  8.  
  9. end)
  10.  
  11. function nameplateSize()
  12.    
  13.     --Friendly Nameplate Size--
  14.     local FRIENDLY_NAMEPLATE_WIDTH = 85 --Percentage relative to default width.
  15.     local FRIENDLY_NAMEPLATE_HEIGHT = 100 --Percentage relative to default height.
  16.  
  17.  
  18.     local FNW = 110*(FRIENDLY_NAMEPLATE_WIDTH/100)
  19.  
  20.     local FNH = 45*(FRIENDLY_NAMEPLATE_HEIGHT/100)
  21.  
  22.     C_Timer.After(1, function() C_NamePlate.SetNamePlateFriendlySize(((FNH/45/2)*2.44444)/1.22222*FNW, 45) end);
  23.     local f = CreateFrame("Frame")
  24.     f:RegisterEvent("NAME_PLATE_UNIT_ADDED")
  25.     f:SetScript("OnEvent", function(self, event, unit)
  26.     if UnitIsFriend("player", unit) then
  27.     C_NamePlate.GetNamePlateForUnit(unit).UnitFrame:SetScale(FNH/45) --
  28.     else
  29.     end
  30.     end)
  31.  
  32.     --Enemy Nameplate Size--
  33.     local ENEMY_NAMEPLATE_WIDTH = 85 --Percentage relative to default width.
  34.     local ENEMY_NAMEPLATE_HEIGHT = 100 --Percentage relative to default height.
  35.  
  36.  
  37.     local FNW = 110*(ENEMY_NAMEPLATE_WIDTH/100)
  38.  
  39.     local FNH = 45*(ENEMY_NAMEPLATE_HEIGHT/100)
  40.  
  41.     C_Timer.After(1, function() C_NamePlate.SetNamePlateEnemySize(((FNH/45/2)*2.44444)/1.22222*FNW, 45) end);
  42.     local f = CreateFrame("Frame")
  43.     f:RegisterEvent("NAME_PLATE_UNIT_ADDED")
  44.     f:SetScript("OnEvent", function(self, event, unit)
  45.     if UnitIsEnemy("player", unit) then
  46.     C_NamePlate.GetNamePlateForUnit(unit).UnitFrame:SetScale(FNH/45) --
  47.     else
  48.     end
  49.     end)
  50.    
  51.     --Personal Nameplate Size--
  52.     local SELF_NAMEPLATE_WIDTH = 100 --Percentage relative to default width.
  53.     local SELF_NAMEPLATE_HEIGHT = 100 --Percentage relative to default height.
  54.  
  55.  
  56.     local FNW = 110*(SELF_NAMEPLATE_WIDTH/100)
  57.  
  58.     local FNH = 45*(SELF_NAMEPLATE_HEIGHT/100)
  59.  
  60.     C_Timer.After(1, function() C_NamePlate.SetNamePlateSelfSize(((FNH/45/2)*2.44444)/1.22222*FNW, 45) end);
  61.     local f = CreateFrame("Frame")
  62.     f:RegisterEvent("NAME_PLATE_UNIT_ADDED")
  63.     f:SetScript("OnEvent", function(self, event, unit)
  64.     if UnitIsEnemy("player", unit) then
  65.     C_NamePlate.GetNamePlateForUnit(unit).UnitFrame:SetScale(FNH/45) --
  66.     else
  67.     end
  68.     end)
  69.  
  70. end

EDIT: I got it working with PLAYER_REGEN_ENABLED, but I'm not sure that's always going to do the trick. There must be a better way to make the nameplates 85% of their normal width.

Last edited by Zaqqari : 01-22-22 at 05:51 PM.
  Reply With Quote