WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   AddOn Help/Support (https://www.wowinterface.com/forums/forumdisplay.php?f=3)
-   -   Character Stats not loading on PLAYER_LOGIN (https://www.wowinterface.com/forums/showthread.php?t=56109)

Seethe 03-18-18 09:28 AM

Character Stats not loading on PLAYER_LOGIN
 
Hello, I am new and noob to WoW addons development.
As an exercise I am trying to do a little panel with player stats in it, but actually I am failing to do so :D
With the following code, when I enter into the game my stat is 0.000.
Any help? Thanks in advance! ;)

Lua Code:
  1. function round(number, decimals)
  2.         return (("%%.%df"):format(decimals)):format(number)
  3.     end
  4.  
  5.     local crit = round(GetCritChance(), 3)
  6.  
  7.     local c = CreateFrame("Frame", "myframe", UIParent)
  8.  
  9.     c:SetWidth(400)
  10.     c:SetHeight(200)
  11.     c:SetPoint("TOP", UIParent, "CENTER")
  12.     c:SetFrameStrata("MEDIUM")
  13.  
  14.     c.tex = c:CreateTexture()
  15.     c.tex:SetAllPoints(c)
  16.     c.tex:SetColorTexture( unpack(cfg.color))
  17.  
  18.     c.text = c:CreateFontString(nil,"ARTWORK","GameFontNormal")
  19.     c.text:SetPoint("TOPLEFT",8,-10)
  20.     c.text:SetTextColor(classColor.r, classColor.g, classColor.b)
  21.  
  22.     c:RegisterEvent("PLAYER_LOGIN")
  23.  
  24.     c:SetScript("OnEvent", function()
  25.        c.text:SetText( "Crit: " .. crit )
  26.     end)

Kanegasi 03-18-18 10:13 AM

Stats may not be available right at login. Plus, they could change with procs and other events during play. Use the event COMBAT_RATING_UPDATE instead. This could get spammy in a group, so you may have to check the unit return.

Lua Code:
  1. c:SetScript("OnEvent", function(self,event,unit)
  2.     if unit=="player" then
  3.         crit = round(GetCritChance(), 3)
  4.         c.text:SetText( "Crit: " .. crit )
  5.     end
  6. end)

I just noticed that you're getting crit only once, which explains the 0 since you're getting crit before you even login. The OnEvent is just setting the same number over and over again if you use the event I suggested. I put another crit= inside the OnEvent for you. You can even skip using a crit variable and just put the round() call in directly.

Lua Code:
  1. c:SetScript("OnEvent", function(self,event,unit)
  2.     if unit=="player" then
  3.         c.text:SetText( "Crit: " .. round(GetCritChance(), 3) )
  4.     end
  5. end)

Seethe 03-18-18 11:17 AM

Thanks! That's working exactly how I want!
Much appreciated ;)

Kakjens 03-19-18 12:55 PM

Where did you get information about COMBAT_RATING_UPDATE' s variables?

Tim 03-19-18 06:44 PM

I really don't think there's any variables for it considering there's no payload table. Look at other events and there's payload tables including variables, so yeah.. Just do what the above code does and watch for the event and then poll the stat(s) you're desiring.

Kanegasi 03-19-18 09:38 PM

Quote:

Originally Posted by Kakjens (Post 327294)
Where did you get information about COMBAT_RATING_UPDATE' s variables?

I assumed the event had a unit return looking at the function that updates your character stats.

10leej 03-20-18 07:05 AM

Quote:

Originally Posted by Kanegasi (Post 327286)
Stats may not be available right at login. Plus, they could change with procs and other events during play. Use the event COMBAT_RATING_UPDATE instead. This could get spammy in a group, so you may have to check the unit return.

Lua Code:
  1. c:SetScript("OnEvent", function(self,event,unit)
  2.     if unit=="player" then
  3.         crit = round(GetCritChance(), 3)
  4.         c.text:SetText( "Crit: " .. crit )
  5.     end
  6. end)

I just noticed that you're getting crit only once, which explains the 0 since you're getting crit before you even login. The OnEvent is just setting the same number over and over again if you use the event I suggested. I put another crit= inside the OnEvent for you. You can even skip using a crit variable and just put the round() call in directly.

Lua Code:
  1. c:SetScript("OnEvent", function(self,event,unit)
  2.     if unit=="player" then
  3.         c.text:SetText( "Crit: " .. round(GetCritChance(), 3) )
  4.     end
  5. end)

I think OP would want to check PLAYER_ENTERING_WORLD as well if he wants the stats available right away. I'm probably wrong but I believe COMBAT_RATING_UPDATE only fires in combat.

Ammako 03-20-18 07:47 AM

Quote:

Originally Posted by 10leej (Post 327301)
I think OP would want to check PLAYER_ENTERING_WORLD as well if he wants the stats available right away. I'm probably wrong but I believe COMBAT_RATING_UPDATE only fires in combat.

What about when you take off or equip gear? It has to keep the stats on character sheet updated, even if you're not in combat.
I don't think the COMBAT here refers to being in combat, rather, it refers to combat stats (ratings, percentages.)

Otherwise if it's not that one, there has to be one, anyway.


All times are GMT -6. The time now is 05:32 PM.

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