Originally Posted by Woeler
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:
webraid = {} -- Add these lines here: webraid.Default = { OffsetX = 20, OffsetY = 75 } function getAA() d("LEaderboard refreshed") QueryRaidLeaderboardData() local raidIndex = 1 local ranking, charName, score, classId, allianceId local i = 1 while i ~= GetNumRaidLeaderboardEntries(raidIndex) do ranking, charName, score, classId, allianceId = GetRaidLeaderboardEntryInfo(raidIndex, i) SavedVariables.rank[i] = ranking SavedVariables.charname[i] = charname SavedVariables.score[i] = score SavedVariables.allianceId[i] = allianceId i = i + 1 end end --event handler for EVENT_ADD_ON_LOADED local function OnAddonLoaded(event, addonName) if addonName == "webraid" then --addonName is in general name of your addon manifext without .txt extension d("Webraid loaded") EVENT_MANAGER:UnregisterForEvent(MoveHandler, EVENT_ADD_ON_LOADED) --saved variables (in this case account wide) savedVariables = ZO_SavedVars:New("webraid", 1, nil, webraid.Default) end end EVENT_MANAGER:RegisterForEvent(MoveHandler, EVENT_ADD_ON_LOADED, OnAddonLoaded) 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()