新しいリーダーボードサービスを使用してプレイヤーのランキングを表示する
Last updated on October 23, 2024
Overview
The AccelByte Gaming Services (AGS) Leaderboard service allows you to create a competitive atmosphere among players by displaying the leaderboard and providing information about player rankings.
Goals
- Explain how to use the SDK to retrieve a leaderboard, or retrieve a specific player's ranking.
- Provide an overview of how to display the leaderboard.
- Explain how to display the leaderboard for all time and a specific time window.
- To explain how to use leaderboards using AGS SDK.
Prerequisites
- Access to the AGS Admin Portal.
- Access to the AGS SDK for Unreal or Unity.
- Access to the AGS Leaderboard. View the API documentation for more information.
- A leaderboard configuration you want to display. You can use the guide on new cycled leaderboards to create a leaderboard configuration.
Display the leaderboard rankings
To display the leaderboard rankings, you need to get the leaderboard data using the desired leaderboard code and time frame/cycle of the leaderboard. The total number of players that you want to display from the leaderboard also can be set based on your game's needs.
You can use the following function to get the leaderboard rankings:
Get leaderboard rankings
- Unreal Engine
- Unity
const FApiClientPtr ApiClient = FMultiRegistry::GetApiClient("Client1");
ApiClient->Leaderboard.GetRankingsV3(LeaderboardCode,Offset, Limit,
THandler<FAccelByteModelsLeaderboardRankingResultV3>::CreateLambda(
[&](const FAccelByteModelsLeaderboardRankingResultV3& Response)
{
// Handle response data here
}),
FErrorHandler::CreateLambda(
[&](const int32 Code, const FString& Message)
{
// Handle error here
}));
var leaderboard = AccelByteSDK.GetClientRegistry().GetApi().GetLeaderboard();
var leaderboardCode = "leaderboardCode";
leaderboard.GetRankingsV3(leaderboardCode, result =>
{
if (result.IsError)
{
// Do something if GetRankingsV3 has an error
Debug.Log($"Error GetRankingsV3, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
return;
}
foreach(var data in result.Value.data)
{
// Do something with the ranking data
}
});
Display a specific player's ranking
You can display or highlight a specific player's ranking.
You can get a specific player's ranking using their user ID with the following function:
Get a specific player's ranking
- Unreal Engine
- Unity
const FApiClientPtr ApiClient = FMultiRegistry::GetApiClient("Client1");
ApiClient->Leaderboard.GetUserRankingV3("UserId",LeaderboardCode,
THandler<FAccelByteModelsUserRankingDataV3>::CreateLambda([&](const FAccelByteModelsUserRankingDataV3& Response)
{
// Handle response data here
}), FErrorHandler::CreateLambda([&](const int32 Code, const FString& Message)
{
// Handle error here
}));
var leaderboard = AccelByteSDK.GetClientRegistry().GetApi().GetLeaderboard();;
var userId = "userId";
var leaderboardCode = "leaderboardCode";
leaderboard.GetUserRankingV3(userId, leaderboardCode, result =>
{
if (result.IsError)
{
// Do something if GetUserRankingV3 has an error
Debug.Log($"Error GetUserRankingV3, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
return;
}
// Do something with user data
// result.Value.AllTime;
// result.Value.Cycles;
});