Thread Tools Display Modes
02-23-14, 04:28 AM   #1
tub
A Murloc Raider
Join Date: Feb 2014
Posts: 6
LUA: Hide unit frame out of combat

Hi, I know it is not easy to make a LUA, but I need a LUA to make unit frame(Blizzard original frame,including :"Player","Target" and "Focus") fade out of combt.
  Reply With Quote
02-23-14, 05:38 AM   #2
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
This will keep the player, target and focus frames hidden while out of combat and show them when combat starts.
Lua Code:
  1. local f = CreateFrame('frame', nil, nil, 'SecureHandlerStateTemplate')
  2. f:SetFrameRef('PlayerFrame', PlayerFrame)
  3. f:SetFrameRef('TargetFrame', TargetFrame)
  4. f:SetFrameRef('FocusFrame', FocusFrame)
  5. f:SetAttribute('_onstate-combat', [=[ -- Securely toggle visibility in combat
  6.     if newstate == 'show' then
  7.         self:GetFrameRef('PlayerFrame'):Show()
  8.         if UnitExists('target') then
  9.             self:GetFrameRef('TargetFrame'):Show()
  10.         end
  11.         if UnitExists('focus') then
  12.             self:GetFrameRef('FocusFrame'):Show()
  13.         end
  14.     else
  15.         self:GetFrameRef('PlayerFrame'):Hide()
  16.         self:GetFrameRef('TargetFrame'):Hide()
  17.         self:GetFrameRef('FocusFrame'):Hide()
  18.     end
  19. ]=])
  20. RegisterStateDriver(f, 'combat', '[combat] show; hide')
  21.  
  22. local function HideFrame(self) -- Insecurely hide out of combat if shown
  23.     if not InCombatLockdown() then self:Hide() end
  24. end
  25. PlayerFrame:HookScript('OnShow', HideFrame)
  26. TargetFrame:HookScript('OnShow', HideFrame)
  27. FocusFrame:HookScript('OnShow', HideFrame)
  Reply With Quote
02-23-14, 07:10 AM   #3
tub
A Murloc Raider
Join Date: Feb 2014
Posts: 6
thank u so much !!
  Reply With Quote
02-23-14, 07:23 AM   #4
tub
A Murloc Raider
Join Date: Feb 2014
Posts: 6
I tried to write it into my Addons , but It appeared "incompatible" what's wrong whith toc? Here is the TOC I
write
## Interface: 17930
## Title: iaddon
## Notes: fade ui
iaddon.lua
  Reply With Quote
02-23-14, 07:26 AM   #5
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
Change it to ## Interface: 50400 for the current version.
  Reply With Quote
02-23-14, 08:23 AM   #6
tub
A Murloc Raider
Join Date: Feb 2014
Posts: 6
It works. It's amazing!! I can't believe it ! While the Rogue's combo point did't disappear with the frame
  Reply With Quote
02-23-14, 08:38 AM   #7
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
I think this should work for hiding the combo frame as well, for some reason it's not parented to the target frame.
Lua Code:
  1. local f = CreateFrame('frame', nil, nil, 'SecureHandlerStateTemplate')
  2. f:SetFrameRef('PlayerFrame', PlayerFrame)
  3. f:SetFrameRef('TargetFrame', TargetFrame)
  4. f:SetFrameRef('FocusFrame', FocusFrame)
  5. f:SetFrameRef('ComboFrame', ComboFrame)
  6. f:SetAttribute('_onstate-combat', [=[ -- Securely toggle visibility in combat
  7.     if newstate == 'show' then
  8.         self:GetFrameRef('PlayerFrame'):Show()
  9.         if UnitExists('target') then
  10.             self:GetFrameRef('TargetFrame'):Show()
  11.         end
  12.         if UnitExists('focus') then
  13.             self:GetFrameRef('FocusFrame'):Show()
  14.         end
  15.     else
  16.         self:GetFrameRef('PlayerFrame'):Hide()
  17.         self:GetFrameRef('TargetFrame'):Hide()
  18.         self:GetFrameRef('FocusFrame'):Hide()
  19.         self:GetFrameRef('ComboFrame'):Hide()
  20.     end
  21. ]=])
  22. RegisterStateDriver(f, 'combat', '[combat] show; hide')
  23.  
  24. local function HideFrame(self) -- Insecurely hide out of combat if shown
  25.     if not InCombatLockdown() then self:Hide() end
  26. end
  27. PlayerFrame:HookScript('OnShow', HideFrame)
  28. TargetFrame:HookScript('OnShow', HideFrame)
  29. FocusFrame:HookScript('OnShow', HideFrame)
  30. ComboFrame:HookScript('OnShow', HideFrame)
  31.  
  32. f:SetScript('OnEvent', function(self, event)
  33.     if GetComboPoints('player', 'target') > 0 then -- Show ComboFrame upon entering combat if we have points
  34.         ComboFrame:Show()
  35.     end
  36. end)
  37. f:RegisterEvent('PLAYER_REGEN_DISABLED')
  Reply With Quote
02-23-14, 08:47 AM   #8
tub
A Murloc Raider
Join Date: Feb 2014
Posts: 6
thank so much! It's perfect.
  Reply With Quote
02-23-14, 09:51 AM   #9
Vrul
A Scalebane Royal Guard
 
Vrul's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 404
This is another way to go:
Code:
RegisterStateDriver(PlayerFrame, "visibility", "[combat] show; hide")
RegisterStateDriver(TargetFrame, "visibility", "[combat,exists] show; hide")
RegisterStateDriver(ComboFrame, "visibility", "[combat,exists] show; hide")
RegisterStateDriver(FocusFrame, "visibility", "[@focus,combat,exists] show; hide")
  Reply With Quote
02-23-14, 10:07 AM   #10
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
Well sure, if you don't want to use 40 lines to do the same thing.
  Reply With Quote
09-29-15, 01:33 AM   #11
gezus
A Deviate Faerie Dragon
Join Date: Oct 2008
Posts: 11
Does this require an Addon?.. or can I use it with the stock player frame?
  Reply With Quote
09-29-15, 05:20 AM   #12
Nikita S. Doroshenko
A Cyclonian
 
Nikita S. Doroshenko's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2015
Posts: 45
Originally Posted by Vrul View Post
This is another way to go:
Code:
RegisterStateDriver(PlayerFrame, "visibility", "[combat] show; hide")
RegisterStateDriver(TargetFrame, "visibility", "[combat,exists] show; hide")
RegisterStateDriver(ComboFrame, "visibility", "[combat,exists] show; hide")
RegisterStateDriver(FocusFrame, "visibility", "[@focus,combat,exists] show; hide")
Originally Posted by gezus View Post
Does this require an Addon?.. or can I use it with the stock player frame?
You can use this code without any addons, you can even use your ingame chat to try it:
just type in chat: /run RegisterStateDriver(PlayerFrame, "visibility", "[combat] show; hide") and then hit enter, and then next line: /run RegisterStateDriver(TargetFrame, "visibility", "[combat,exists] show; hide") and so on...

Or you use can use AddOns generator to easily build an addon: http://addon.bool.no/ Paste code and hit "Create AddOn"

As well, i suggest you to add 2 more lines of code, to show unit frames when target selected:

Lua Code:
  1. RegisterStateDriver(TargetFrame, "visibility", "[target,exists] show; hide")
  2. RegisterStateDriver(PlayerFrame, "visibility", "[target,exists] show; hide")

Only problem is that this code don't use fade animation. So i personally used for my UI here http://www.youtube.com/watch?v=rFo3Bn919wA something that semlar suggested and added animation above. But i think it's possible to add animate to this method too.

Last edited by Nikita S. Doroshenko : 09-29-15 at 05:29 AM.
  Reply With Quote
09-29-15, 11:40 PM   #13
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by Nikita S. Doroshenko View Post
Only problem is that this code don't use fade animation. ... But i think it's possible to add animate to this method too.
Fading in would be easy -- you'd want to set the alpha to 0 in an OnShow script, then play an animation that transitioned the alpha to 1, then set the alpha to 1 in the animation's OnFinished script (otherwise it will revert to the original 0 alpha from before the animation played). Fading out, though, wouldn't be possible with this method.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
07-21-16, 09:08 PM   #14
romereo
A Kobold Labourer
Join Date: Jul 2016
Posts: 1
Originally Posted by Nikita S. Doroshenko View Post
Only problem is that this code don't use fade animation. So i personally used for my UI here http://www.youtube.com/watch?v=rFo3Bn919wA something that semlar suggested and added animation above. But i think it's possible to add animate to this method too.
Hey, sorry to post in old topic but this code is what i was looking for!
I want to see my health bar also when it's less than 100% and i want to know how you adjuste the length of the health bars just like in your video.
Maybe if it's possible, there is a way to change the numbers in the health bar? I mean it shows something like 20.2k/20.2k I was looking for something to just show the exact number: 20 291 (an example).

Sorry for my bad english! :/
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Search/Requests » LUA: Hide unit frame out of combat

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