Thread Tools Display Modes
03-08-21, 05:56 AM   #1
jegarn123
A Defias Bandit
Join Date: Mar 2021
Posts: 2
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!
  Reply With Quote
03-08-21, 06:16 PM   #2
Kanegasi
A Molten Giant
 
Kanegasi's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2007
Posts: 666
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)

Last edited by Kanegasi : 03-08-21 at 06:19 PM.
  Reply With Quote
03-09-21, 01:31 AM   #3
jegarn123
A Defias Bandit
Join Date: Mar 2021
Posts: 2
Originally Posted by Kanegasi View Post
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!
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Search/Requests » Warrior stance on unit frame

Thread Tools
Display Modes

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