View Single Post
06/24/15, 06:42 AM   #6
XanDDemoX
AddOn Author - Click to view addons
Join Date: May 2015
Posts: 28
Originally Posted by Woeler View Post
Guess I'm just a noob, but why do I get nil from the function on line 18, seems like it can't get anything from the leaderboards, but I have no idea why.

Lua Code:
  1. webraid = {}
  2.  
  3. -- Add these lines here:
  4. webraid.Default = {
  5.     OffsetX = 20,
  6.     OffsetY = 75
  7. }
  8.    
  9.  
  10. function getAA()
  11. d("LEaderboard refreshed")
  12. QueryRaidLeaderboardData()
  13. local raidIndex = 1
  14. local ranking, charName, score, classId, allianceId
  15. local i = 1
  16. while i ~= GetNumRaidLeaderboardEntries(raidIndex) do
  17.     ranking, charName, score, classId, allianceId = GetRaidLeaderboardEntryInfo(raidIndex, i)
  18.     SavedVariables.rank[i] = ranking
  19.     SavedVariables.charname[i] = charname
  20.     SavedVariables.score[i] = score
  21.     SavedVariables.allianceId[i] = allianceId
  22.     i = i + 1
  23. end
  24. end
  25.  
  26.     --event handler for EVENT_ADD_ON_LOADED
  27.     local function OnAddonLoaded(event, addonName)
  28.         if addonName == "webraid" then --addonName is in general name of your addon manifext without .txt extension
  29.             d("Webraid loaded")
  30.             EVENT_MANAGER:UnregisterForEvent(MoveHandler, EVENT_ADD_ON_LOADED)
  31.      
  32.             --saved variables (in this case account wide)
  33.             savedVariables = ZO_SavedVars:New("webraid", 1, nil, webraid.Default)
  34.      
  35.  
  36.         end
  37.     end
  38.         EVENT_MANAGER:RegisterForEvent(MoveHandler, EVENT_ADD_ON_LOADED, OnAddonLoaded)
  39.         EVENT_MANAGER:RegisterForEvent(RaidsUpdated, EVENT_RAID_LEADERBOARD_DATA_CHANGED, getAA)
QueryRaidLeaderboardData() works in the background so theres may not be data immediately after calling it, there are a couple of events for leaderboard data changes.

  • EVENT_RAID_LEADERBOARD_DATA_CHANGED (integer eventCode)
  • EVENT_RAID_LEADERBOARD_PLAYER_DATA_CHANGED (integer eventCode)

I think its EVENT_RAID_LEADERBOARD_DATA_CHANGED that will be fired after calling QueryRaidLeaderboardData().

Also your getAA function only checks attempts to get data from leaderboard 1 and leaderboard data only has the top 100 entries

Once you've queried the leaderboard and the data is available you can use the below code to get it

Code:
local function GetRaidLeaderboardEntries(index)
	
	local entries = {}
	
	local ranking, charName, score, classId, allianceId 
	
	local entry
	
	for i = 1, GetNumRaidLeaderboardEntries(index) do
	
		ranking, charName, score, classId, allianceId = GetRaidLeaderboardEntryInfo(index, i)
	
		entry = {
			
			ranking = ranking,
			charName=charName,
			score = score, 
			classId = classId, 
			allianceId = allianceId 
		
		}
		
		table.insert(entries,entry)
		
	end

	return entries
end


local function GetRaidLeaderboards()
    local leaderboards = {}

    for index =1, GetNumRaidLeaderboards() do
         leaderboards[index] = GetLeaderboardEntries(index)
    end

   return leaderboards
end

-- usage 

local leaderboards = GetRaidLeaderboards()
  Reply With Quote