Thread Tools Display Modes
Prev Previous Post   Next Post Next
02-21-12, 08:37 AM   #1
lerb
A Frostmaul Preserver
 
lerb's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 264
Creating a Shadow Orb element for oUF

Hey everyone! Requesting some more of your help I don't know if I'm supposed to post this here or in the actual oUF part of the forum, but I'm gonna give this place a try. It's LUA, after all

What I want to do is rather simple. I want a tracker that tracks a players shadow orbs, shown as 1-3 bars. I have an example here, this is soul shards on my warlock;



I'm using the soulshard-element for oUF to create this, using this code in my layout;

Code:
		if LeUI.Class == 'WARLOCK' then
		    self.SoulShards = CreateFrame('Frame', nil, self)
			for i = 1, 3 do
				self.SoulShards[i] = CreateFrame('StatusBar', self:GetName()..'_SoulShards'..i, self)
				self.SoulShards[i]:SetSize(60, 12)
				self.SoulShards[i]:SetStatusBarTexture(LeUI.media.texture)
				self.SoulShards[i]:SetStatusBarColor(LeUI.Classcolor.r, LeUI.Classcolor.g, LeUI.Classcolor.b)
				
				if(i == 1) then
					self.SoulShards[i]:SetPoint('CENTER', UIParent, 'BOTTOM', -70, 96)
				else
					self.SoulShards[i]:SetPoint('TOPLEFT', self.SoulShards[i-1], 'TOPRIGHT', 10, 0)
				end
				
				CreateBorderLight(self.SoulShards[i], LeUI.media.bordersize, LeUI.bordercolor, LeUI.bordercolor, LeUI.bordercolor, 4)
				
				self.SoulShards[i]:SetBackdrop(backdrop)
				self.SoulShards[i]:SetBackdropColor(unpack(LeUI.media.backdropcolor))
			end
		end
Now, I want the exact same thing but for Shadow Orbs when playing priest. I've been looking around but can't find an oUF element for Shadow Orbs, so I thought it wouldn't be so hard to write my own. I guess I was wrong

I thought it wouldn't be harder than to copy the Soulshard element lua-file and basically edit it for Shadow Orbs, but I can't seem to get it to work. Here's the code I ended up with _after_ editing soulshards.lua in oUF elements;

Code:
if(select(2, UnitClass('player')) ~= 'PRIEST') then return end

local parent, ns = ...
local oUF = ns.oUF

local SPELL_POWER_SHADOW_ORBS = SPELL_POWER_SHADOW_ORBS
local MAX_SHADOW_ORBS = MAX_SHADOW_ORBS

local Update = function(self, event, unit, powerType)
	if(self.unit ~= unit or (powerType and powerType ~= 'SHADOW_ORBS')) then return end

	local so = self.ShadowOrbs
	if(so.PreUpdate) then so:PreUpdate(unit) end

	local num = UnitPower('player', SPELL_POWER_SHADOW_ORBS)
	for i = 1, MAX_SHADOW_ORBS do
		if(i <= num) then
			so[i]:SetAlpha(1)
		else
			so[i]:SetAlpha(0)
		end
	end

	if(so.PostUpdate) then
		return so:PostUpdate(unit)
	end
end

local Path = function(self, ...)
	return (self.ShadowOrbs.Override or Update) (self, ...)
end

local ForceUpdate = function(element)
	return Path(element.__owner, 'ForceUpdate', element.__owner.unit, 'SHADOW_ORBS')
end

local function Enable(self)
	local so = self.ShadowOrbs
	if(so) then
		so.__owner = self
		so.ForceUpdate = ForceUpdate

		self:RegisterEvent('UNIT_POWER', Path)

		return true
	end
end

local function Disable(self)
	local so = self.ShadowOrbs
	if(so) then
		self:UnregisterEvent('UNIT_POWER', Path)
	end
end

oUF:AddElement('ShadowOrbs', Path, Enable, Disable)
Using this, I end up with this error;

Code:
...\LeUI\Modules\Unitframes\oUF\elements\shadoworbs.lua:16: 'for' limit must be a number

I'll have to point out that I'm no more than a rookie to LUA, and this is taking water over my head. But I really hope I can get it working with some help from you guys, like many times before
  Reply With Quote
 

WoWInterface » Developer Discussions » Lua/XML Help » Creating a Shadow Orb element for oUF


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