View Single Post
04-13-21, 12:49 PM   #2
Kanegasi
A Molten Giant
 
Kanegasi's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2007
Posts: 666
I posted on your MMOC thread, but I'll answer here as well. UnitCanAttack will filter for hostile or neutral units, and I'm pretty sure you can't attack yourself so your nameplate will be left alone. The nameplate loop logic was also a bit redundant.

Lua Code:
  1. function(allstates, event, unit, ...)
  2.     if event == "NAME_PLATE_UNIT_ADDED" then
  3.         if unit then
  4.             local guid = UnitGUID(unit)
  5.             allstates[guid] = {
  6.                 changed = true,
  7.                 show = false,
  8.                 PassUnit = unit,
  9.                 glow = false,
  10.             }
  11.         end
  12.     end
  13.     if event == "NAME_PLATE_UNIT_REMOVED" then
  14.         if unit then
  15.             local guid = UnitGUID(unit)
  16.             if allstates[guid] then
  17.                 allstates[guid].changed = true
  18.                 allstates[guid].PassUnit = "none"
  19.             end
  20.         end
  21.     end
  22.     for i = 1,40 do
  23.         local u = "nameplate"..i
  24.         if UnitExists(u) and UnitCanAttack("player",unit) and
  25.                 UnitHealth(u)>=1 and (UnitHealth(u)/UnitHealthMax(u))<.3 then
  26.             allstates[u] = {
  27.                 changed = true,
  28.                 show = true,
  29.                 PassUnit = u,
  30.                 glow = true,
  31.             }
  32.         else
  33.             allstates[u] = {
  34.                 changed = true,
  35.                 show = false,
  36.                 PassUnit = "none",
  37.             }
  38.         end
  39.     end
  40.     return true
  41. end
  Reply With Quote