Addon experience needed please

Hello,

Hoping someone experienced with WoW addons can help add/edit the following script. I followed the instructions with this link. Blizzard frames that are hidden out-of-combat

It nearly has everything I want, except one thing. When I target out of combat I don’t want the unit frames to appear. I only want it to appear in combat, with its mouse-over feature included in the script.

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)
fadeOut(PetFrame)
if (not override) then
fadeOut(PlayerFrame)
end
else --if player has target
fadeIn(PlayerFrame)
fadeIn(TargetFrame)
fadeIn(TargetFrameToT)
fadeIn(PetFrame)
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)
PetFrame: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

Drop this line, and it should stop fading in when out of combat. There will be some dead code in the main function, namely these lines:

else --if player has target
  fadeIn(PlayerFrame)
  fadeIn(TargetFrame)
  fadeIn(TargetFrameToT)
  fadeIn(PetFrame)

These shouldn’t cause problems, but to be safe, you can drop these too.

I deleted the codes, now the player frame and pet frame aren’t disappearing.

I deleted the codes, now the player frame and pet frame aren’t disappearing.

Hi Angleus / Grumok,

I’m actually Grimmj from the thread you’ve linked, i’ve since changed my character’s name to Kealon.

I’m actually surprised to see this script again haha. I didn’t think it would still be findable.

I’ve made the changes you requested, the unit frames will now only show when actually in combat or when mousing over the area where the PlayerFrame is. I’ve also tweaked the mouse over feature so that the pet frame is now shown along with the player frame, and made the fade in/fade out animation react a little quicker.

The code is below. If you don’t like the pet frame being shown on mouse over or would like to change the reaction time of the mouseover feature, i’ve made them easily changeable as settings at the top of the script.

--You can change these settings:
local animationTimeSeconds = 0.15 --amount of seconds it takes to make a frame visible/invisible.
local mouseOverCheckSeconds = 0.15 --check wheter the mouse is over the PlayerFrame every x seconds.
local showPetFrameOnMouseOver = true; --true to also show pet frame when mousing over PlayFrame, false to not show pet frame when mousing over.

--DO NOT EDIT ANYTHING BELOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING.
local f = CreateFrame("Frame");
local f2 = CreateFrame("Frame");
local f3 = CreateFrame("Frame");
f:RegisterEvent("PLAYER_TARGET_CHANGED");
f2:RegisterEvent("PLAYER_REGEN_DISABLED"); --player entered combat
f3:RegisterEvent("PLAYER_REGEN_ENABLED"); --player left combat
local override = false;
local animating = false;

--on target changed
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)
        fadeOut(PetFrame)
        if (not override) then
            fadeOut(PlayerFrame)
        end
    elseif (InCombatLockdown()) then --if player has target and is in combat
        fadeIn(PlayerFrame)
        fadeIn(TargetFrame)
        fadeIn(TargetFrameToT)
        fadeIn(PetFrame)      
    end
end

f:SetScript("OnEvent", main)

--mouseover loop
C_Timer.NewTicker(mouseOverCheckSeconds, function()
    if (PlayerFrame:IsMouseOver()) then
        override = true;
        fadeIn(PlayerFrame);
        if(showPetFrameOnMouseOver) then
            fadeIn(PetFrame);
        end
    else
        override = false;
        if (UnitName("target") == nil or UnitName("target") == UnitName("player")) then
            fadeOut(PlayerFrame);
            fadeOut(PetFrame);
        end
    end
end)

--on combat entered
f2:SetScript("OnEvent", function(self, event, ...)
    fadeIn(PlayerFrame)
    fadeIn(PetFrame)
    if (UnitName("target") ~= nil and UnitName("target") ~= UnitName("player")) then --if player has target
        fadeIn(TargetFrame)
        fadeIn(TargetFrameToT)
    end
end)

--on combat left
f3:SetScript("OnEvent", function(self, event, ...)
    if(not override and (UnitName("target") == nil or UnitName("target") == UnitName("player"))) then
        fadeOut(PlayerFrame)
        fadeOut(TargetFrame)
        fadeOut(TargetFrameToT)
        fadeOut(PetFrame)
    end
end)

PlayerFrame:SetAlpha(0) --hide frames when client loads
TargetFrame:SetAlpha(0)
TargetFrameToT:SetAlpha(0)
PetFrame: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

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.