Thread Tools Display Modes
12-15-16, 12:53 AM   #1
gmarco
An Onyxian Warder
 
gmarco's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 362
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.
__________________
This is Unix-Land. In quiet nights, you can hear the Windows machines reboot.
  Reply With Quote
12-15-16, 06:23 PM   #2
Rainrider
A Firelord
AddOn Author - Click to view addons
Join Date: Nov 2008
Posts: 454
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.
  Reply With Quote
12-15-16, 07:38 PM   #3
Tim
A Rage Talon Dragon Guard
 
Tim's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2008
Posts: 308
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)
  Reply With Quote
12-16-16, 06:37 AM   #4
Lolzen
An Aku'mai Servant
 
Lolzen's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2008
Posts: 36
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
  Reply With Quote
12-16-16, 10:00 AM   #5
Gethe
RealUI Developer
 
Gethe's Avatar
Premium Member
Featured
Join Date: Sep 2008
Posts: 942
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.
__________________
Knowledge = Power; Be OP

  Reply With Quote
12-16-16, 11:54 AM   #6
gmarco
An Onyxian Warder
 
gmarco's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 362
Thanks all for the kind replies.

As usual this forum is so helpfull.
Thanks all.
__________________
This is Unix-Land. In quiet nights, you can hear the Windows machines reboot.
  Reply With Quote
12-18-16, 08:32 PM   #7
Rainrider
A Firelord
AddOn Author - Click to view addons
Join Date: Nov 2008
Posts: 454
@Gethe
ARTIFACT_UPDATE after PEW is caused by addons. You can't rely on it.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » HasArtifactEquipped() not trigger on PLAYER_ENTERING_WORLD

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