WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   HasArtifactEquipped() not trigger on PLAYER_ENTERING_WORLD (https://www.wowinterface.com/forums/showthread.php?t=54926)

gmarco 12-15-16 12:53 AM

HasArtifactEquipped() not trigger on PLAYER_ENTERING_WORLD
 
Hi all,

I have coded to show in a LDB the artifact power instead the max level to accomplish this:
http://www.wowinterface.com/download....html#comments

Lua Code:
  1. local frame = CreateFrame("Frame")
  2. frame:RegisterEvent("PLAYER_ENTERING_WORLD")
  3. frame:RegisterEvent("PLAYER_XP_UPDATE")
  4. frame:RegisterEvent("ARTIFACT_XP_UPDATE")
  5. -- frame:RegisterEvent("PLAYER_EQUIPMENT_CHANGED")
  6.  
  7. frame:SetScript("OnEvent", function(self, event, ...)
  8.  
  9.     if UnitLevel("player") == GetMaxPlayerLevel() then
  10.    
  11.         if HasArtifactEquipped() then
  12.        
  13.             local ArtPower, ArtPointsSpent= select(5,C_ArtifactUI.GetEquippedArtifactInfo());
  14.             dataobj.text = string_format("A:%s %.1f%%", ArtPointsSpent, ArtPower/C_ArtifactUI.GetCostForPointAtRank(ArtPointsSpent)*100)
  15.    
  16.         else
  17.            
  18.             dataobj.text = "L: " .. UnitLevel("player")    
  19.  
  20.         end
  21.    
  22.     else   
  23.    
  24.         dataobj.text = string_format("L:%s %.1f%%", UnitLevel("player"), UnitXP("player")/UnitXPMax("player")*100)
  25.    
  26.     end
  27.    
  28. end)

The problem is that if I don't use the:

Lua Code:
  1. frame:RegisterEvent("PLAYER_EQUIPMENT_CHANGED")

on the first login it doesn't trigger

Lua Code:
  1. HasArtifactEquipped()

and so show only the level 110 info.

If I do /reload everything is fine ...

If I register also PLAYER_EQUIPMENT_CHANGED it works but I like to not add unnecessary events.

So the question is :) ...
Is possible that on PLAYER_ENTERING_WORLD I don't have yet the information about the equipped items ?
Is there a more specific event than PLAYER_EQUIPMENT_CHANGED that I can register to check this ?

Thanks to you all for the always precious help.

Rainrider 12-15-16 06:23 PM

PLAYER_EQUIPMENT_CHANGED is not an unnecessary event and you should use it to detect weapon swaps (which also happen when the player changes specializations and the game swaps the equipped artifact automatically).

The event at which equipped artifact data becomes initially available is UNIT_INVENTORY_CHANGED.

Tim 12-15-16 07:38 PM

The artifact data from what I can tell doesn't fire at login which is why I ended up using a timer and forcing a function call.

ie:

Code:

local events_a = CreateFrame("Frame")
events_a:RegisterEvent("ARTIFACT_XP_UPDATE")
events_a:RegisterEvent("PLAYER_ENTERING_WORLD")
events_a:RegisterEvent("UNIT_INVENTORY_CHANGED")
events_a:SetScript("OnEvent", ArtifactBar_Update)
C_Timer.After(3, ArtifactBar_Update)


Lolzen 12-16-16 06:37 AM

I'm just doing it like this.

Code:

-- get artifact power data
function afbar:ARTIFACT_XP_UPDATE()
        local hasArtifact = HasArtifactEquipped("player")
        if hasArtifact then
                local _, _, _, _, totalXP, pointsSpent = C_ArtifactUI.GetEquippedArtifactInfo()
                local numPoints, artifactXP, xpForNextPoint = MainMenuBar_GetNumArtifactTraitsPurchasableFromXP(pointsSpent, totalXP)
                afbar:SetMinMaxValues(0, xpForNextPoint)
                afbar:SetValue(artifactXP)
                afbar:SetAlpha(0.4)
                xptext:SetFormattedText("%d / %d (%.0f%%)", artifactXP, xpForNextPoint, artifactXP/xpForNextPoint*100)
        else
                afbar:SetAlpha(0)
        end
end
afbar.PLAYER_ENTERING_WORLD = afbar.ARTIFACT_XP_UPDATE
afbar.UNIT_INVENTORY_CHANGED = afbar.ARTIFACT_XP_UPDATE

So whenever you change the artifact or login/at loading screen ARTIFACT_XP_UPDATE is called regardless.

take a look here

Gethe 12-16-16 10:00 AM

There is another event ARTIFACT_UPDATE. This fires after P_E_W when the client first gets artifact info, as well as whenever your artifact changes (relics equipped, traits bought, etc), or if you receive a new artifact.

gmarco 12-16-16 11:54 AM

Thanks all for the kind replies.

As usual this forum is so helpfull.
Thanks all.

Rainrider 12-18-16 08:32 PM

@Gethe
ARTIFACT_UPDATE after PEW is caused by addons. You can't rely on it.


All times are GMT -6. The time now is 09:30 PM.

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