Thread Tools Display Modes
04-21-14, 02:05 PM   #1
philipe24
A Deviate Faerie Dragon
Join Date: Jan 2014
Posts: 10
Script to visualize a PlayerBuff;performance?

Hey,
i've been using WeakAauras for a long time to visualize how many Stacks of specific buff I currently got. But to keep my performance as high as possible I decided to write a script for that on my own.

My LUA knowledge isnt that high, so the following script is what came out of my plan.

local readysetaim1 = UIParent:CreateTexture(nil,"Overlay")
readysetaim1:SetHeight(25)
readysetaim1:SetWidth(25)
readysetaim1:SetPoint("CENTER",SpellActivationOverlayFrame,"CENTER", 0, -220)
readysetaim1:SetTexture("Interface\\ready1.blp")


local readysetaim2 = UIParent:CreateTexture(nil,"Overlay")
readysetaim2:SetHeight(25)
readysetaim2:SetWidth(25)
readysetaim2:SetPoint("CENTER",SpellActivationOverlayFrame,"CENTER", 0, -220)
readysetaim2:SetTexture("Interface\\ready2.blp")

local readysetaim = CreateFrame("FRAME")
readysetaim:RegisterEvent("UNIT_AURA")
readysetaim:SetScript("OnEvent", function(self, event, ...)
local unitid = ... if unitid ~= "player" then return end
local mm={UnitBuff("player","Ready, Set, Aim...")}
if UnitBuff("player", "Ready, Set, Aim...") and mm[4]==1 then
readysetaim1:Show()
else
if UnitBuff("player", "Ready, Set, Aim...") and mm[4]==2 then
readysetaim1:Hide()
readysetaim2:Show()
else
readysetaim1:Hide()
readysetaim2:Hide()
end
end
end)


It just creates two different Textures which I created with Photoshop. These are only shown if I either got one or two stacks of "Ready, Set, Aim..."

Screenshot: http://i.imgur.com/hNyFOtN.jpg

My question now is if its possible to make this any less performance-heavy or if its "okay" the way i made it. Actually it just needs to show the number of stacks like "1" or "2". So is it even necessary to use a texture?

greetings and first of all thanks for any help!

Last edited by philipe24 : 04-21-14 at 02:31 PM.
  Reply With Quote
04-21-14, 02:47 PM   #2
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Code:
local frame = CreateFrame("Frame", "ReadySetAim", UIParent)
frame:SetPoint("CENTER", SpellActivationOverlayFrame, "CENTER", 0, -220)
frame:SetSize(25, 25)

local texture = frame:CreateTexture(nil, "ARTWORK")
texture:SetAllPoints(true)
frame.texture = texture

frame:RegisterUnitEvent("UNIT_AURA", "player")
frame:SetScript("OnEvent", function(self, event, unit)
	local _, _, _, count = UnitAura("player", "Ready, Set, Aim...")
	if count == 2 then
		texture:SetTexture("Interface\\AddOns\\YOUR_ADDON_FOLDER\\ready2")
	elseif count == 1 then
		texture:SetTexture("Interface\\AddOns\\YOUR_ADDON_FOLDER\\ready1")
	else
		texture:SetTexture("")
	end
end)
  • You should generally avoid attaching textures directly to the UIParent, and since you're already creating a frame to listen for events, you can just attach your textures to your own frame instead.
  • Since only one texture is shown at a time, you only need one texture object, and then instead of hiding and showing, you can just change which texture it's displaying.
  • Since you only care about your own auras, you can use RegisterUnitEvent instead of RegisterEvent, so you don't have to check the unit argument, because your frame won't even receive the event for other units.
  • Instead of calling UnitAura with the same arguments multiple times, you should just call it once, and store the returned values in variables, and check the variables. You can assign multiple variables at a time; you don't need to create a table to hold them, and in fact should never do this, as creating new tables over and over will waste a lot of memory.
  • Finally, you should move your texture files into your addon folder, and change "YOUR_ADDON_FOLDER" in the code above to the name of your addon folder. You don't need to include the file extension in the path you give to SetTexture, and in fact some functions (like SetPortraitToTexture) will actually fail if you include the extension, so it's best to just get in the habit of leaving it off.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Script to visualize a PlayerBuff;performance?


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