Quantcast make blizz frames appear when damaged - WoWInterface
Thread Tools Display Modes
07-31-18, 02:38 PM   #1
joeyo
An Aku'mai Servant
Join Date: Jan 2012
Posts: 31
make blizz frames appear when damaged

so i want to make the blizz player,target,and pet frames disapear when im out of combat but also have my player frame appear when im damaged.
so the code i have here can hide them out of combat but i dont know what to put to make it appear when im damaged also.

im also trying to make a toggle switch that if i need to make them visible i can press a macro to unhide and hide manually.

RegisterStateDriver(PlayerFrame,"visibility","[combat][exists] show; hide")
RegisterStateDriver(TargetFrame,"visibility","[combat][exists] show; hide")
RegisterStateDriver(PetFrame,"visibility","[combat,@pet,exists] show;hide")

thats what i got so far after searching the internet for a solution for hours.
help me o lua gods your my only hope.
  Reply With Quote
07-31-18, 07:50 PM   #2
briskman3000
A Cliff Giant
AddOn Author - Click to view addons
Join Date: Mar 2009
Posts: 74
:Show() and :Hide() are protected in combat iirc (which means they can't be called), so I believe you can't have the frame jump to shown when damaged, as taking damage throws you in combat
  Reply With Quote
07-31-18, 08:11 PM   #3
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 931
Removing [exists] will hide while not in combat.

You could
Code:
RegisterStateDriver(PlayerFrame,"visibility","[combat][noexists:target] show; hide")
Which will hide the player frame out of combat unless a target exists which makes F1/esc. your toggle for that unit only while the others are hidden until combat.

Someone else might have better.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle and Move Pad Plus.

Last edited by Fizzlemizz : 07-31-18 at 08:14 PM.
  Reply With Quote
07-31-18, 10:11 PM   #4
joeyo
An Aku'mai Servant
Join Date: Jan 2012
Posts: 31
Originally Posted by briskman3000 View Post
:Show() and :Hide() are protected in combat iirc (which means they can't be called), so I believe you can't have the frame jump to shown when damaged, as taking damage throws you in combat
I meant if I知 out of combat the playerframe will stay visible until I知 at full health again.

So what this does so far will hide it if I知 out of combat and show if I知 in combat or have a target.
I want to make it so that it also makes it stay visible if I知 not at full health.

I知 still new at writing code so if any knows how to add that to what I got I appreciate your efforts.
  Reply With Quote
07-31-18, 10:20 PM   #5
Theroxis
A Fallenroot Satyr
Join Date: Jun 2018
Posts: 24
Originally Posted by joeyo View Post
I meant if I’m out of combat the playerframe will stay visible until I’m at full health again.

So what this does so far will hide it if I’m out of combat and show if I’m in combat or have a target.
I want to make it so that it also makes it stay visible if I’m not at full health.

I’m still new at writing code so if any knows how to add that to what I got I appreciate your efforts.
Take a look at the way ImprovedBlizzardUI handles this:

https://github.com/kaytotes/Improved...yer.lua#L25-39

This block of code decides whether or not to hide the Blizzard PlayerFrame;

The variable "hide" comes from their event handler here:

https://github.com/kaytotes/Improved...er.lua#L84-114

And the event(s) that will fire that function are here:

https://github.com/kaytotes/Improved...r.lua#L122-130


Basically, they fire an event any appropriate time (PLAYER_ENTERING_WORLD for initial login, and any time the player sees a loading screen, any time you enter/exit a vehicle, etc..) to check the status of the PlayerFrame healthbar.
Then, inside that function they check a couple of small things:
Do you have a target?
Are you regenerating heatlh?
If either of these things are true, then it DOES NOT hide the frame.
If BOTH of these things are FALSE, then it DOES hide the frame.

The actual hiding function checks a couple of other things once more:

Is your health actually full? (It's actually possible for you to NOT be at max health, be OUT of combat and NOT have Regen for a brief period, this works around that.)
Is your target actually empty? (It's possible to have targetted something between when the event handler fired and when the hide function runs, this fixes that)

As a small caveat, you could add a function to toggle a variable between true and false. Then your macro to force show the unit frame could use /run FunctionName(); to toggle that variable, and you could add a conditional to the hide code that makes sure that variable is false before hiding.

Last edited by Theroxis : 07-31-18 at 10:26 PM.
  Reply With Quote
08-01-18, 03:24 AM   #6
joeyo
An Aku'mai Servant
Join Date: Jan 2012
Posts: 31
Originally Posted by Theroxis View Post
Take a look at the way ImprovedBlizzardUI handles this:

https://github.com/kaytotes/Improved...yer.lua#L25-39

This block of code decides whether or not to hide the Blizzard PlayerFrame;

The variable "hide" comes from their event handler here:

https://github.com/kaytotes/Improved...er.lua#L84-114

And the event(s) that will fire that function are here:

https://github.com/kaytotes/Improved...r.lua#L122-130


Basically, they fire an event any appropriate time (PLAYER_ENTERING_WORLD for initial login, and any time the player sees a loading screen, any time you enter/exit a vehicle, etc..) to check the status of the PlayerFrame healthbar.
Then, inside that function they check a couple of small things:
Do you have a target?
Are you regenerating heatlh?
If either of these things are true, then it DOES NOT hide the frame.
If BOTH of these things are FALSE, then it DOES hide the frame.

The actual hiding function checks a couple of other things once more:

Is your health actually full? (It's actually possible for you to NOT be at max health, be OUT of combat and NOT have Regen for a brief period, this works around that.)
Is your target actually empty? (It's possible to have targetted something between when the event handler fired and when the hide function runs, this fixes that)

As a small caveat, you could add a function to toggle a variable between true and false. Then your macro to force show the unit frame could use /run FunctionName(); to toggle that variable, and you could add a conditional to the hide code that makes sure that variable is false before hiding.
So this looks to be the exact function I知 looking for I just have no idea how I would go about having a simple addon Lua for just that function and not have the rest of the stuff in that add on
  Reply With Quote
08-01-18, 12:42 PM   #7
joeyo
An Aku'mai Servant
Join Date: Jan 2012
Posts: 31
Is it as simple as copy/paste the lines that mention player frame and such and hope it works?
  Reply With Quote
08-01-18, 04:52 PM   #8
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,056
If you only care about its visibility and not whether you can interact with it, you can show and hide the player frame whenever you want by just setting its alpha via PlayerFrame:SetAlpha(0) and PlayerFrame:SetAlpha(1).

You will not be able to click through it (unless you want to remove mouse interaction altogether), but you can easily toggle its visibility.
  Reply With Quote
08-01-18, 11:28 PM   #9
Theroxis
A Fallenroot Satyr
Join Date: Jun 2018
Posts: 24
Originally Posted by joeyo View Post
Is it as simple as copy/paste the lines that mention player frame and such and hope it works?
Here's just that part of the ImprovedBlizzardUI, made into a standalone addon, plus an override function:
https://drive.google.com/open?id=12Z...rigsW8rhsGlzL0

Put:
Code:
/run TogglePlayerFrameHide()
Into a macro to toggle the automatic hiding/showing based on combat/health/target.

I should note, this only does the PlayerFrame. Just add the other frames you desire with Show() and Hide() in the appropriate places.

Last edited by Theroxis : 08-02-18 at 11:27 AM.
  Reply With Quote
08-05-18, 10:37 AM   #10
joeyo
An Aku'mai Servant
Join Date: Jan 2012
Posts: 31
Originally Posted by Theroxis View Post
Here's just that part of the ImprovedBlizzardUI, made into a standalone addon, plus an override function:
https://drive.google.com/open?id=12Z...rigsW8rhsGlzL0

Put:
Code:
/run TogglePlayerFrameHide()
Into a macro to toggle the automatic hiding/showing based on combat/health/target.

I should note, this only does the PlayerFrame. Just add the other frames you desire with Show() and Hide() in the appropriate places.
im so blind and didnt realize that you posted this a while back thankyou so much theroxis your the best
  Reply With Quote
08-05-18, 11:00 AM   #11
Vrul
A Frostmaul Preserver
 
Vrul's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 291
This should get you started at least:
Code:
local frame, forceShow, inCombat, queue = CreateFrame("Frame")

local function UnitFrame_OnShow(self)
    if not (inCombat or forceShow) then
        self:Hide()
    end
end
PetFrame:HookScript("OnShow", UnitFrame_OnShow)
TargetFrame:HookScript("OnShow", UnitFrame_OnShow)

local function DisableShowMode()
    frame:RegisterUnitEvent("UNIT_HEALTH", "player", "vehicle")
    frame:RegisterUnitEvent("UNIT_MAXHEALTH", "player", "vehicle")
    if not inCombat then
        PetFrame:Hide()
        TargetFrame:Hide()
    else
        queue = DisableShowMode
    end
end

local function EnableShowMode(override)
    frame:UnregisterEvent("UNIT_HEALTH")
    frame:UnregisterEvent("UNIT_MAXHEALTH")
    if not inCombat or override then
        PlayerFrame:Show()
        PetFrame:SetShown(UnitExists("pet"))
        TargetFrame:SetShown(UnitExists("target"))
    else
        queue = EnableShowMode
    end
end

local function OnEvent(self, event, unit)
    if event == "PLAYER_REGEN_DISABLED" then
        inCombat = true
        EnableShowMode(true)
    elseif event == "PLAYER_REGEN_ENABLED" then
        inCombat = false
        (queue or DisableShowMode)()
    end
    if not (inCombat or forceShow) then
        unit = PlayerFrame.unit
        PlayerFrame:SetShown(UnitHealth(unit) < UnitHealthMax(unit))
    end
end

frame:SetScript("OnEvent", OnEvent)
frame:RegisterEvent("PLAYER_ENTERING_WORLD")
frame:RegisterEvent("PLAYER_REGEN_DISABLED")
frame:RegisterEvent("PLAYER_REGEN_ENABLED")
frame:RegisterUnitEvent("UNIT_ENTERED_VEHICLE", "player")
frame:RegisterUnitEvent("UNIT_EXITED_VEHICLE", "player")
DisableShowMode()

function ToggleUnitFrameForceShow()
    forceShow = not forceShow
    if forceShow then
        EnableShowMode()
    else
        DisableShowMode()
        OnEvent(frame)
    end
end
To toggle forcing to show the frames in your macro use:
Code:
/run ToggleUnitFrameForceShow()
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » make blizz frames appear when damaged

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off