Thread Tools Display Modes
03-29-17, 08:05 PM   #1
Joker119
A Flamescale Wyrmkin
 
Joker119's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2014
Posts: 113
Nameplate addon after 7.2

So with the changes in how nameplates are allowed to be accessed in 7.2 when you are in a dungeon or raid, my nameplate addon no longer functions, throwing a crapton of errors and screwing them over.

All my addon did was reskin the statusbar itself and use raid icons specially made to fit the rest of my UI, but, yknow, blizzard's too lazy to stop us from anchoring things to nameplates so they just make it so we can do nothing with them in dungeons. *shrug*

I need a way of determining if the player is in a dungeon or raid (or if the nameplates are turned into a protected object) so that my addon doesn't throw abunch of errors.

I do distinctly remembering blizz saying "these changes won't break existing addons, they will simple "stop working" when they enter a dungeon. Welp, it breaks my addon, not only causing LUA errors but also royally fucking over the default nameplates somehow. (not sure, don't ask *shrug*)
  Reply With Quote
03-30-17, 05:30 AM   #2
Joker119
A Flamescale Wyrmkin
 
Joker119's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2014
Posts: 113
I've tried registering the PLAYER_ENTERING_WORLD event and checking for the instanceType with IsInInstance() with this:
Code:
s:RegisterEvent("PLAYER_ENTERING_WORLD")
s:SetScript("OnEvent", function(s, event, ...)
	if select(2, IsInInstance()) == "party" then return end
end)
But it seems to do nothing. Obviously I'm missing something I just don't know what, I've never tried to stop an entire addon from a event script before

Last edited by Joker119 : 03-30-17 at 05:32 AM.
  Reply With Quote
03-30-17, 05:55 AM   #3
Joker119
A Flamescale Wyrmkin
 
Joker119's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2014
Posts: 113
I was able to solve this myself afterall.

in my addon I had
Code:
for i, group  in next, groups do
  for key, value in next, options do
    _G["DefaultCompactNamePlate"..group.."FrameOptions"][key] = value
end
and before that I had
Code:
local groups = {
"Enemy",
"Friendly",
}
I moved all of this into an event handler for the frame itself, and set the "groups" table to be determined by an if/then/else function that checks for the instanceType like so:
Code:
h:RegisterEvent("PLAYER_ENTERING_WORLD")
h:SetScript("OnEvent", function(h, event, ...)
	if select(2, IsInInstance()) == "party" or select(2, IsInInstance()) == "raid" then 
		local groups = { "Enemy",}
	else
		local groups = { "Enemy", "Friendly", }
	end
	for i, group  in next, groups do
		for key, value in next, options do
			_G["DefaultCompactNamePlate"..group.."FrameOptions"][key] = value
		end
	end
end)
And the addon seems to be working the way i need it to. Everything remains unchanged until the player enters a dungeon or raid instance, then the friendly nameplates are no longer handled by the addon until the player is no longer in an instance anymore.
  Reply With Quote
03-30-17, 06:14 AM   #4
lightspark
A Rage Talon Dragon Guard
 
lightspark's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2012
Posts: 341
TBH, I didn't need to change anything to make nameplates work in oUF.

The only way to "stumble upon" so-called forbidden nameplates is to intentionally call `C_NamePlate.GetNamePlateForUnit` w/ necessary argument.

Lua Code:
  1. C_NamePlate.GetNamePlateForUnit(unitToken[, includeForbidden])

You probably should review the way you handle nameplates. I really hope that you don't do it by iterating through `WorldFrame`'s children, that's been unnecessary since 7.0.
__________________

Last edited by lightspark : 03-30-17 at 06:20 AM.
  Reply With Quote
03-30-17, 07:22 AM   #5
Joker119
A Flamescale Wyrmkin
 
Joker119's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2014
Posts: 113
I don't use oUF for nameplates, and I don't iterate through world frame's children either, funny enough, the error is actually coming from the blizzard default nameplates xml, not my addon, but it refers to trying to access a forbidden function that "has been tainted by an addon"
Lua Code:
  1. -- rNamePlates: core
  2. -- Galaxy 2016
  3.  
  4. -----------------------------
  5. -- Variables
  6. -----------------------------
  7.  
  8. local addon, ns = ...
  9. local EliteTag = "+"
  10. local RareTag = "^"
  11. local BossTag = "*"
  12. local cfg = ns.cfg
  13. if not cfg.embeds.rNamePlates then return end
  14. -----------------------------
  15. -- SetCVar
  16. -----------------------------
  17.  
  18. SetCVar("namePlateMinScale", 1)
  19. SetCVar("namePlateMaxScale", 1)
  20.  
  21. -----------------------------
  22. -- Options
  23. -----------------------------
  24.  
  25. local options = {
  26.   useClassColors = true,
  27.   displayNameWhenSelected = true,
  28.   displayNameByPlayerNameRules = true,
  29.   playLoseAggroHighlight = false,
  30.   displayAggroHighlight = true,
  31.   displaySelectionHighlight = true,
  32.   considerSelectionInCombatAsHostile = true,
  33.   colorNameWithExtendedColors = true,
  34.   colorHealthWithExtendedColors = true,
  35.   selectedBorderColor = CreateColor(0, 0, 0, 1),
  36.   tankBorderColor = false,
  37.   defaultBorderColor = CreateColor(0, 0, 0, 1),
  38.   showClassificationIndicator = true,
  39. }
  40.  
  41.  
  42.  
  43.  
  44. -----------------------------
  45. -- Functions
  46. -----------------------------
  47.  
  48. local function GetHexColorFromRGB(r, g, b)
  49.     return string.format("%02x%02x%02x", r*255, g*255, b*255)
  50. end
  51.  
  52. --SetupNamePlate
  53. local h = CreateFrame("Frame")
  54. h:RegisterEvent("PLAYER_ENTERING_WORLD")
  55. h:SetScript("OnEvent", function(h, event, ...)
  56.     if select(2, IsInInstance()) == "party" or select(2, IsInInstance()) == "raid" then
  57.         local groups = { "Enemy",}
  58.     else
  59.         local groups = { "Enemy", "Friendly", }
  60.     end
  61.     for i, group  in next, groups do
  62.         for key, value in next, options do
  63.             _G["DefaultCompactNamePlate"..group.."FrameOptions"][key] = value
  64.         end
  65.     end
  66. end)
  67. h:RegisterEvent("NAME_PLATE_CREATED")
  68. h:SetScript("OnEvent", function(h, event, ...)
  69.     if event == "NAME_PLATE_CREATED" then
  70.         hooksecurefunc("DefaultCompactNamePlateFrameSetupInternal", function(frame, setupOptions, frameOptions, ...)
  71.         local unit = ...
  72.             --Health Bar
  73.             frame.healthBar:SetStatusBarTexture(mediapath.."statusbar_fill")
  74.             frame.healthBar:SetSize(256,32)
  75.             frame.healthBar:SetScale(0.35)
  76.             frame.RaidTargetFrame.RaidTargetIcon:SetTexture(mediapath.."raidicons")
  77.             frame.RaidTargetFrame:SetPoint("RIGHT", frame.healthBar,"RIGHT",35,0)
  78.             frame.ClassificationFrame:Hide()
  79.  
  80.             --Left Edge artwork
  81.             if (not frame.healthBar.le) then
  82.                 frame.healthBar.le = frame.healthBar:CreateTexture(nil,"BACKGROUND",nil,-8)
  83.                 frame.healthBar.le:SetTexture(mediapath.."edge_left")
  84.                 frame.healthBar.le:SetSize(64,64)
  85.                 frame.healthBar.le:SetPoint("RIGHT",frame.healthBar,"LEFT",0,0)
  86.             end
  87.    
  88.             --Right Edge artwork
  89.             if (not frame.healthBar.re) then
  90.                 frame.healthBar.re = frame.healthBar:CreateTexture(nil,"BACKGROUND",nil,-8)
  91.                 frame.healthBar.re:SetTexture(mediapath.."edge_right")
  92.                 frame.healthBar.re:SetSize(64,64)
  93.                 frame.healthBar.re:SetPoint("LEFT",frame.healthBar,"RIGHT",0,0)
  94.             end
  95.            
  96.             --Healthbar Background
  97.             if (not frame.healthBar.bg) then
  98.                 frame.healthBar.bg = frame.healthBar:CreateTexture(nil,"BACKGROUND",nil,-8)
  99.                 frame.healthBar.bg:SetTexture(mediapath.."statusbar_bg")
  100.                 frame.healthBar.bg:SetAllPoints()
  101.             end
  102.            
  103.             --Name shadow
  104.             if (not frame.healthBar.shadow) then
  105.                 frame.healthBar.shadow = frame.healthBar:CreateTexture(nil,"BACKGROUND",nil,-8)
  106.                 frame.healthBar.shadow:SetTexture("Interface\\Common\\NameShadow")
  107.                 frame.healthBar.shadow:SetPoint("BOTTOM",frame.healthBar,"TOP",0,-20)
  108.                 frame.healthBar.shadow:SetSize(256,32)
  109.                 frame.healthBar.shadow:SetTexCoord(1,1,1,0,0,1,0,0)
  110.                 frame.healthBar.shadow:SetAlpha(0.5)
  111.             end
  112.  
  113.             --Highlight Frame
  114.             if (not frame.healthBar.hlf) then
  115.                 frame.healthBar.hlf = CreateFrame("Frame",nil,frame.healthBar)
  116.                 frame.healthBar.hlf:SetAllPoints(frame.healthBar)
  117.                 frame.healthBar.hlf = frame.healthBar.hlf
  118.             end
  119.  
  120.             --Highlight
  121.             if (not frame.healthBar.hl) then
  122.                 frame.healthBar.hl = frame.healthBar.hlf:CreateTexture(nil,"BACKGROUND",nil,-8)
  123.                 frame.healthBar.hl:SetTexture(mediapath.."statusbar_highlight")
  124.                 frame.healthBar.hl:SetPoint("TOP",50,0)
  125.                 frame.healthBar.hl:SetPoint("LEFT",-30,0)
  126.                 frame.healthBar.hl:SetPoint("RIGHT",30,0)
  127.                 frame.healthBar.hl:SetPoint("BOTTOM",40,0)
  128.             end
  129.  
  130.             --Cast Bar
  131.             frame.castBar:SetStatusBarTexture(mediapath.."statusbar_fill")
  132.             if GetCVar("NamePlateVerticalScale") == "1" then
  133.                 frame.castBar:SetHeight(11)
  134.                 frame.castBar.Icon:SetTexCoord(0.1,0.9,0.1,0.9)
  135.                 frame.castBar.Icon:SetSize(17,17)
  136.                 frame.castBar.Icon:ClearAllPoints()
  137.                 frame.castBar.Icon:SetPoint("BOTTOMRIGHT",frame.castBar,"BOTTOMLEFT",-2,0)
  138.             end
  139.         end)
  140.     end
  141. end)
  142.  
  143.  
  144. --Name
  145. hooksecurefunc("CompactUnitFrame_UpdateName", function (frame)
  146.    --Set the tag based on UnitClassification, can return "worldboss", "rare", "rareelite", "elite", "normal", "minus"
  147.     local tag
  148.     local level = UnitLevel(frame.unit)
  149.     local name = UnitName(frame.unit)
  150.     local hexColor
  151.    
  152.     if level >= UnitLevel("player")+5 then
  153.         hexColor = GetHexColorFromRGB(1,0,0)
  154.     elseif level >= UnitLevel("player")+3 then
  155.         hexColor = "ff6600"
  156.     elseif level <= UnitLevel("player")-5 then
  157.         hexColor = GetHexColorFromRGB(.5,.5,.5)
  158.     elseif level <= UnitLevel("player")-3 then
  159.         hexColor = GetHexColorFromRGB(0,1,0)
  160.     else
  161.         hexColor = GetHexColorFromRGB(1,1,0)
  162.     end
  163.  
  164.     if UnitClassification(frame.unit) == "worldboss" or UnitLevel(frame.unit) == -1 then
  165.         level = "??"
  166.         hexColor = "ff6600"
  167.     elseif UnitClassification(frame.unit) == "rare" then
  168.         name = "*"..name.."*"
  169.     elseif UnitClassification(frame.unit) == "rareelite" then
  170.         name = "*"..name.."*"
  171.         level = "+"..level
  172.     elseif UnitClassification(frame.unit) == "elite" then
  173.         level = "+"..level
  174.     end
  175.     --Set the nameplate name to include tag(if any), name and level
  176.     frame.name:SetText("|cff"..hexColor.."("..level..")|r "..name)
  177.     frame.name:SetFont(cfg.font, 12)
  178. end)
  179.  
  180.  
  181.  
  182. local function IsTank()
  183.   local assignedRole = UnitGroupRolesAssigned("player")
  184.   if assignedRole == "TANK" then return true end
  185.   local role = GetSpecializationRole(GetSpecialization())
  186.   if role == "TANK" then return true end
  187.   return false
  188. end
  189.  
  190.  
  191. --UpdateHealthBorder
  192. local function UpdateHealthBorder(frame)
  193.   if frame.displayedUnit:match("(nameplate)%d?$") ~= "nameplate" then return end
  194.   if not IsTank() then return end
  195.   local status = UnitThreatSituation("player", frame.displayedUnit)
  196.   if status and status >= 3 then
  197.     frame.healthBar.border:SetVertexColor(0, 1, 0, 0.8)
  198.   end
  199. end
  200. hooksecurefunc("CompactUnitFrame_UpdateHealthBorder", UpdateHealthBorder)
  Reply With Quote
03-30-17, 07:34 AM   #6
lightspark
A Rage Talon Dragon Guard
 
lightspark's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2012
Posts: 341
Almost no one uses oUF for nameplates atm, cuz it's in dev branch, future release, you know

As for your code, try adding `:IsForbidden()` checks to all your hooks.

Lua Code:
  1. local function UpdateHealthBorder(frame)
  2.     if frame:IsForbidden() then return end -- <-- this one
  3.  
  4.     if frame.displayedUnit:match("(nameplate)%d?$") ~= "nameplate" then return end
  5.     if not IsTank() then return end
  6.     local status = UnitThreatSituation("player", frame.displayedUnit)
  7.     if status and status >= 3 then
  8.         frame.healthBar.border:SetVertexColor(0, 1, 0, 0.8)
  9.     end
  10. end

There are other issues w/ your code, but this thread isn't about them...
__________________

Last edited by lightspark : 03-30-17 at 07:59 AM.
  Reply With Quote
03-30-17, 10:22 PM   #7
Joker119
A Flamescale Wyrmkin
 
Joker119's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2014
Posts: 113
Awesome thanks for that, and I would be interested in that the other issues would be.. >.>
  Reply With Quote
03-30-17, 11:25 PM   #8
lightspark
A Rage Talon Dragon Guard
 
lightspark's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2012
Posts: 341
Originally Posted by Galaxy119 View Post
Awesome thanks for that, and I would be interested in that the other issues would be.. >.>
For instance this block:
Lua Code:
  1. h:RegisterEvent("NAME_PLATE_CREATED")
  2. h:SetScript("OnEvent", function(h, event, ...)
  3.     if event == "NAME_PLATE_CREATED" then
  4.         hooksecurefunc("DefaultCompactNamePlateFrameSetupInternal", function(frame, setupOptions, frameOptions, ...)
  5.             -- code here    
  6.         end)
  7.     end
  8. end)

You hook the same function multiple times That's the most obvious one, sorry, I'm a bit busy atm to look through the rest T_T
__________________
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » Nameplate addon after 7.2

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off