Thread Tools Display Modes
02-08-10, 05:55 AM   #1
hairy_palms
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Feb 2010
Posts: 25
Newb Issue

ive been trying to write my first ever addon with ouf, but ive hit some issues pretty early, its only supposed to show debuffs at the moment, which it does, but i want a text timer on it which doesnt seem to work, heres my code currently if anyone can see where im going wrong

Code:
local function mylayout(self, event, unit)

	-- dimensions.

	self:SetHeight(40)
	self:SetWidth(240)	

	-- Debuffz bar.

	local deebeez = CreateFrame("Frame", nil, self)
	deebeez:SetHeight(40)
	deebeez:SetWidth(240)
	deebeez:SetPoint("TOPLEFT", 0, 0)
	self.Debuffs = deebeez	
	self.Debuffs:SetPoint("TOPLEFT", self, "BOTTOMLEFT", -1, -8)
	self.Debuffs.initialAnchor = "TOPLEFT"
	self.Debuffs.onlyShowPlayer = true
	self.Debuffs:SetWidth(44 * 6)
	self.Debuffs.size = 40
	self.Debuffs.spacing = 4
	--self.Debuffs.disableCooldown = true
	self.PostUpdateAuraIcon = imbadatlua
end

oUF:RegisterStyle("ouf_mikerockz", mylayout)
oUF:SetActiveStyle("ouf_mikerockz")
oUF:Spawn("target", "oUF_Layout_MikesTargetFrame"):SetPoint("CENTER", -455, 0)

local imbadatlua = function(self,elapsed)
		if self.timeLeft > 0 then
			local time = FormatTime(self.timeLeft)
			self.remaining:SetText(time)				
		end		
end

Last edited by hairy_palms : 02-08-10 at 06:01 AM.
  Reply With Quote
02-08-10, 06:16 AM   #2
contramundi
A Chromatic Dragonspawn
 
contramundi's Avatar
AddOn Compiler - Click to view compilations
Join Date: May 2008
Posts: 180
Originally Posted by hairy_palms View Post
ive been trying to write my first ever addon with ouf, but ive hit some issues pretty early, its only supposed to show debuffs at the moment, which it does, but i want a text timer on it which doesnt seem to work, heres my code currently if anyone can see where im going wrong

Code:
local function mylayout(self, event, unit)

	-- dimensions.

	self:SetHeight(40)
	self:SetWidth(240)	

	-- Debuffz bar.

	local deebeez = CreateFrame("Frame", nil, self)
	deebeez:SetHeight(40)
	deebeez:SetWidth(240)
	deebeez:SetPoint("TOPLEFT", 0, 0)
	self.Debuffs = deebeez	
	self.Debuffs:SetPoint("TOPLEFT", self, "BOTTOMLEFT", -1, -8)
	self.Debuffs.initialAnchor = "TOPLEFT"
	self.Debuffs.onlyShowPlayer = true
	self.Debuffs:SetWidth(44 * 6)
	self.Debuffs.size = 40
	self.Debuffs.spacing = 4
	--self.Debuffs.disableCooldown = true
	self.PostUpdateAuraIcon = imbadatlua
end

oUF:RegisterStyle("ouf_mikerockz", mylayout)
oUF:SetActiveStyle("ouf_mikerockz")
oUF:Spawn("target", "oUF_Layout_MikesTargetFrame"):SetPoint("CENTER", -455, 0)

local imbadatlua = function(self,elapsed)
		if self.timeLeft > 0 then
			local time = FormatTime(self.timeLeft)
			self.remaining:SetText(time)				
		end		
end
another noob here throwing up a thought, the "self.timeleft" function your trying to use, doesn't it need to be defined so the code actually knows what your trying to call upon?

and another question, doesn't "self,elapsed" has to be "self.elapsed"? (with a dot)

Those are the things that kind of look strange to me, but me being a newbie at lua as well, it might just be my fault ^^. There's bound to be a lua pro commenting as well quickly enough

Last edited by contramundi : 02-08-10 at 06:19 AM.
  Reply With Quote
02-08-10, 06:53 AM   #3
hairy_palms
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Feb 2010
Posts: 25
hmm u might be right, should i call self.timeleft from UnitAura("Target", index, "HARMFUL")?


the function
Code:
function(self,elapsed)
could probably be function(self) i think but all the other ouf frames i looked at seemed to include the elapsed as well, and i thought the worst it would do is be useless, taking it out doesnt make the timer work anyway
  Reply With Quote
02-08-10, 08:14 AM   #4
nailertn
An Aku'mai Servant
Join Date: Oct 2008
Posts: 33
I have just briefly run through aura.lua so I may be off but:

PostUpdateAuraIcon sends the following arguments: object, icons, unit, icon, index, offset, filter, isDebuff. In your imbadatlua function you are referring object with self, thus self.timeLeft and self.remaining are undefined fields. Unless SetCooldown does add those automatically, they would be undefined even if you were referring the correct frame. In any case, since cooldown is enabled, you are better off just installing OmniCC and let it create and update the strings you are looking for.
  Reply With Quote
02-08-10, 10:54 AM   #5
hairy_palms
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Feb 2010
Posts: 25
omniCC doesnt do what i want, and cooldowns only commented out untill i can get the text to show up, besides, im trying to make a simple target debuff tracker partly as a learning exercise and just installing another addon wont help that :P

but anyway, ive been lookin at it some more and i think ive made progress but still no cigar im calling it with UnitDebuff, im calling VT directly just for testing purposes.

Code:
local function mylayout(self, event, unit)

	-- dimensions.

	self:SetHeight(40)
	self:SetWidth(240)	

	-- Debuffz bar.

	local deebeez = CreateFrame("Frame", nil, self)
	deebeez:SetHeight(40)
	deebeez:SetWidth(240)
	deebeez:SetPoint("TOPLEFT", 0, 0)
	self.Debuffs = deebeez	
	self.Debuffs:SetPoint("TOPLEFT", self, "BOTTOMLEFT", -1, -8)
	self.Debuffs.initialAnchor = "TOPLEFT"
	self.Debuffs.onlyShowPlayer = true
	self.Debuffs:SetWidth(44 * 6)
	self.Debuffs.size = 40
	self.Debuffs.spacing = 4
	--self.Debuffs.disableCooldown = true
	self.PostUpdateAuraIcon = imbadatlua
end

oUF:RegisterStyle("ouf_mikerockz", mylayout)
oUF:SetActiveStyle("ouf_mikerockz")
oUF:Spawn("target", "oUF_Layout_MikesTargetFrame"):SetPoint("CENTER", -455, 0)

local imbadatlua = function(self,elapsed)
       local name, _, _, _, _, duration, expiry, unitCaster = UnitDebuff("target","Vampiric Touch")
	self.timeLeft = expiry
	self.remaining = duration
	self.remaining:SetText(self.timeLeft)
	self.remaining:SetTextColor(0.84, 0.75, 0.65)
end
  Reply With Quote
02-08-10, 12:53 PM   #6
Rostok
A Flamescale Wyrmkin
Join Date: Jul 2008
Posts: 127
Code:
local FormatTime = function(s)
	if s >= 86400 then
		return format('|cffffffff%d|r'..hexclasscolor..'d|r', floor(s/86400 + 0.5)), s % 86400
	elseif s >= 3600 then
		return format('|cffffffff%d|r'..hexclasscolor..'h|r', floor(s/3600 + 0.5)), s % 3600
	elseif s >= 60 then
		return format('|cffffffff%d|r'..hexclasscolor..'m|r', floor(s/60 + 0.5)), s % 60
	end
	return floor(s + 0.5), (s * 100 - floor(s * 100))/100
end

local CreateAuraTimer = function(self,elapsed)
	if self.timeLeft then
		self.elapsed = (self.elapsed or 0) + elapsed
		if self.elapsed >= 0.1 then
			if not self.first then
				self.timeLeft = self.timeLeft - self.elapsed
			else
				self.timeLeft = self.timeLeft - GetTime()
				self.first = false
			end
			if self.timeLeft > 0 then
				local atime = FormatTime(self.timeLeft)
				self.remaining:SetText(atime)
			else
				self.remaining:Hide()
				self:SetScript('OnUpdate', nil)
			end
			self.elapsed = 0
		end
	end
end

local CustomAuraFilter = function(icons, unit, icon, name, rank, texture, count, dtype, duration, timeLeft, caster)
	local isPlayer
	if(caster == 'player' or caster == 'vehicle') then
		isPlayer = true
	end
	if((icons.onlyShowPlayer and isPlayer) or (not icons.onlyShowPlayer and name)) then
		icon.isPlayer = isPlayer
		icon.owner = caster
		-- We set it to math.huge, because it lasts until cancelled.
		if(timeLeft == 0) then
			icon.timeLeft = math.huge
		else
			icon.timeLeft = timeLeft
		end
		return true
	end
end

local sort = function(a, b)
	return a.timeLeft > b.timeLeft
end

local PreAuraSetPosition = function(self, auras, max)
	table.sort(auras, sort)
end

local CancelAura = function(self, button)
    if (button == 'RightButton' and not self.debuff) then
        CancelUnitBuff('player', self:GetID())
    end
end

local function PostCreateAuraIcon(self, button, icons, index, debuff)
	button.count:SetFont(db.font, db.fontsize, 'OUTLINE')
	button.count:SetPoint('TOPRIGHT', button, 'TOPRIGHT', -1, 8)
	icons.disableCooldown = true
	icons.showDebuffType = true
	button.cd:SetReverse()

	icons.noOCC = true
	button.overlay:SetTexture(db.border)
	button.overlay:SetTexCoord(0, 1, 0, 1)
	button.overlay.Hide = function(self) self:SetVertexColor(0, 0, 0) end

	if icons ~= self.Enchant then
		if (self.unit == 'player') then
			button:SetScript('OnMouseUp', CancelAura)
		end
	else
		button.overlay:SetVertexColor(RAID_CLASS_COLORS[class].r,RAID_CLASS_COLORS[class].g,RAID_CLASS_COLORS[class].b)
		button.cd:Hide()
	end
	
	button.bg = CreateFrame('Frame', nil, button)
	button.bg:SetPoint('TOPLEFT', button, 'TOPLEFT', -4, 4)
	button.bg:SetPoint('BOTTOMRIGHT', button, 'BOTTOMRIGHT', 4, -4)
	button.bg:SetFrameStrata('LOW')
	button.bg:SetBackdrop(db.frameBD)
	button.bg:SetBackdropColor(0, 0, 0, 0)
	button.bg:SetBackdropBorderColor(0, 0, 0,0.5)
	
	local remaining = button:CreateFontString(nil, 'OVERLAY')
	remaining:SetPoint('BOTTOM')
	remaining:SetFont(db.font, db.fontsize+1, 'OUTLINE')
	remaining:SetTextColor(1, 1, 1)
	button.remaining = remaining
end

local function PostUpdateAuraIcon(self, icons, unit, icon, index, offset, filter, duration, timeLeft)
	local name, _, _, _, _, duration, timeLeft, unitCaster, _ = UnitAura(unit, index, icon.filter)
	if UnitCanAttack('player', unit) then
		if unitCaster == 'player' or unitCaster == 'pet' or unitCaster == 'vehicle' then
			if duration and duration > 0 then
				icon.cd:Show()
			else
				icon.cd:Hide()
			end
		else
			icon.icon:SetDesaturated(true)
			icon.cd:Hide()
		end
	else
		if duration and duration > 0 then
			icon.cd:Show()
		else
			icon.cd:Hide()
		end
	end
	if duration and duration > 0 then
		icon.remaining:Show()
	else
		icon.remaining:Hide()
	end

	icon.duration = duration
	icon.first = true
	icon:SetScript('OnUpdate', CreateAuraTimer)
end
That's what I have. Code from oUF_p3lim and oUF_Freeb for the timer text and haste for the sorting portion (credit to the authors).
Just some code changes, as i'm not an author myself.
But you must define remaining in a PostCreateAuraIcon for your code to work.
  Reply With Quote

WoWInterface » Featured Projects » oUF (Otravi Unit Frames) » Newb Issue


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