WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   GetPowerRegen() * (start + duration - GetTime()) rounding problem (https://www.wowinterface.com/forums/showthread.php?t=52729)

Skudnfroodie 09-12-15 01:31 PM

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.

Seerah 09-12-15 07:43 PM

Have you tried using this? http://wowprogramming.com/docs/api/IsUsableAction

Skudnfroodie 09-13-15 02:09 AM

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.

pelf 09-13-15 04:00 AM

You could always ceil or floor the result before you compare against it.


All times are GMT -6. The time now is 03:52 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI