Event Leaderboards
Read more about the Event Leaderboards system in Hiro here.
Initialize the event leaderboards system #
The event leaderboards system system relies on the Nakama System and an ILogger, both must be passed in as dependencies via the constructor.
| |
Event leaderboard response #
The IEventLeaderboard response object includes the following properties:
| Property | Type | Description |
|---|---|---|
BestRank | long | Best rank achieved across cohorts this phase. |
CanClaim | bool | Whether the player can claim their reward. |
CanRoll | bool | Whether the player can roll into a new cohort right now. |
CanRollWithClaim | bool | Whether the player can claim and roll in a single call. |
CanUpdate | bool | Whether the player can submit scores to their current cohort. |
Count | long | Number of players currently in the cohort. |
IsActive | bool | Whether the event leaderboard’s current phase is live. |
MaxCount | long | Maximum number of players the cohort can hold. |
MaxRolls | long | Maximum rolls allowed per phase. |
RerollCountFreeze | bool | Whether the next roll is “free” (does not count against MaxRolls). |
RollCooldownSec | long | Effective cooldown between rolls, in seconds. |
Rolls | long | Number of rolls the player has used this phase. |
ScoreTarget | long | Target score for cohort completion. |
ScoreTargetPlayers | long | How many players must reach the target. |
Tier | int | The player’s current tier (0-indexed). |
TierDeltaPerPhase | long | Tier adjustment applied when a phase expires. |
ClaimTimeSec | long | Unix timestamp when the player claimed their reward (0 if unclaimed). |
EndTimeSec | long | Unix timestamp when the player’s current cohort is scheduled to end. |
ExpiryTimeSec | long | Unix timestamp when the player’s phase pointer expires. |
RollCooldownEndsSec | long | When the current cooldown expires (UNIX timestamp). |
ScoreTimeLimitEndsSec | long | When this player’s time limit expires (UNIX timestamp). |
ScoreTimeLimitSec | long | Per-player time limit from roll time, in seconds. |
StartTimeSec | long | Unix timestamp when the player’s current cohort started. |
Score entry properties #
IEventLeaderboard.Scores is a collection of IEventLeaderboardScore objects, one per player in the cohort.
| Property | Type | Description |
|---|---|---|
Id | string | User ID of the player. |
Username | string | Username of the player. |
DisplayName | string | Display name of the player. |
AvatarUrl | string | Avatar URL of the player. |
Rank | long | The player’s rank within the cohort. 0 means the player hasn’t submitted a score yet. |
Score | long | The player’s primary score. |
Subscore | long | The player’s secondary score. |
NumScores | long | Number of score submissions by this player. |
TierDelta | int | Predicted tier change if the current phase ended now. Positive: promotion (value = tiers gained) Negative: demotion (value = tiers lost) 0: no change |
Metadata | string | Custom metadata attached to this score entry. |
CreateTimeSec | long | Unix timestamp when the player joined this cohort. |
UpdateTimeSec | long | Unix timestamp of the player’s last score submission. |
Use TierDelta to show players whether they’re on track for promotion, demotion, or no change, while the event is still live.
| |
Determine event leaderboard state #
When the server returns an Event Leaderboard, its current state is represented by a combination of boolean properties. Check if the player can claim rewards and roll into a new cohort simultaneously by reading the CanRollWithClaim property in the response.
| IsActive | CanClaim | CanRoll | Description |
|---|---|---|---|
FALSE | FALSE | FALSE | Visible, but inactive. No actions are possible. |
FALSE | TRUE | FALSE | Visible, but inactive. A reward from a previous phase can be claimed. |
TRUE | FALSE | FALSE | Active, a valid cohort exists and the player can submit scores (CanUpdate is true). |
TRUE | FALSE | TRUE | Active, need to roll to get a cohort. |
TRUE | TRUE | FALSE | Active, a completed cohort exists with an unclaimed reward. The player has no remaining rolls after claiming, or is waiting for a roll cooldown to expire. |
List event leaderboards #
You can list all the available event leaderboards to the player by passing null as an argument.
| |
You can filter down the event leaderboards to only include those that belong to at least one of the given categories.
| |
By default, the response doesn’t include the scores of the event leaderboards. To have the response returning with the scores, set the boolean with_score on the request to true.
| |
Get an individual event leaderboard #
You can get an individual event leaderboard, including it’s records and information on it’s rewards.
| |
Submit an event leaderboard score #
You can submit an event leaderboard score for the user. Check CanUpdate on the response to determine whether the player can still submit scores to their current cohort.
| |
Claim rewards #
You can claim event leaderboard rewards for the user.
| |
Check CanClaim to determine whether the player has a reward available. The server sets CanClaim to false within the claim request, so the IEventLeaderboard returned by ClaimEventLeaderboardAsync already reflects the claimed state. Await the call and use the returned object for any follow-up logic.
ClaimEventLeaderboardAsync doesn’t update the local event leaderboard state used by offline support. When the client is offline or the request fails with a transient error, UpdateEventLeaderboardAsync returns that cached state, which can still show CanClaim as true after a claim.Roll into a cohort #
You can roll (or re-roll) the user into a cohort for a specific event leaderboard. The first roll in a phase places the player into a cohort for the first time. Subsequent rolls within the same phase are re-rolls, where the player leaves a completed cohort and joins a new one with fresh opponents.
| |
After rolling, eventLeaderboard.Count and eventLeaderboard.MaxCount show how many players are currently in the cohort and the maximum it can hold.
| |
To claim the current reward and roll into a new cohort in a single call, pass claimReward: true. This is the recommended approach for re-rolling as it avoids an extra round-trip.
| |
Multi-roll game loop #
For score-based events where players can compete in multiple cohorts within a single phase, the typical flow looks like this:
| |
Debug an event leaderboard #
You can fill an event leaderboard with dummy users and assign random scores to them for testing purposes.
| |
