Thread Tools Display Modes
11-16-09, 07:17 AM   #1
Taaron
A Defias Bandit
Join Date: Nov 2009
Posts: 3
Showing cooldown from spell

Hi guys,

i am new here and have a problem to create my first addon.
I need to show the cooldown from innervate in a little frame:

Innervate is ready: the textbox displays ready
innervate is used: the textbox displays the countdown form 60 to 0

I found some code in the internet, and edited it for my use, but my problem is the setScript:OnUpdate event. when i'm casting innervate the cooldown stops at 60 seconds (no automatic refresh). The only refresh is, when i'm casting another spell, that uses the GlobalCooldown.

Could someone help me please, here is my code:

Code:
function createCI( spellName, xPos, yPos )

	--create and position our frame
	local f = CreateFrame("Frame")
	f:RegisterEvent("SPELL_UPDATE_COOLDOWN") 
	f:SetWidth(320)
	f:SetHeight(320)
	f:SetPoint("BOTTOMLEFT", xPos, yPos )

	--create the background texture
	local tex = f:CreateTexture(nil, "BACKGROUND")
	tex:SetTexture(GetSpellTexture(spellName))
	tex:SetAllPoints()

	--create the countdown overlay
	f.text = f:CreateFontString()
	f.text:SetFontObject(GameFontNormal)
	f.text:SetAllPoints()
	--f.text:SetTextHeight(32)
	f.text:SetText("Hellooo")

	--register the cooldown update function
	f:SetScript("OnEvent", updateCI )

	--store the spellname to be looked up later
	f.theSpellName = spellName
	
end

function updateCI( self, event, ... )

	local start, duration = GetSpellCooldown(self.theSpellName)

	local remaining = ""
	if ( GetTime() < start + duration ) then 
		self.remaining = 1 + math.floor((start+duration) - GetTime()) 
	end
                     self:SetScript("OnUpdate", showCD)

end

function showCD (self, event, ...)
     	self.text:SetText(remaining)
end

createCI("Innervate", 320, 320 )
Thanks in advance

Taaron

P.S: Sorry for my bad english, i'm a german guy
  Reply With Quote
11-16-09, 10:01 AM   #2
p3lim
A Pyroguard Emberseer
 
p3lim's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 1,710
Code:
function updateCI(self)
	local start, duration, enabled = GetSpellCooldown(self.theSpellName)

	if(enabled == 1 and duration > 1.5) then -- Make sure the spell is on cooldown and its not the global cooldown that ticks
		self.duration = start - GetTime() + duration
		self:SetScript('OnUpdate', showCD)
	end
end

function showCD(self, elapsed)
	self.duration = self.duration - elapsed

	if(self.duration <= 0) then
		self.text:SetText(nil)
		self:SetScript('OnUpdate', nil)
		return
	end

	if(self.duration < 60) then
		self.text:SetFormattedText('%d', self.duration)
	else
		self.text:setText(nil)
	end
end
Though I have a very lightweight alpha-quality addon with a very simple slashcommand system for cooldowns if you want.
This code is taken from that addon.
http://github.com/p3lim/Chill
  Reply With Quote
11-17-09, 05:09 AM   #3
Taaron
A Defias Bandit
Join Date: Nov 2009
Posts: 3
Great

Hey, thanks for ur great help, i modified it a little bit, but it works good.

Great addon u have, i hope, someday i will also can do so

But i have one another question and hope, you can help me:

Code:
	local tex = f:CreateTexture(nil, "BACKGROUND")
	tex:SetTexture(GetSpellTexture(spellName))
	tex:SetAllPoints()
Here i try to get the Texture from the spell, but i won't work, no error or something, the only thing i see is my frame without any texture.

Also i want to use Variables, to save my spells, do you know a good tutorial, because i am a noob right now, your addon seems to hard for me to read and understand

What i've read: In the .toc file there have to be an entry like this:

Code:
## SavedVariables: CooldownsDB,
in the .lua file i can load them into local variables, like

Code:
Cooldown_Options={} -- set Cooldown_Options as a table
Cooldown_Options=CooldownsDB[spells] --here i load the variables from the saved values to local ones
And for read the Table i can use in pairs, to get the saved spells

Is that right?

Thanks in advance

Greetz

Taaron
  Reply With Quote
11-17-09, 11:23 AM   #4
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,935
You might want to look up the SpellID from wowhead. It is quite possible that using the spellName instead will not work in all instances if it at all works like the spellInfo function.

If you look at this page http://www.wowwiki.com/API_GetSpellTexture it tells you that the SpellName parameter needs to be as if it was in the spell book. Using spellID instead means it doesn't have to be in the spell book for it to work.

This also gives an example of saving variables if you haven't read it already http://www.wowwiki.com/Saving_variab..._game_sessions. A small example but if you replace the variable with a table name you can then use the tablename to update the variables you want to save.
__________________


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
11-20-09, 01:00 PM   #5
Taaron
A Defias Bandit
Join Date: Nov 2009
Posts: 3
Thank you

Hi guys,

thanks for your help, works really fine now.

But i have one last question:

My texture of the spell fills my whole frame, is it able to
fit it only in the left of my frame?

Like this:



Anyone know, how to do this?

Greetz

Taaron
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Showing cooldown from spell


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