WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   make blizz frames appear when damaged (https://www.wowinterface.com/forums/showthread.php?t=56479)

joeyo 07-31-18 02:38 PM

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.

briskman3000 07-31-18 07:50 PM

: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

Fizzlemizz 07-31-18 08:11 PM

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.

joeyo 07-31-18 10:11 PM

Quote:

Originally Posted by briskman3000 (Post 329221)
: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.

Theroxis 07-31-18 10:20 PM

Quote:

Originally Posted by joeyo (Post 329225)
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.

joeyo 08-01-18 03:24 AM

Quote:

Originally Posted by Theroxis (Post 329226)
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

joeyo 08-01-18 12:42 PM

Is it as simple as copy/paste the lines that mention player frame and such and hope it works?

semlar 08-01-18 04:52 PM

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.

Theroxis 08-01-18 11:28 PM

Quote:

Originally Posted by joeyo (Post 329236)
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.

joeyo 08-05-18 10:37 AM

Quote:

Originally Posted by Theroxis (Post 329244)
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

Vrul 08-05-18 11:00 AM

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()


All times are GMT -6. The time now is 02:10 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI