Displaying a specific player ranking in the new Leaderboard service
Last updated on December 6, 2023
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:
- Unreal Engine
- Unity
Get leaderboard rankings (Unreal SDK)
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
}));
Get leaderboard rankings (Unity SDK)
var leaderboard = AccelBytePlugin.GetLeaderboard();
var leaderboardCode = “Leaderboard Code”
leaderboard.GetRankingsV3(leaderboardCode, GetRankingsHandler);
--------------------------------------------------------------------
public void GetRankingsHandler(Result<LeaderboardRankingResult> result)
{
if(result.IsError)
{
// handle error here
return;
}
foreach(var data in getResult.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:
- Unreal Engine
- Unity
Get a specific player's ranking (Unreal SDK)
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
}));
Get a specific player's ranking (Unity SDK)
var leaderboard = AccelBytePlugin.GetLeaderboard();
var leaderboardId = this.leaderboardCodes.First().Value;
var userId = “UserId”;
Result<UserRankingDataV3> getResult = null;
leaderboard.GetUserRankingV3(this.userId, GetUserRankingHandler);
public void GetUserRankingHandler(Result<UserRankingDataV3> result)
{
if(result.IsError)
{
// handle error here
return;
}
// handle result data
// result.AllTime
// result.Cycles
// result.UserId
}