WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Script - Update Char-Portrait when exit an vehicle (https://www.wowinterface.com/forums/showthread.php?t=42320)

Rufio 01-09-12 07:07 AM

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

Phanx 01-09-12 05:25 PM

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)


Rufio 01-12-12 06:15 AM

I've no clue how to write stuff in lua, if it works i'll been ok with it :o

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

Phanx 01-13-12 05:36 AM

Typo. This:
Code:

f:SetScript("OnEvent", self, event, unit)
should be this:
Code:

f:SetScript("OnEvent", function(self, event, unit)


All times are GMT -6. The time now is 07:18 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI