Addon doesn't work anymore

I don’t know if something got changed for 9.0 or if there’s just an error in there somewhere that I am not seeing. Help please.

local animationTimeSeconds = 0.2
local f = CreateFrame(“Frame”)
local x = 100 – horizontal distance from center
local y = -50 – verticial position from center (negative=down, positive=up)

f.showingPlayer = true
f.showingTarget = false

C_Timer.After(0,function()
PlayerFrame:ClearAllPoints()
PlayerFrame:SetPoint(“RIGHT”,UIParent,“CENTER”,-x,y)
PlayerFrame:SetUserPlaced(true)
TargetFrame:ClearAllPoints()
TargetFrame:SetPoint(“LEFT”,UIParent,“CENTER”,x,y)
TargetFrame:SetUserPlaced(true)
end)

– creates fadeout/fadein animations
for k,v in pairs({“playerfadein”,“playerfadeout”,“targetfadein”}) do
f[v] = f:CreateAnimationGroup()
f[v].alpha = f[v]:CreateAnimation(“alpha”)
f[v].alpha:SetFromAlpha(k%2==0 and 1 or 0)
f[v].alpha:SetToAlpha(k%2==0 and 0 or 1)
f[v].alpha:SetDuration(animationTimeSeconds)
f[v].alpha:SetTarget(PlayerFrame)
end
f.targetfadein.alpha:SetTarget(TargetFrame)

f:SetScript(“OnEvent”,function(self,event,…)
if f[event] then
fevent
end
end)
f:RegisterEvent(“PLAYER_LOGIN”)

function f:UpdatePlayerShown(inCombat)
local shouldShow = inCombat or InCombatLockdown() or UnitExists(“target”) or UnitHealth(“player”)<UnitHealthMax(“player”)
if shouldShow and not f.showingPlayer then
f.playerfadein:Play()
f.showingPlayer = true
elseif not shouldShow and f.showingPlayer then
f.playerfadeout:Play()
f.showingPlayer = false
end
end

function f:PLAYER_LOGIN()
f:RegisterEvent(“UNIT_HEALTH”)
f:RegisterEvent(“PLAYER_REGEN_ENABLED”)
f:RegisterEvent(“PLAYER_REGEN_DISABLED”)
f:RegisterEvent(“PLAYER_TARGET_CHANGED”)
f:UpdatePlayerShown()
TargetFrame:SetAlpha(0)
end

function f:UNIT_HEALTH(unit)
if unit==“player” then
f:UpdatePlayerShown()
end
end

function f:PLAYER_REGEN_ENABLED()
f:UpdatePlayerShown()
f:RegisterEvent(“UNIT_HEALTH”)
end

function f:PLAYER_REGEN_DISABLED()
f:UpdatePlayerShown(true)
f:UnregisterEvent(“UNIT_HEALTH”)
end

function f:PLAYER_TARGET_CHANGED()
f:UpdatePlayerShown()
local exists = UnitExists(“target”)
if exists and not f.showingTarget then
f.targetfadein:Play()
f.showingTarget = true
elseif not exists and f.showingTarget then
TargetFrame:SetAlpha(0)
f.showingTarget = false
end
end

This code looks copy-pasted from OneNote or something. It’s badly malformed.

– should be two hyphens (forum is converting this to a single dash)
… should be … (forum is converting 3 .'s into a unicode ellipsis character too)
“ should be "
” should be "

Some of it is this forum too. Amusingly, it’s converting

f[event](self,...)
into
fevent

probably more. This code should work:

local animationTimeSeconds = 0.2
local f = CreateFrame("Frame")
local x = 100 -- horizontal distance from center
local y = -50 -- verticial position from center (negative=down, positive=up)

f.showingPlayer = true
f.showingTarget = false

C_Timer.After(0,function()
    PlayerFrame:ClearAllPoints()
    PlayerFrame:SetPoint("RIGHT",UIParent,"CENTER",-x,y)
    PlayerFrame:SetUserPlaced(true)
    TargetFrame:ClearAllPoints()
    TargetFrame:SetPoint("LEFT",UIParent,"CENTER",x,y)
    TargetFrame:SetUserPlaced(true)
end)

-- creates fadeout/fadein animations
for k,v in pairs({"playerfadein","playerfadeout","targetfadein"}) do
    f[v] = f:CreateAnimationGroup()
    f[v].alpha = f[v]:CreateAnimation("alpha")
    f[v].alpha:SetFromAlpha(k%2==0 and 1 or 0)
    f[v].alpha:SetToAlpha(k%2==0 and 0 or 1)
    f[v].alpha:SetDuration(animationTimeSeconds)
    f[v].alpha:SetTarget(PlayerFrame)
end
f.targetfadein.alpha:SetTarget(TargetFrame)

f:SetScript("OnEvent",function(self,event,...)
    if f[event] then
        f[event](self,...)
    end
end)
f:RegisterEvent("PLAYER_LOGIN")

function f:UpdatePlayerShown(inCombat)
    local shouldShow = inCombat or InCombatLockdown() or UnitExists("target") or UnitHealth("player")<UnitHealthMax("player")
    if shouldShow and not f.showingPlayer then
        f.playerfadein:Play()
        f.showingPlayer = true
    elseif not shouldShow and f.showingPlayer then
        f.playerfadeout:Play()
        f.showingPlayer = false
    end
end

function f:PLAYER_LOGIN()
    f:RegisterEvent("UNIT_HEALTH")
    f:RegisterEvent("PLAYER_REGEN_ENABLED")
    f:RegisterEvent("PLAYER_REGEN_DISABLED")
    f:RegisterEvent("PLAYER_TARGET_CHANGED")
    f:UpdatePlayerShown()
    TargetFrame:SetAlpha(0)
end

function f:UNIT_HEALTH(unit)
    if unit=="player" then
        f:UpdatePlayerShown()
    end
end

function f:PLAYER_REGEN_ENABLED()
    f:UpdatePlayerShown()
    f:RegisterEvent("UNIT_HEALTH")
end

function f:PLAYER_REGEN_DISABLED()
    f:UpdatePlayerShown(true)
    f:UnregisterEvent("UNIT_HEALTH")
end

function f:PLAYER_TARGET_CHANGED()
    f:UpdatePlayerShown()
    local exists = UnitExists("target")
    if exists and not f.showingTarget then
        f.targetfadein:Play()
        f.showingTarget = true
    elseif not exists and f.showingTarget then
        TargetFrame:SetAlpha(0)
        f.showingTarget = false
    end
end
1 Like

Most of it works, but the player frame always resets back to it’s default spot.

Nevermind, I forgot I had moved it with Move Anything, so I just had to reset it. o3o

This addon doesn’t seem to work anymore, and I don’t even get an error message from it.