类型 事件 版本 版本 2024.3703 关键词 steam, steamworks, 排行榜, leaderboardEntries 另请参阅 steamworks.requestLeaderboardEntries() steamworks.*
提供从排行榜请求的条目数组的事件。
此事件只能由已传递给 steamworks.requestLeaderboardEntries() 函数的 函数 监听器接收。
local steamworks = require( "plugin.steamworks" ) -- Called by the "steamworks.requestLeaderboardEntries()" function with the result local function onReceivedLeaderboardEntries( event ) if ( event.isError ) then -- Request failed; typically happens when there is no Internet access print( "Failed to fetch leaderboard entries." ) else -- Print the received leaderboard entries to the log for index = 1, #event.entries do -- Get the next leaderboard entry local nextEntry = event.entries[index] -- Fetch the user's nickname via their steam ID local userName = "Unknown" local userInfo = steamworks.getUserInfo( nextEntry.userSteamId ) if ( userInfo ) then userName = userInfo.nickname end -- Print the leaderboard entry to the log local message = string.format( "Rank(%d) Name(%s) Score(%d)", nextEntry.globalRank, userName, nextEntry.score ) print( message ) end end end -- Fetch the top 10 players on the leaderboard -- Requires an active Internet connection to succeed -- Will provide the requested result to the given listener function local requestSettings = { leaderboardName = "My Leaderboard Name", playerScope = "Global", startIndex = 1, endIndex = 10, listener = onReceivedLeaderboardEntries } steamworks.requestLeaderboardEntries( requestSettings )