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:
function(allstates, event, unit, ...)
if event == "NAME_PLATE_UNIT_ADDED" then
if unit then
local guid = UnitGUID(unit)
allstates[guid] = {
changed = true,
show = false,
PassUnit = unit,
glow = false,
}
end
end
if event == "NAME_PLATE_UNIT_REMOVED" then
if unit then
local guid = UnitGUID(unit)
if allstates[guid] then
allstates[guid].changed = true
allstates[guid].PassUnit = "none"
end
end
end
for i = 1,40 do
local u = "nameplate"..i
if UnitExists(u) and UnitCanAttack("player",unit) and
UnitHealth(u)>=1 and (UnitHealth(u)/UnitHealthMax(u))<.3 then
allstates[u] = {
changed = true,
show = true,
PassUnit = u,
glow = true,
}
else
allstates[u] = {
changed = true,
show = false,
PassUnit = "none",
}
end
end
return true
end