Buff Timer to be Statusbar instead of text
|
|
Quote:
|
Look at the SkinningMachine and SkinBuffs functions.
|
Quote:
|
Forgot to post the code
Lua Code:
|
Every time your function gets called you are setting a new OnUpdate for that buff slot.
|
Quote:
|
In ShinyBuffs you should see how I saved whether a buff slot was skinned/handled yet or not.
|
Quote:
|
Look for where it says "firstTime" and then check the event handler that actually calls the functions and sets that argument. ;)
|
Quote:
|
When you skin/handle a buff frame, store a value in that frame's table. Check to see if it's been handled already before trying to skin/handle it again.
|
Quote:
http://hastebin.com/olisukoyeb.coffee |
What doesn't work? You've commented out the whole status bar section, so no wonder! What did you do to prevent it from getting created multiple times?
|
Quote:
|
There are several problems with your code. Let's start with this one:
Code:
hooksecurefunc("AuraButton_Update", function(self, index) Code:
local BuffStatusBar = CreateFrame("StatusBar", nil, ABuffFrame) It also includes this: Code:
BuffStatusBar:SetScript("OnUpdate", function(self, Elapsed) Fortunately these are easy problems to solve. ================================ First, stop creating a new copy of that OnUpdate function every time a button is update. Create one copy of the function, outside of your AuraButton_Update hook: Code:
local function AuraButtonStatusBar_OnUpdate(self, Elapsed) Code:
BuffStatusBar:SetScript("OnUpdate", AuraButtonStatusBar_OnUpdate) Code:
_,_,_,_,_, ABuffFrameDuration, Exps = UnitBuff("player", index) 2. There is no variable "index" in this scope. Instead of looking for one, look for a value stored on the statusbar itself under the key name "index". 3. You're always specifying "player" -- this will fail when you're using a vehicle. Instead of "player", look at PlayerFrame.unit, which will usually be "player", but gets swapped with "vehicle" automatically when you enter or leave a vehicle. 4. You're using UnitBuff, but AuraButton_Update also runs for debuffs, so you should use UnitAura here instead, and store the filter value that's passed to AuraButton_Update. Fixed version: Code:
local _,_,_,_,_, ABuffFrameDuration, Exps = UnitAura(PlayerFrame.unit, self.index, self.filter) Code:
local Val = Exps-GetTime() Code:
BuffStatusBar.index = index You also need to update your hook function definition so it actually receives the "filter" argument: Code:
hooksecurefunc("AuraButton_Update", function(self, index, filter) ================================ Let's move on to the "creating thousands of statusbars" problem. Instead of indiscriminately creating a new statusbar every time an aura button updates, check to see if one already exists. If it does, use it. If it doesn't, then and only then should you create a new one: Code:
local BuffStatusBar = ABuffFrame.StatusBar From here, the logical next step is to move other things that only need to happen once into that chunk of code, so they don't keep getting run over and over for no reason. Since the statusbar is something you are creating, the default UI will never touch it, so all of the lines of code that place and style the statusbar only need to happen once. Move them into that block. The only thing you need to do with your statusbar after it's created is set the "index" value. ================================ Now your code should work, but there are a few simple optimizations I'd recommend doing. Since your code is going to be running very frequently, you should do everything you can (within reason) to make it as fast as possible. The first optimization is similar to what we did for the statusbar. The default UI isn't moving and styling icons and font strings on every button update, so you don't need to do that either -- you only need to do that once, on the first update for each button. Conveniently, you already have a way to tell if this is the first update for a given button -- if it doesn't have a statusbar yet, it's the first update. Just move all of your other one-time styling code into the same chunk of code where you create a statusbar. ================================ The second optimization would be to use just one OnUpdate function to update all the statusbars, instead of a separate OnUpdate function for each statusbar, and to use GetTime() directly as the statusbar value instead of doing math calculations. The parent frame for buffs and debuffs already has an OnUpdate function, so just piggyback on that: Code:
BuffFrame:HookScript("OnUpdate", function() You don't need to worry about whether or not the statusbar exists here, because BUFF_ACTUAL_DISPLAY is a count of how many buttons have already been updated, so your AuraButton_Update hook will already have been run for every button this loop catches. However, you need to make another adjustment inside your AuraButton_Update hook to support using times directly as statusbar values: Code:
-- Remove these two lines; we don't need them anymore: (Note that I didn't actually test any of this code in-game, so there may be typos. If you get an error and can't figure it out, post your complete updated code and the actual error message.) |
Quote:
This makes everything much more easier, when explained like this :D It works, but its behaving strange, the bars fills up instead of down, and sometime it doesn't really even do anything. Lua Code:
|
In the future, please don't quote the entire 1500 lines of a post. If you're replying the post directly before yours in the thread, there's no need for a quote at all. If you're replying to something further back, just quote the 1-3 lines that are most relevant to what you're replying. Scrolling past the whole thing quoted is annoying. :(
The first 26 lines of your current code don't need to exist. Delete everything up to (but not including) line 27: Code:
hooksecurefunc("AuraButton_Update", function(self, index, filter) Code:
local _, _, _, _, _, duration, expirationTime = UnitAura(PlayerFrame.unit, index, filter) And actually now that I'm looking at it again, the current code doesn't account for buffs that don't have durations. You'll want to do something like this: Code:
local _, _, _, _, _, duration, expirationTime = UnitAura(PlayerFrame.unit, index, filter) Code:
if ABuffFrame then |
Quote:
That makes much more sense. When i actually remove the check it give errors for some reason Lua Code:
|
All times are GMT -6. The time now is 12:03 PM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI