WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   AddOn Search/Requests (https://www.wowinterface.com/forums/forumdisplay.php?f=6)
-   -   Warrior stance on unit frame (https://www.wowinterface.com/forums/showthread.php?t=58620)

jegarn123 03-08-21 05:56 AM

Warrior stance on unit frame
 
Hello all!

Wow CLASSIC lua question:

I've been looking quite some time for an addon that shows the warrior stance on the unit frame.
After alot of searching, I came across this Lua code:

local _, class = UnitClass("player")
if class ~= "WARRIOR" then return end

local stance = {
2457, -- Battle Stance
71, -- Defensive Stance
2458 -- Berserker Stance
}

for id = 1, #stance do
local _, _, icon = GetSpellInfo(stance[id])
stance[id] = icon
end

-- Override Blizzard's code
PlayerFrame:UnregisterEvent("UNIT_PORTRAIT_UPDATE")
PlayerFrame.portrait = nil

local function UpdatePlayerPortrait()
local icon = stance[GetShapeshiftForm()]
if icon then
SetPortraitToTexture("PlayerPortrait", icon)
end
end

local frame = CreateFrame("Frame", PlayerFrame)
frame:SetScript("OnEvent", UpdatePlayerPortrait)
frame:RegisterUnitEvent("UPDATE_SHAPESHIFT_FORM")

SetPortraitToTexture("PlayerPortrait", stance[1])
UpdatePlayerPortrait()




-----------------------------------------------------------------------------------

I have no idea what I'm doing with Lua codes, but I somehow managed to convert it to an addon, and it did infact work.
Only problem I only want this to show in combat. When I'm out of combat I want my character portrait to show, just like normal. Probably a quick and easy fix, but I have no idea :)

Can someone experienced please help out?

Regards!

Kanegasi 03-08-21 06:16 PM

Replace everything you have here with the following:

Lua Code:
  1. local f=CreateFrame("frame")
  2. f:RegisterEvent("PLAYER_LOGIN")
  3. f.update=function(frame)
  4.     if frame and frame.unit=="player" and frame.portrait then
  5.         if frame.onHateList then
  6.             for i=1,GetNumShapeshiftForms() do
  7.                 local _,active,_,spellid=GetShapeshiftFormInfo(i)
  8.                 local _,_,icon=GetSpellInfo(spellid)
  9.                 if active and icon then
  10.                     SetPortraitToTexture(frame.portrait,icon)
  11.                     return
  12.                 end
  13.             end
  14.         end
  15.         SetPortraitTexture(frame.portrait,"player")
  16.     end
  17. end
  18. f:SetScript("OnEvent",function(self,event)
  19.     if event=="PLAYER_LOGIN" then
  20.         local _,class=UnitClass("player")
  21.         if class~="WARRIOR" then return end
  22.         self:RegisterEvent("PLAYER_REGEN_DISABLED")
  23.         self:RegisterEvent("PLAYER_REGEN_ENABLED")
  24.         self:RegisterEvent("UPDATE_SHAPESHIFT_FORM")
  25.         hooksecurefunc("UnitFramePortrait_Update",self.update)
  26.     end
  27.     self.update(PlayerFrame)
  28. end)

jegarn123 03-09-21 01:31 AM

Quote:

Originally Posted by Kanegasi (Post 338584)
Replace everything you have here with the following:

Lua Code:
  1. local f=CreateFrame("frame")
  2. f:RegisterEvent("PLAYER_LOGIN")
  3. f.update=function(frame)
  4.     if frame and frame.unit=="player" and frame.portrait then
  5.         if frame.onHateList then
  6.             for i=1,GetNumShapeshiftForms() do
  7.                 local _,active,_,spellid=GetShapeshiftFormInfo(i)
  8.                 local _,_,icon=GetSpellInfo(spellid)
  9.                 if active and icon then
  10.                     SetPortraitToTexture(frame.portrait,icon)
  11.                     return
  12.                 end
  13.             end
  14.         end
  15.         SetPortraitTexture(frame.portrait,"player")
  16.     end
  17. end
  18. f:SetScript("OnEvent",function(self,event)
  19.     if event=="PLAYER_LOGIN" then
  20.         local _,class=UnitClass("player")
  21.         if class~="WARRIOR" then return end
  22.         self:RegisterEvent("PLAYER_REGEN_DISABLED")
  23.         self:RegisterEvent("PLAYER_REGEN_ENABLED")
  24.         self:RegisterEvent("UPDATE_SHAPESHIFT_FORM")
  25.         hooksecurefunc("UnitFramePortrait_Update",self.update)
  26.     end
  27.     self.update(PlayerFrame)
  28. end)






It worked! Thank you so much for taking the time to help out! Appreciated! :)


All times are GMT -6. The time now is 06:05 AM.

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