Thread Tools Display Modes
10-27-10, 04:05 PM   #1
Miiru
A Flamescale Wyrmkin
 
Miiru's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2008
Posts: 138
Frame only Hiding once :S

Hello.

Im trying to write a little addon showing the first letter of the cast im currently casting.

So far it looks like this:

Code:
llocal frame = CreateFrame("Frame")

function frame:OnEvent(event, ...)

if event == "UNIT_SPELLCAST_START" then
	local spell, _, _, _, _, _ = UnitCastingInfo("player")
		
		if spell then 				
			
			resultat = string.sub (spell, 1, 1)
			local cnc = CreateFrame("Frame", "CNC",UIParent)
			cnc:SetFrameStrata(HIGH)
			cnc:SetMovable(false)
			cnc:SetWidth(220)
			cnc:SetHeight(10)
			cnc:ClearAllPoints()
			cnc:SetPoint("Center", "AzCastBarPluginPlayer")
			local font = cnc:CreateFontString(nil,"OVERLAY")
			font:SetFont("Fonts\\FRIZQT__.TTF",11, "OUTLINE")
			font:SetTextColor(0.07, 0.30, 0.46, 1.0);
			font:SetText(resultat)
			font:SetPoint("Left",CNC,"Left",-1,0)	
		end

elseif event == "UNIT_SPELLCAST_STOP" then
	CNC:Hide()
elseif event == "UNIT_SPELLCAST_FAILED" then
	CNC:Hide()
elseif event == "UNIT_SPELLCAST_SUCCEEDED" then
CNC:Hide()
elseif event == "UNIT_SPELLCAST_FAILED_QUIET" then
CNC:Hide()
end

end
frame:RegisterEvent("UNIT_SPELLCAST_START")
frame:RegisterEvent("UNIT_SPELLCAST_STOP")
frame:RegisterEvent("UNIT_SPELLCAST_SENT")
frame:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED")
frame:RegisterEvent("UNIT_SPELLCAST_FAILED")
frame:RegisterEvent("UNIT_SPELLCAST_FAILED_QUIET")

frame:SetScript("OnEvent", frame.OnEvent)
Now, im no lua expert, im pretty much just using trial and error method so here's my problem:

The Addon does exactly what i want until after my first cast. After that cast, regardless if it fails or not, it just stops hiding the frame showing the first letter :S

I'm pretty clueless what to do so i thought maybe someone over here can help me out^^
  Reply With Quote
10-27-10, 04:26 PM   #2
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,933
As far as I know you can't hide or show frames while in combat. Correct me if I'm wrong guys However, you could just set an alpha state and make it transparent until you need to show it.
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818
  Reply With Quote
10-27-10, 04:29 PM   #3
Miiru
A Flamescale Wyrmkin
 
Miiru's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2008
Posts: 138
Originally Posted by Xrystal View Post
As far as I know you can't hide or show frames while in combat. Correct me if I'm wrong guys However, you could just set an alpha state and make it transparent until you need to show it.
Tested it ooc
  Reply With Quote
10-27-10, 05:04 PM   #4
Vrul
A Scalebane Royal Guard
 
Vrul's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 404
Part of your problem is that you are creating a new frame/fontstring for each 'UNIT_SPELLCAST_START'. Another issue is that those events fire for more than just your character so you need to check that the first argument is 'player'.

I would recommend modifying things a bit:
lua Code:
  1. local frame = CreateFrame('Frame', "CNC", UIParent)
  2. frame:SetPoint('CENTER', "AzCastBarPluginPlayer")
  3. frame:SetFrameStrata('HIGH')
  4. frame:SetHeight(10)
  5. frame:SetWidth(220)
  6. frame:Hide()
  7.  
  8. local font = frame:CreateFontString(nil, 'OVERLAY')
  9. font:SetPoint('LEFT', -1, 0)   
  10. font:SetFont([[Fonts\FRIZQT__.TTF]], 11, 'OUTLINE')
  11. font:SetTextColor(0.07, 0.3, 0.46, 1)
  12.  
  13. frame:SetScript('OnEvent', function(self, event, unit)
  14.     if unit ~= 'player' then return end
  15.     if event == 'UNIT_SPELLCAST_START' then
  16.         local spell = UnitCastingInfo('player')
  17.         if spell then              
  18.             font:SetText(spell:sub(1, 1))
  19.             self:Show()
  20.             return
  21.         end
  22.     end
  23.     self:Hide()
  24. end)
  25. frame:RegisterEvent('UNIT_SPELLCAST_FAILED')
  26. frame:RegisterEvent('UNIT_SPELLCAST_FAILED_QUIET')
  27. frame:RegisterEvent('UNIT_SPELLCAST_SENT')
  28. frame:RegisterEvent('UNIT_SPELLCAST_START')
  29. frame:RegisterEvent('UNIT_SPELLCAST_STOP')
  30. frame:RegisterEvent('UNIT_SPELLCAST_SUCCEEDED')
  Reply With Quote
10-27-10, 05:15 PM   #5
p3lim
A Pyroguard Emberseer
 
p3lim's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 1,710
Originally Posted by Xrystal View Post
As far as I know you can't hide or show frames while in combat. Correct me if I'm wrong guys.
That only applies to secure frames (buttons, unitframes etc)
  Reply With Quote
10-28-10, 05:35 AM   #6
Miiru
A Flamescale Wyrmkin
 
Miiru's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2008
Posts: 138
Originally Posted by Vrul View Post
Part of your problem is that you are creating a new frame/fontstring for each 'UNIT_SPELLCAST_START'. Another issue is that those events fire for more than just your character so you need to check that the first argument is 'player'.

I would recommend modifying things a bit:
This gives me

Message: Interface\AddOns\CNC\Core.lua:2: CNC:SetPoint(): Couldn't find region named 'AzCastBarPluginPlayer'
Time: 10/28/10 13:33:50
Count: 1
Stack: [C]: in function `SetPoint'
Interface\AddOns\CNC\Core.lua:2: in main chunk

Locals: (*temporary) = CNC {
0 = <userdata>
}
(*temporary) = "CENTER"
(*temporary) = "AzCastBarPluginPlayer"

>:
  Reply With Quote
10-28-10, 07:21 AM   #7
Taroven
A Cyclonian
AddOn Author - Click to view addons
Join Date: Dec 2006
Posts: 49
Originally Posted by Neza View Post
This gives me

Message: Interface\AddOns\CNC\Core.lua:2: CNC:SetPoint(): Couldn't find region named 'AzCastBarPluginPlayer'<snip>
Remove the quotes from "AzCastBarPluginPlayer" on line 2.
__________________
Former author of EventHorizon Continued and Other Releases.
  Reply With Quote
10-28-10, 02:05 PM   #8
Vrul
A Scalebane Royal Guard
 
Vrul's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 404
Originally Posted by Neza View Post
Message: Interface\AddOns\CNC\Core.lua:2: CNC:SetPoint(): Couldn't find region named 'AzCastBarPluginPlayer'
You need to make sure that AzCastBar (or what ever addon creates AzCastBarPluginPlayer) is loaded before your addon. See wowpedia for details on how to accomplish that.
  Reply With Quote
10-28-10, 03:41 PM   #9
Taroven
A Cyclonian
AddOn Author - Click to view addons
Join Date: Dec 2006
Posts: 49
Removing the quotes from the frame name should work if it's already been created as well.
__________________
Former author of EventHorizon Continued and Other Releases.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Frame only Hiding once :S


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