Thread Tools Display Modes
09-12-15, 01:31 PM   #1
Skudnfroodie
Premium Member
Premium Member
AddOn Author - Click to view addons
Join Date: Jul 2015
Posts: 3
GetPowerRegen() * (start + duration - GetTime()) rounding problem

Hi,

this code should display the Jab symbol every time the player has enough energy to use Jab and still be able to use Keg Smash when it comes of cooldown.

Code:
local regen = GetPowerRegen()
local power = UnitPower("player")
local start, duration = GetSpellCooldown(121253)
local timeLeft = start + duration - GetTime()

if power + (regen * timeLeft) >= 80 then KSA.icon:SetTexture(GetSpellTexture("Jab")) end
It functions fine in most cases but if the player is right between sufficient and insufficient energy the icon flickers. I'm pretty sure that it's because of some rounding errors but I don't have a solution.
  Reply With Quote
09-12-15, 07:43 PM   #2
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Have you tried using this? http://wowprogramming.com/docs/api/IsUsableAction
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
09-13-15, 02:09 AM   #3
Skudnfroodie
Premium Member
Premium Member
AddOn Author - Click to view addons
Join Date: Jul 2015
Posts: 3
As far if I understand it, "IsUsableAction" would only return 0, 1 when "Keg Smash" is on Cooldown but the player has enough energy to use it.

The function of the addon is to predict how much energy the player will have when "Keg Smash" comes off cooldown and, if the predicted value is above 80, inform the player that he can use "Jab" (which costs 40 energy) and still have 40 energy left the moment "Keg Smash" comes off cooldown (so the player can use "Keg Smash" immediately when it comes off cooldown without waiting.
  Reply With Quote
09-13-15, 04:00 AM   #4
pelf
Sentient Plasmoid
 
pelf's Avatar
Premium Member
Join Date: May 2008
Posts: 133
You could always ceil or floor the result before you compare against it.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » GetPowerRegen() * (start + duration - GetTime()) rounding problem

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