Reply
Thread Tools Display Modes
Unread 03-26-13, 06:09 PM   #1
Brusalk
A Fallenroot Satyr
 
Brusalk's Avatar
AddOn Author - Click to view addons
Join Date: May 2010
Posts: 29
Help getting cooldown duration on spells with recharges

Hello!

I've been looking high and low and I haven't been able to find any information on this. (Probably because it's kind of obscure, and the only reason I'm looking for it is for backwards compatibility reasons)

Anyway, what I'm looking for is a way to determine the amount of time until a spell that has charges (conflag for example) will hit 1 charge when it first hits 0 charges.

So, for example, take conflag with 2 max charges and a recharge time of 12 seconds. If the player was to cast 2 conflags back to back, I would expect GetSpellCooldown() or GetSpellCharges() to return a duration of 12-GCDDuration, because it took 1 GCD to cast the first GCD, so you've already recharged 1 GCDDuration before the chgarges first hit 0 charges.


Both GetSpellCooldown and GetSpellCharges return 12 seconds as the duration, and the start is the same for both.


I'm looking for a way to determine how much time there is until a spell with charges goes from 0 charges to 1 from the time when it hits 0 charges.


Any help you can give me would be very appreciated! Thanks
Brusalk is offline   Reply With Quote
Unread 03-26-13, 09:35 PM   #2
Phanx
A Pyroguard Emberseer
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 4,743
I'm not entirely clear on what you're trying to do, but if you're having trouble displaying the correct cooldown on spells with charges, I'd suggest looking at OmniCC, as it shows the correct time remaining until I can cast the spell again once I hit 0 charges.
__________________
Author/maintainer of Grid, PhanxChat, ShieldsUp, and many more.
Troubleshoot an addonTurn any code into an addonMore addon resources
Need help with your code? Post all of your actual code! Attach or paste your files.
Please don’t PM me about addon bugs or code questions. Post a comment or forum thread instead!
Phanx is offline   Reply With Quote
Unread 03-26-13, 10:14 PM   #3
semlar
A Molten Giant
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 636
GetSpellCooldown returns the timestamp of when you first cast it and its duration. All you need to do is subtract the current time from that to get how much time is left.

Here's a complete example.
Lua Code:
  1. local text = UIParent:CreateFontString(nil, nil, 'GameFontNormal')
  2. text:SetPoint('CENTER')
  3. CreateFrame('frame'):SetScript('OnUpdate', function()
  4.  local start, duration = GetSpellCooldown('conflagrate')
  5.  if duration > 2 then
  6.   local timeLeft = start + duration - GetTime() -- time until it recharges the first charge, in seconds
  7.   text:SetFormattedText('%d seconds until conflagrate', timeLeft)
  8.  else
  9.   text:SetText('Conflagrate not on cooldown')
  10.  end
  11. end)

Last edited by semlar : 03-26-13 at 10:23 PM.
semlar is online now   Reply With Quote
Unread 03-26-13, 11:59 PM   #4
Brusalk
A Fallenroot Satyr
 
Brusalk's Avatar
AddOn Author - Click to view addons
Join Date: May 2010
Posts: 29
@Semlar,

That's not the problem I'm having.

The problem is that the duration for recharge spells (namely Conflag) is ALWAYS 12 seconds, regardless of how much actual time there is left.
Brusalk is offline   Reply With Quote
Unread 03-27-13, 12:06 AM   #5
semlar
A Molten Giant
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 636
The duration is 12 seconds. The duration of the cooldown doesn't change.

The time left is determined by adding the duration to the start time and subtracting the current time.
semlar is online now   Reply With Quote
Unread 03-27-13, 12:13 AM   #6
Brusalk
A Fallenroot Satyr
 
Brusalk's Avatar
AddOn Author - Click to view addons
Join Date: May 2010
Posts: 29
Okay, so for an example of what I'm trying to describe:

Normal CD (12 second Cooldown):

Cast @ 10
Start = 10
Duration = 12
Start + Duration = 22


Recharge CD (12 second recharge):

Cast 1 @ 10
Cast 2 @ 12
Duration = 12
Start + Duration = 24

However, the expected time for the charges to actually hit 1 is @22sec. (As 2 seconds of recharge have already happened at the time you casted the spell a second time and it's charges hit 0)
Brusalk is offline   Reply With Quote
Unread 03-27-13, 12:15 AM   #7
semlar
A Molten Giant
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 636
The time until the first charge comes back is 12 seconds from the first cast.

I tested this in-game before I wrote the example.
semlar is online now   Reply With Quote
Unread 03-27-13, 12:31 AM   #8
Brusalk
A Fallenroot Satyr
 
Brusalk's Avatar
AddOn Author - Click to view addons
Join Date: May 2010
Posts: 29
I guess I'll have to include more logic then.

I was hoping there was a way to get the value not from when the recharge first starts but when it first hits 0 charges.
Brusalk is offline   Reply With Quote
Unread 03-27-13, 12:43 AM   #9
semlar
A Molten Giant
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 636
I am very confused about what you're trying to do.

I thought you wanted to know how much time before conflagrate was usable again after it hit 0 charges, but you don't need to know the timestamp of when it hit 0 charges for that.

The main reason for knowing when it hit 0 would be to determine when the second charge is going to come back.

I guess the other reason would be if you needed the start time for a cooldown spinner or something.

If you know when it went on cooldown then you know when it hit 0 charges. The most efficient way to determine that really depends on how this is being implemented.

If this is for an action button there are much simpler ways to get the cooldown information.

Last edited by semlar : 03-27-13 at 01:18 AM.
semlar is online now   Reply With Quote
Unread 03-27-13, 01:16 AM   #10
Brusalk
A Fallenroot Satyr
 
Brusalk's Avatar
AddOn Author - Click to view addons
Join Date: May 2010
Posts: 29
Basically I'm trying to implement some old functionality into a rewritten version of the addon (for various reasons)

The old behavior was that it would show a timer starting when Conflag would hit 0 charges, and end when it went up to 1 charge.
Brusalk is offline   Reply With Quote
Unread 03-27-13, 01:30 AM   #11
semlar
A Molten Giant
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 636
Isn't that what the script I posted does?
semlar is online now   Reply With Quote
Unread 03-27-13, 01:40 AM   #12
Brusalk
A Fallenroot Satyr
 
Brusalk's Avatar
AddOn Author - Click to view addons
Join Date: May 2010
Posts: 29
Yeah. You're completely correct.


I was in the middle of raiding and between pulls responding, and I totally made an assumption about what your code was doing. I didn't look close enough at it. My bad.


I was totally overcomplicating it.


Thanks for the help!
Brusalk is offline   Reply With Quote
Unread 03-27-13, 01:49 AM   #13
semlar
A Molten Giant
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 636
Ah, well that explains the confusion.

If you have any more questions don't hesitate to ask.
semlar is online now   Reply With Quote
Reply

Go BackWoWInterface » Developer Discussions » Lua/XML Help » Help getting cooldown duration on spells with recharges

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