View Single Post
08-06-18, 06:53 PM   #4
joeyo
An Aku'mai Servant
Join Date: Jan 2012
Posts: 31
so ive tried this

so i have been trying to edit a current pieced together .lua so that the pet frame shows when in combat/have a target/less than full health and hides when out of combat and full health.also set to hide the pet mana bar and frame texture.

the problem is that the frame is not hidden from entering the game also i cannot seem to get the pet mana bar to be hidden from entering the game. this is what i got so far if anyone can help out or at least let me know where i went wrong.

Lua:
Code:
-- This file is loaded from "!frame combat.toc"

local PlayerUnitFrame = CreateFrame('Frame', nil, UIParent);  
local ForceShown = false
--[[
    Hides the Pet Frame when you are out of combat, have no target and are at full health.

    @ param boolean $hide Should we hide the frame
    @ return void
]]

local function HidePet(hide)
    if (InCombatLockdown() == false) then
        if (hide and UnitHealth('pet') == UnitHealthMax('pet') and UnitExists('target') == false and (not ForceShown)) then
            PetFrame:Hide();
        else
            PetFrame:Show();
        end
    end
end


--[[
    Handles the WoW API Events Registered Below

    @ param Frame $self The Frame that is handling the event 
    @ param string $event The WoW API Event that has been triggered
    @ param arg $... The arguments of the Event
    @ return void
]]

local function HandleEvents (self, event, ...)
    if (event == 'PLAYER_ENTERING_WORLD' or event == 'PLAYER_LOGIN' or event == 'ADDON_LOADED') then
        HidePet(true);
    end

    if (event == 'PLAYER_REGEN_DISABLED') then
        HidePet(false);
    elseif (event == 'PLAYER_REGEN_ENABLED' or event == 'UNIT_HEALTH') then
        HidePet(true);
    end

    if (event == 'PLAYER_TARGET_CHANGED') then
        if (UnitExists('target')) then
            HidePet(false);
        else
            HidePet(true);
        end
    end

    if (event == 'UNIT_EXITED_VEHICLE' and ... == 'pet') then
        StyleFrames();
    end


end

function TogglePetFrameHide()
	ForceShown = not ForceShown
	DEFAULT_CHAT_FRAME:AddMessage(ForceShown)
	HidePet(true)
end


    local f = CreateFrame("Frame")    --we need a frame to listen for an event
    f:RegisterEvent("PLAYER_ENTERING_WORLD)   --we'll listen for this event - all the UI stuff should be done loading by now
    f:SetScript("OnEvent", function(self, event)   --when the event fires we want this to happen
           PetFrameManaBar:Hide()
    end)
PetFrameTexture:Hide()
-- Register the Modules Events
PlayerUnitFrame:SetScript('OnEvent', HandleEvents);
PlayerUnitFrame:RegisterEvent('PLAYER_ENTERING_WORLD');
PlayerUnitFrame:RegisterEvent('PLAYER_LOGIN');
PlayerUnitFrame:RegisterEvent('UNIT_HEALTH');
PlayerUnitFrame:RegisterEvent('PLAYER_REGEN_DISABLED');
PlayerUnitFrame:RegisterEvent('PLAYER_REGEN_ENABLED');
PlayerUnitFrame:RegisterEvent('PLAYER_TARGET_CHANGED');
PlayerUnitFrame:RegisterEvent('UNIT_EXITED_VEHICLE');
PlayerUnitFrame:RegisterEvent('ADDON_LOADED');

Last edited by joeyo : 08-06-18 at 06:55 PM.
  Reply With Quote