Thread Tools Display Modes
06/23/15, 04:13 PM   #1
Woeler
 
Woeler's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2014
Posts: 40
function to get leaderboard scores?

Hello all,

I can't find a function to get scores from the trials leaderboards. is there one? Or is there anything like it? I would really like to know because I certainly can't find it.

Thanks.
  Reply With Quote
06/23/15, 11:36 PM   #2
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,578
I think you are looking for these:

Code:
     GetRaidName(integer raidId)
        Returns: string name 

    QueryRaidLeaderboardData() 

    GetNumRaidLeaderboards()
        Returns: integer count 

    GetRaidLeaderboardInfo(integer raidIndex)
        Returns: string name, boolean isWeekly, integer raidId, integer RaidCategory category 

    GetRaidLeaderboardLocalPlayerInfo(integer raidIndex)
        Returns: integer rank, integer bestScore 

    GetNumRaidLeaderboardEntries(integer raidIndex)
        Returns: integer count 

    GetRaidLeaderboardEntryInfo(integer raidIndex, integer entryIndex)
        Returns: integer ranking, string charName, integer time, integer classId, integer allianceId
  Reply With Quote
06/24/15, 03:50 AM   #3
Woeler
 
Woeler's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2014
Posts: 40
Ah thanks, but I'm just gonne throw it out here. I have no clue how to use these functions. Whatever raidindex I use, I always get nil values back. Even when testing with 0, 1 or 2(which should indicate a raid I think?).

I just want to save 4 things in the saved variables. I want to save for each trialleaderboard and each spot on that board:
-ranking
-charname
-score
-alliance

So that in the end I have the entire leaderboard in my SV.

Can anyone help me? I'm pretty sure it's not a big piece of code, but I simple can't get it to work with loops.

Last edited by Woeler : 06/24/15 at 03:54 AM.
  Reply With Quote
06/24/15, 04:04 AM   #4
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,578
Haven't used that api myself yet, but I think you need to call QueryRaidLeaderboardData first and can only do stuff after you receive the related event.
Lua Code:
  1. EVENT_MANAGER:RegisterForEvent("MyEventHandlerNamespace", EVENT_RAID_LEADERBOARD_DATA_CHANGED, function()
  2. -- do something here
  3. end)
  4. QueryRaidLeaderboardData()
  Reply With Quote
06/24/15, 04:28 AM   #5
Woeler
 
Woeler's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2014
Posts: 40
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)
  Reply With Quote
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
06/24/15, 10:47 AM   #7
Woeler
 
Woeler's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2014
Posts: 40
All please see http://www.esoui.com/forums/showthread.php?t=4827

If anyone would be willing to create this small addon, would be much appreciated.
  Reply With Quote

ESOUI » Developer Discussions » General Authoring Discussion » function to get leaderboard scores?


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