The reason your first try didn't work is that Lua is case-sensitive, so "Portrait" and "portrait" are not the same thing.
Also, your current solution works, but is fairly inefficient since it's actually creating a portrait on every frame -- you can't see it on most frames because you don't set any points, but it's still there, being updated.
Also:
- Since you use the same points for both units, you don't actually need to do two separate statements there either -- just wrap the whole block in a single check.
- oUF doesn't do anything with a "type" member on the portrait object, so there's no reason to set one.
- Rather than setting an OnShow script, you should use oUF hooks so that your function gets called each time the portrait is updated, rather than each time it's shown -- otherwise, your function won't run if you switch from one target directly to another, for example.
- Rather than explicitly setting the height of the portrait in pixels, I'd suggest using anchors so that it automatically adjusts its height to match the health bar, since that's what it looks like you want to happen.
Code:
if unit == "player" or unit == "target" then
local portrait = CreateFrame("PlayerModel", nil, self)
portrait:SetPoint("TOPLEFT", health)
portrait:SetPoint("BOTTOMLEFT", health)
portrait:SetWidth(158)
portrait:SetAlpha(0.6)
portrait.PostUpdate = function(portrait, unit)
portrait:SetCamera(0)
end
self.Portrait = portrait
end
If you want it to cover the whole health bar, just do:
Code:
portrait:SetAllPoints(health)
and remove all of the SetPoint and SetWidth lines.