• 0

    posted a message on "Overwriting" a function
    Hi there,

    I really don't know if this is the right forum to ask for general LUA problems.. but the others seemed more wrong XD

    I'm using PitBull4 to display debuffs on my target frame, which works just as intended. Now I saw a nice detail on Tukui - all debuffs exept my own are greyed out - so that you can easily see if and which debuffs are active on the target and if it's yours.

    So I thought - you need this too ! I had a look at the LUA code of PitBull and found the function which handles the creation of the aura stuff .. my only problem is HOW can I "Highjack" this function and replace it with my own one (which has the altered/added code) ?

    I tired making an aditional addon, which just had PitBull4_Aura as parent and tried to replace the function with "PitBull4_Aura:set_aura(blablastuff)" but that just threw up some errors (seems some globals were overwritten by this function).

    Am I on the right path or shoud I face the problem from a different angle ?
    This is the original function as it can be found in PitBull4_Aura/Update.lua

    local function set_aura(frame, db, aura_controls, aura, i, is_friend)
    	local control = aura_controls[i]
    
    	local id, slot, quality, is_buff, name, rank, icon, count, debuff_type, duration, expiration_time, caster, is_stealable = unpack(aura, 1, ENTRY_END)
    
    	local is_mine = my_units[caster]
    	local who = is_mine and "my" or "other"
    	-- No way to know who applied a weapon buff so we have a separate
    	-- category for them.
    	if slot then who = "weapon" end
    	local rule = who .. '_' .. (is_buff and "buffs" or "debuffs")
    
    	if not control then
    		control = PitBull4.Controls.MakeAura(frame)
    		aura_controls[i] = control
    	end
    
    	local layout = is_buff and db.layout.buff or db.layout.debuff
    	control:SetFrameLevel(frame:GetFrameLevel() + layout.frame_level)
    
    	control.id = id
    	control.is_mine = is_mine
    	control.is_buff = is_buff
    	control.name = name
    	control.count = count
    	control.duration = duration
    	control.expiration_time = expiration_time
    	control.debuff_type = debuff_type
    	control.slot = slot
    
    	local class_db = frame.classification_db
    	if not db.click_through and class_db and not class_db.click_through then
    		control:EnableMouse(true)
    	else
    		control:EnableMouse(false)
    	end
    
    	local texture = control.texture
    	texture:SetTexture(icon)
    	if db.zoom_aura then
    		texture:SetTexCoord(0.07, 0.93, 0.07, 0.93)
    	else
    		texture:SetTexCoord(0, 1, 0, 1)
    	end
    		
    	local texts = db.texts[rule]
    	local count_db = texts.count
    	local font,font_size = frame:GetFont(count_db.font, count_db.size)
    	local count_text = control.count_text
    	local count_anchor = count_db.anchor
    	local count_color = count_db.color
    	count_text:ClearAllPoints()
    	count_text:SetPoint(count_anchor,control,count_anchor,count_db.offset_x,count_db.offset_y)
    	count_text:SetFont(font, font_size, "OUTLINE")
    	count_text:SetTextColor(count_color[1],count_color[2],count_color[3],count_color[4])
    	count_text:SetText(count > 1 and count or "")
    
    	if db.cooldown[rule] and duration and duration > 0 then
    		local cooldown = control.cooldown
    		cooldown:Show()
    		cooldown:SetCooldown(expiration_time - duration, duration)
    	else
    		control.cooldown:Hide()
    	end
    
    	if db.cooldown_text[rule] and duration and duration > 0 then
    		local cooldown_text = control.cooldown_text
    		local cooldown_text_db = texts.cooldown_text
    		local color = cooldown_text_db.color
    		local r,g,b,a = color[1],color[2],color[3],color[4]
    		font,font_size = frame:GetFont(cooldown_text_db.font, cooldown_text_db.size)
    		cooldown_text:SetFont(font, font_size, "OUTLINE")
    		cooldown_text:ClearAllPoints()
    		local anchor = cooldown_text_db.anchor
    		cooldown_text:SetPoint(anchor,control,anchor,cooldown_text_db.offset_x,cooldown_text_db.offset_y)
    		local color_by_time = cooldown_text_db.color_by_time
    		if not color_by_time then
    			cooldown_text:SetTextColor(r,g,b,a)
    		end
    		cooldown_text.color_by_time = cooldown_text_db.color_by_time
    		PitBull4_Aura:EnableCooldownText(control)	
    	else
    		PitBull4_Aura:DisableCooldownText(control)	
    	end
    
    	local border_db
    	if who == "weapon" then
    		border_db = db.borders[rule]
    	else
    		border_db = db.borders[rule][is_friend and "friend" or "enemy"]
    	end
    	if border_db.enabled then
    		local border = control.border
    		local colors = PitBull4_Aura.db.profile.global.colors
    		border:Show()
    		local color_type = border_db.color_type
    
    		if color_type == "weapon" and quality then
    			local r,g,b = GetItemQualityColor(quality)
    			border:SetVertexColor(r,g,b)
    		elseif color_type == "type" then
    			local color = colors.type[tostring(debuff_type)]
    			if not color then
    				-- Use the Other color if there's not
    				-- a color for the specific debuff type.
    				color = colors.type["nil"]
    			end
    			border:SetVertexColor(unpack(color))
    		elseif color_type == "caster" then
    			border:SetVertexColor(unpack(colors.caster[who]))
    		elseif color_type == "custom" and border_db.custom_color then
    			border:SetVertexColor(unpack(border_db.custom_color))
    		else
    			-- Unknown color type just set it to red, shouldn't actually
    			-- ever get to this code
    			border:SetVertexColor(1,0,0)
    		end
    	else
    		control.border:Hide()
    	end
    end


    I'm really looking forward to some ideas.
    Posted in: Lua Code Discussion
  • To post a comment, please or register a new account.