Thread Tools Display Modes
01-09-12, 07:07 AM   #1
Rufio
A Murloc Raider
 
Rufio's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 9
Script - Update Char-Portrait when exit an vehicle

Hello guys,

i'm using this to replace the portrait with the classicon on a couple of frames:
Code:
--[[ Class Icons ]]
UFP = "UnitFramePortrait_Update"; 
UICC = "Interface\\TargetingFrame\\UI-Classes-Circles"; 
CIT = CLASS_ICON_TCOORDS

hooksecurefunc(UFP,function(self) 
 if self.portrait then
  if self.unit == "player" or self.unit == "pet" or self.unit == "partypet1" or self.unit == "partypet2" or self.unit == "partypet3" or self.unit == "partypet4" then return end
   local t = CIT[select(2,UnitClass(self.unit))] 
 if t 
  then self.portrait:SetTexture(UICC) self.portrait:SetTexCoord(unpack(t)) end end end)
The problem is, anytime i exit an vehicle my playerportrait looks kind a weird.
Anyone can give me a code to update this while exiting the vehicle?
typing /rl each time is nasty :-/

Ty<3
  Reply With Quote
01-09-12, 05:25 PM   #2
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
You guys copying arena macros into addons need to do some reading on good Lua coding practices. Everything any of you posts is full of leaked globals, unnecessary variables that don't even save space in the original macro versions, glaring general inefficiencies, horrible readability with inconsistent or no indentation, etc.

Anyway, you probably just need to force an update after someone leaves a vehicle:

Code:
local careUnits = {
	-- Likely, there are fewer units you do care about
	-- than units you don't, so this is easier to maintain.
	-- We need the frame references for forced updates later.
	["party1"] = PartyMemberFrame1,
	["party2"] = PartyMemberFrame2,
	["party3"] = PartyMemberFrame3,
	["party4"] = PartyMemberFrame4,
}

local CLASS_ICON_TCOORDS = CLASS_ICON_TCOORDS

local function UpdateClassPortrait(self)
	local unit, portrait = self.unit, self.portrait
	-- This saves a few table lookups.

	if not careUnits[unit] or not portrait then
		-- We do not care about this unit,
		-- or this frame does not have a portrait.
		return
	end

	local _, class = UnitClass(unit)
	local coords = CLASS_ICON_TCOORDS[class]
	if coords then
		portrait:SetTexture("Interface\\TargetingFrame\\UI-Classes-Circles")
		portrait:SetTexCoord(unpack(coords))
	end
end

hooksecurefunc("UnitFramePortrait_Update", UpdateClassPortrait)

-- Force an update when a unit leaves a vehicle.
local f = CreateFrame("Frame")
f:RegisterEvent("UNIT_EXITED_VEHICLE")
f:SetScript("OnEvent", function(self, event, unit)
	local frame = careUnits[unit]
	if frame then
		UpdateClassPortrait(frame)
	end
end)

Last edited by Phanx : 01-13-12 at 05:36 AM.
  Reply With Quote
01-12-12, 06:15 AM   #3
Rufio
A Murloc Raider
 
Rufio's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 9
I've no clue how to write stuff in lua, if it works i'll been ok with it

Code:
-- Force an update when a unit leaves a vehicle.
local f = CreateFrame("Frame")
f:RegisterEvent("UNIT_EXITED_VEHICLE")
f:SetScript("OnEvent", self, event, unit)
	local frame = careUnits[unit]
	if frame then
		UpdateClassPortrait(frame)
	end
end)
getting an error there
  Reply With Quote
01-13-12, 05:36 AM   #4
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Typo. This:
Code:
f:SetScript("OnEvent", self, event, unit)
should be this:
Code:
f:SetScript("OnEvent", function(self, event, unit)
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Script - Update Char-Portrait when exit an vehicle


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