Plz edit script for character frame

For some reason i cant post on the EU forums and ask over there. Is anyone able to edit this script to still show character frame whenever health is NOT full? then fade out when full health is reached? Thank you!

local animationTimeSeconds = 0.15 --amount of seconds it takes to make a frame visible/invisible.

local f = CreateFrame(“Frame”)
local f2 = CreateFrame(“Frame”);
local f3 = CreateFrame(“Frame”);
f:RegisterEvent(“PLAYER_TARGET_CHANGED”) – Run code when player’s target changed
f2:RegisterEvent(“PLAYER_REGEN_DISABLED”) --player entered combat
f3:RegisterEvent(“PLAYER_REGEN_ENABLED”)–player left combat
local override = false;
local animating = false;

local main = function(self, event, …) --target changed event
if (DropDownList1Button2ExpandArrow:GetRight() == nil) then --init mouse menu
PlayerFrame:Click(“RightButton”);
DropDownList1Button16:Click();
DropDownList1:SetScript(“OnShow”, --keep mouse menu hidden when player frame is hidden
function()
if(PlayerFrame:GetAlpha() == 0) then
DropDownList1:Hide();
end
end)
end
if(UnitName(“target”) == nil or UnitName(“target”) == UnitName(“player”)) then --if player has no target
fadeOut(TargetFrame)
fadeOut(TargetFrameToT)
if (not override) then
fadeOut(PlayerFrame)
end
else --if player has target
fadeIn(PlayerFrame)
fadeIn(TargetFrame)
fadeIn(TargetFrameToT)
end
end

f:SetScript(“OnEvent”, main)

C_Timer.NewTicker(0.25, function()
if (PlayerFrame:IsMouseOver()) then
override = true;
fadeIn(PlayerFrame);
else
override = false;
if (UnitName(“target”) == nil or UnitName(“target”) == UnitName(“player”)) then
fadeOut(PlayerFrame);
end
end
end)

f2:SetScript(“OnEvent”, function(self, event, …)
fadeIn(PlayerFrame)
end)

f3:SetScript(“OnEvent”, function(self, event, …)
if(not override and (UnitName(“target”) == nil or UnitName(“target”) == UnitName(“player”))) then
fadeOut(PlayerFrame)
end
end)

PlayerFrame:SetAlpha(0) --hide frames when client loads
TargetFrame:SetAlpha(0)
TargetFrameToT:SetAlpha(0)
DropDownList1:Hide();

function fadeIn(frame)
if (frame:GetAlpha() < 1 and not animating) then
animating = true;
local ticker = C_Timer.NewTicker(animationTimeSeconds / 10, function()
frame:SetAlpha(frame:GetAlpha()+0.1)
end, 10)
animating = false;
end
end

function fadeOut(frame)
if (frame:GetAlpha() > 0 and not animating) then
animating = true;
local ticker = C_Timer.NewTicker(animationTimeSeconds / 10, function()
frame:SetAlpha(frame:GetAlpha()-0.1)
end, 10)
animating = false;
end
end

ALL CREDIT TO @GRIMMJ for original script

WoW’s animation system is pretty powerful. This doesn’t integrate into your code there, but as a standalone addon this will fade in PlayerFrame when health drops below max and fade out after health reaches max; and demonstrates how to do this with the animation API:

local animationTimeSeconds = 0.15

local f = CreateFrame("Frame")

-- creates fadeout/fadein animations
for k,v in pairs({"fadeout","fadein"}) do
  f[v] = f:CreateAnimationGroup()
  f[v].alpha = f[v]:CreateAnimation("alpha")
  f[v].alpha:SetFromAlpha(2-k) -- fadeout = 2-1, fadein = 2-2
  f[v].alpha:SetToAlpha(k-1) -- fadeout = 1-1, fadein = 2-1
  f[v].alpha:SetDuration(animationTimeSeconds)
  f[v].alpha:SetTarget(PlayerFrame)
  f[v]:SetScript("OnFinished",function(self) f.last = v end)
end

f:SetScript("OnEvent",function(self,event,...)
  local health = UnitHealth("player")
  local healthMax = UnitHealthMax("player")
  if health<healthMax and (not f.last or f.last=="fadeout") then
    f.fadein:Play()
  elseif health==healthMax and (not f.last or f.last=="fadein") then
    f.fadeout:Play()
  end
end)
f:RegisterEvent("UNIT_HEALTH")
f:RegisterEvent("PLAYER_LOGIN")
1 Like

hmmm thank you for the response. as separate addons the first one is taking priority over the one you wrote and still only shwoing health if i have a target. even if under 100% health :frowning: . this is exactly what im looking for if i could combine the two

I didn’t implement the fadein on mouseover bit, but the rest should be there.

local animationTimeSeconds = 0.2
local f = CreateFrame("Frame")

f.showingPlayer = true
f.showingTarget = false

-- 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
2 Likes

this is working perfectly! cant thank you enough. spent way too long trying to combine the codes myself >_< . thanks a ton!

I was just coming here to post about this! Thanks Gello!