WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Event for switching talents? (https://www.wowinterface.com/forums/showthread.php?t=55629)

Galaxy119 08-07-17 09:43 AM

Event for switching talents?
 
Sorry if this has been asked before but I couldn't find an answer, is there an event that fires when players select a talent?
The reason for needing this is for the rogue level 45 talents, Deeper stratagem and Anticipation, I have it where it correctly displays the proper amount of combo points for each talent choice in this tier, however you have to /reload upon logging in or changing the talent selection for the combo point bar to be affected by the change.

Lua Code:
  1. local parent, ns = ...
  2. local oUF = ns.oUF or oUF
  3.  
  4. local GetComboPoints = GetComboPoints
  5. if (select(2, GetTalentTierInfo(3,1))) == 1 then
  6.     MAX_COMBO_POINTS = 6
  7. elseif (select(2, GetTalentTierInfo(3,1))) == 2 then
  8.     MAX_COMBO_POINTS = 10
  9. else
  10.     MAX_COMBO_POINTS = 5
  11. end
  12. local class = select(2, UnitClass("player"))
  13.  
  14. local Update = function(self, event, unit, powerType)
  15.   if unit and (unit ~= "player" and unit ~= "vehicle") then return end
  16.   if powerType and powerType ~= "COMBO_POINTS" then return end
  17.   local bar = self.ComboBar
  18.   local cp = 0
  19.   if(UnitExists("vehicle") and UnitPower("vehicle",4) >= 1) then
  20.     cp = UnitPower("vehicle",4)
  21.   else
  22.     cp = UnitPower("player",4)
  23.   end
  24.  
  25.   if cp < 1 and (UnitHasVehicleUI("player") or class ~= "ROGUE") then
  26.     bar:Hide()
  27.     return
  28.   else
  29.     bar:Show()
  30.   end
  31.  
  32.   for i=1, MAX_COMBO_POINTS do
  33.     local orb = self.ComboPoints[i]
  34.     local full = cp/MAX_COMBO_POINTS
  35.     if(i <= cp) then
  36.       if full == 1 then
  37.         orb.fill:SetVertexColor(1,0,0)
  38.         orb.glow:SetVertexColor(1,0,0)
  39.       else
  40.         orb.fill:SetVertexColor(bar.color.r,bar.color.g,bar.color.b)
  41.         orb.glow:SetVertexColor(bar.color.r,bar.color.g,bar.color.b)
  42.       end
  43.       orb.fill:Show()
  44.       orb.glow:Show()
  45.       orb.highlight:Show()
  46.     else
  47.       orb.fill:Hide()
  48.       orb.glow:Hide()
  49.       orb.highlight:Hide()
  50.     end
  51.   end
  52. end
  53.  
  54. local Path = function(self, ...)
  55.   return (self.ComboPoints.Override or Update) (self, ...)
  56. end
  57.  
  58. local ForceUpdate = function(element)
  59.   return Path(element.__owner, "ForceUpdate", element.__owner.unit, nil)
  60. end
  61.  
  62. local Enable = function(self)
  63.   local element = self.ComboPoints
  64.   if(element) then
  65.     element.__owner = self
  66.     element.ForceUpdate = ForceUpdate
  67.     self:RegisterEvent("UNIT_COMBO_POINTS", Path, true) --make this unitless, some vehicles have combo points
  68.     self:RegisterEvent("UNIT_POWER_FREQUENT", Path)
  69.     local helper = CreateFrame("Frame") --this is needed...adding player_login to the visivility events does not do anything
  70.     helper:RegisterEvent("PLAYER_ENTERING_WORLD")
  71.     helper:SetScript("OnEvent", function() Path(self) end)
  72.     return true
  73.   end
  74. end
  75.  
  76. local Disable = function(self)
  77.   local element = self.ComboPoints
  78.   if(element) then
  79.     self:UnregisterEvent("UNIT_COMBO_POINTS", Path)
  80.     self:UnregisterEvent("UNIT_POWER_FREQUENT", Path)
  81.     self:UnregisterEvent("PLAYER_ENTERING_WORLD")
  82.   end
  83. end
  84.  
  85. oUF:AddElement("ComboPoints", Path, Enable, Disable)

syncrow 08-07-17 10:23 AM

Quote:

"PLAYER_TALENT_UPDATE"
might be the event you are searching for!

sezz 08-07-17 10:49 AM

Unit_maxpower

Galaxy119 08-07-17 11:23 AM

Quote:

Originally Posted by syncrow (Post 324550)
might be the event you are searching for!

Nope, that event fires when you change specs afaik

pas06 08-07-17 11:34 AM

i am not sure if there is an event but /eventtrace
Code:

https://wow.gamepedia.com/Eventtrace
tells you whenever a event fires
i just tested it and PLAYER_TALENT_UPDATE, PLAYER_PVP_TALENT_UPDATE and ACTIVE_TALENT_GROUP_CHANGED fired.
PLAYER_PVP_TALENT_UPDATE fired even tho i changed a normal (non pvp) talent

Galaxy119 08-07-17 11:57 AM

Hm, in that case, can you look over the code I'm using and see how you would go about using PLAYER_TALENT_UPDATE to update the MAX_COMBO_POINTS variable cuz it's not working the way i've tried it

Kakjens 08-07-17 12:20 PM

Why you are not using UnitPowerMax in line 32?

p3lim 08-07-17 01:32 PM

Why are you not using the ClassPower element that works out of the box in oUF?
If you need to do customizations to its behavior you can easily use callbacks or overrides.

syncrow 08-08-17 12:51 AM

try to use

Lua Code:
  1. local cp = UnitPower("Player", SPELL_POWER_COMBO_POINTS)
  2. local cpMax = UnitPowerMax("player", SPELL_POWER_COMBO_POINTS);
  3.  
  4. for i = 1, cpMax do...

Galaxy119 08-09-17 09:32 AM

Quote:

Originally Posted by p3lim (Post 324568)
Why are you not using the ClassPower element that works out of the box in oUF?
If you need to do customization to its behavior you can easily use callbacks or overrides.

Because I'm working with an older version oUF and when I tried to implement ClassPower I failed epically because I have no idea what i'm doing with oUF itself. Most of my coding involves me reverse engineering things that work to figure out how they work so I can implement them myself.

Seerah 08-09-17 06:29 PM

You should update your copy of oUF.

Galaxy119 08-09-17 09:52 PM

So I thought I had already, and upon updating I realize why I thought I did and why I hadn't.

I did previously attempt to update the oUF version being used, but upon doing so I am hit with this error that pretty much completely breaks my entire oUF layout, and I could never figure out how to fix it;
Code:

Message: Interface\AddOns\Roth_UI\units\player.lua:305: attempt to compare number with nil
Time: 08/09/17 20:50:05
Count: 1
Stack: Interface\AddOns\Roth_UI\units\player.lua:305: attempt to compare number with nilInterface\SharedXML\SharedBasicControls.lua:204: in function <Interface\SharedXML\SharedBasicControls.lua:203>
[C]: ?
Interface\AddOns\Roth_UI\units\player.lua:305: in function <Interface\AddOns\Roth_UI\units\player.lua:303>
(tail call): ?
(tail call): ?
Interface\AddOns\Roth_UI\embeds\oUF\ouf.lua:198: in function <Interface\AddOns\Roth_UI\embeds\oUF\ouf.lua:187>
(tail call): ?

Locals: errorMessage = "Interface\AddOns\Roth_UI\units\player.lua:305: attempt to compare number with nil"
DisplayMessageInternal = <function> defined @Interface\SharedXML\SharedBasicControls.lua:187
MESSAGE_TYPE_ERROR = 0


The offending function (4th line down is the one that causes the error):
Lua Code:
  1. --post update orb func (used to display lowHp on percentage)
  2.   local updateValue = function(bar, unit, cur, max)
  3.     local per = 0
  4.     if max > 0 then per = floor(cur/max*100) end
  5.     local orb = bar:GetParent()
  6.     local self = orb:GetParent()
  7.     --if orb.type == "HEALTH" and  (per <= 25 and not UnitIsDeadOrGhost(unit)) then
  8.     if orb.type == "HEALTH" and  (per <= 25 or UnitIsDeadOrGhost(unit)) then
  9.       orb.lowHP:Show()
  10.     elseif orb.type == "HEALTH" then
  11.       orb.lowHP:Hide()
  12.     end
  13.     if orb.type == "HEALTH" and UnitIsDeadOrGhost(unit) then
  14.       orb.skull:Show()
  15.     elseif orb.type == "HEALTH" then
  16.       orb.skull:Hide()
  17.     end
  18.     if db.char[orb.type].value.hideOnEmpty and (UnitIsDeadOrGhost(unit) or cur < 1) then
  19.       orb.values:Hide()
  20.     elseif db.char[orb.type].value.hideOnFull and (cur == max) then
  21.       orb.values:Hide()
  22.     elseif not orb.values:IsShown() then
  23.       orb.values:Show()
  24.     end
  25.     if orb.type == "HEALTH" then
  26.       orb.values.top:SetText(oUF.Tags.Methods["diablo:HealthOrbTop"](self.unit or "player"))
  27.       orb.values.bottom:SetText(oUF.Tags.Methods["diablo:HealthOrbBottom"](self.unit or "player"))
  28.     elseif orb.type == "POWER" then
  29.       orb.values.top:SetText(oUF.Tags.Methods["diablo:PowerOrbTop"](self.unit or "player"))
  30.       orb.values.bottom:SetText(oUF.Tags.Methods["diablo:PowerOrbBottom"](self.unit or "player"))
  31.     end
  32.     if UnitIsDeadOrGhost(unit) then
  33.       bar:SetValue(0)
  34.     end
  35.     if ns.panel:IsShown() then
  36.       ns.panel.eventHelper:SetOrbsToMax()
  37.     end
  38.   end --post update orb func (used to display lowHp on percentage)
  39.   local updateValue = function(bar, unit, cur, max)
  40.     local per = 0
  41.     if max > 0 then per = floor(cur/max*100) end
  42.     local orb = bar:GetParent()
  43.     local self = orb:GetParent()
  44.     --if orb.type == "HEALTH" and  (per <= 25 and not UnitIsDeadOrGhost(unit)) then
  45.     if orb.type == "HEALTH" and  (per <= 25 or UnitIsDeadOrGhost(unit)) then
  46.       orb.lowHP:Show()
  47.     elseif orb.type == "HEALTH" then
  48.       orb.lowHP:Hide()
  49.     end
  50.     if orb.type == "HEALTH" and UnitIsDeadOrGhost(unit) then
  51.       orb.skull:Show()
  52.     elseif orb.type == "HEALTH" then
  53.       orb.skull:Hide()
  54.     end
  55.     if db.char[orb.type].value.hideOnEmpty and (UnitIsDeadOrGhost(unit) or cur < 1) then
  56.       orb.values:Hide()
  57.     elseif db.char[orb.type].value.hideOnFull and (cur == max) then
  58.       orb.values:Hide()
  59.     elseif not orb.values:IsShown() then
  60.       orb.values:Show()
  61.     end
  62.     if orb.type == "HEALTH" then
  63.       orb.values.top:SetText(oUF.Tags.Methods["diablo:HealthOrbTop"](self.unit or "player"))
  64.       orb.values.bottom:SetText(oUF.Tags.Methods["diablo:HealthOrbBottom"](self.unit or "player"))
  65.     elseif orb.type == "POWER" then
  66.       orb.values.top:SetText(oUF.Tags.Methods["diablo:PowerOrbTop"](self.unit or "player"))
  67.       orb.values.bottom:SetText(oUF.Tags.Methods["diablo:PowerOrbBottom"](self.unit or "player"))
  68.     end
  69.     if UnitIsDeadOrGhost(unit) then
  70.       bar:SetValue(0)
  71.     end
  72.     if ns.panel:IsShown() then
  73.       ns.panel.eventHelper:SetOrbsToMax()
  74.     end
  75.   end

Galaxy119 08-09-17 09:58 PM

It also apparently somehow breaks a vast majority of the rest of my interface if I comment the offending line out, all of my unit frames seem to break, so I need to fix that line but I'm not sure what the actual problem is, since it works fine with the older version of oUF.
(statusbars and raid icons are super misplaced and some textures aren't even loaded, but no lua errors are displayed, see image, ignore actionbars, those are from bartender cuz i was testing another bug)

SDPhantom 08-09-17 11:32 PM

What happens add this at the top of the function?
Code:

max = max or 0
This will force max to be zero if nil is passed.

Galaxy119 08-09-17 11:59 PM

Quote:

Originally Posted by SDPhantom (Post 324594)
What happens add this at the top of the function?
Code:

max = max or 0
This will force max to be zero if nil is passed.

This does solve the lua error, however the visual artifacts remain (the green statusbars on the target and target's target, aswell as no unitframe textures for the target, all unit frames have all raid icons above their head simultaneously, etc. (the stuff pictured in the screenshot)
Now I'm not entierly convinced the visual issue with the statusbars is related to this error, disabling the player's frame entierly doesn't seem to affect the issue, and removing thatline while using the older version of oUF doesn't either, so now I'm super confused.

Yay for things breaking without errors!

Resike 08-11-17 04:06 PM

Quote:

Originally Posted by Galaxy119 (Post 324592)
It also apparently somehow breaks a vast majority of the rest of my interface if I comment the offending line out, all of my unit frames seem to break, so I need to fix that line but I'm not sure what the actual problem is, since it works fine with the older version of oUF.
(statusbars and raid icons are super misplaced and some textures aren't even loaded, but no lua errors are displayed, see image, ignore actionbars, those are from bartender cuz i was testing another bug)

Whats the name of this font?

Galaxy119 08-12-17 01:09 AM

Quote:

Originally Posted by Resike (Post 324604)
Whats the name of this font?

"Cracked" it's included in my UI.
Thanks for offering something useful to my problem tho.


All times are GMT -6. The time now is 12:55 PM.

vBulletin © 2020, Jelsoft Enterprises Ltd
© 2004 - 2020 MMOUI