Event Leaderboards #

Read more about the Event Leaderboards system in Hiro here.

Get an event leaderboard #

Get a specified event leaderboard defined for the game.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
void onEventLeaderboardGet(const Hiro::EventLeaderboard& eventLeaderboard)
{
    std::cout << "Found event leaderboard: " << eventLeaderboard.name << '\n';
}

void onError(const Nakama::NError& error)
{
    std::cout << Nakama::toString(error.code) << ": " << error.message << '\n';
}

Hiro::EventLeaderboardGet request;
request.id = "leaderboard_1";

hiroClient->eventLeaderboardGet(session, request, onEventLeaderboardGet, onError);

Update event leaderboard record #

Update an event leaderboard record for a user.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
void onEventLeaderboardUpdate(const Hiro::EventLeaderboard& eventLeaderboard)
{
    std::cout << "Updated event leaderboard: " << eventLeaderboard.name << '\n';
}

void onError(const Nakama::NError& error)
{
    std::cout << Nakama::toString(error.code) << ": " << error.message << '\n';
}

Hiro::EventLeaderboardUpdate request;
request.id = "leaderboard_1";
request.score = "100";
request.subscore = "10";

hiroClient->eventLeaderboardUpdate(session, request, onEventLeaderboardUpdate, onError);

Claim event leaderboard reward #

Claim an event leaderboard reward for a user.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
void onEventLeaderboardClaim(const Hiro::EventLeaderboard& eventLeaderboard)
{
    std::cout << "Claimed event leaderboard reward: " << eventLeaderboard.name << '\n';
}

void onError(const Nakama::NError& error)
{
    std::cout << Nakama::toString(error.code) << ": " << error.message << '\n';
}

Hiro::EventLeaderboardClaim request;
request.id = "leaderboard_1";

hiroClient->eventLeaderboardClaim(session, request, onEventLeaderboardClaim, onError);

Roll a new cohort #

Roll a new cohort for the specified event leaderboard.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
void onEventLeaderboardRoll(const Hiro::EventLeaderboard& eventLeaderboard)
{
    std::cout << "New cohort rolled for event leaderboard: " << eventLeaderboard.name << '\n';
}

void onError(const Nakama::NError& error)
{
    std::cout << Nakama::toString(error.code) << ": " << error.message << '\n';
}

Hiro::EventLeaderboardRoll request;
request.id = "leaderboard_1";

hiroClient->eventLeaderboardRoll(session, request, onEventLeaderboardRoll, onError);

Debugging an event leaderboard #

You can fill an event leaderboard with dummy users and assign random scores to them for testing purposes.

This is intended for debugging use only.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
void onEventLeaderboardDebugFill(const Hiro::EventLeaderboard& eventLeaderboard)
{
    std::cout << "Filled event leaderboard with debug users: " << eventLeaderboard.name << '\n';
}

void onEventLeaderboardDebugRandomScores(const Hiro::EventLeaderboard& eventLeaderboard)
{
    std::cout << "Random scores generated for event leaderboard: " << eventLeaderboard.name << '\n';
}

void onFillError(const Nakama::NError& error)
{
    std::cout << Nakama::toString(error.code) << ": " << error.message << '\n';
}

void onScoresError(const Nakama::NError& error)
{
    std::cout << Nakama::toString(error.code) << ": " << error.message << '\n';
}

Hiro::EventLeaderboardDebugFillRequest fillRequest;
fillRequest.id = "leaderboard_1";
fillRequest.targetCount = 50; // Optional target cohort size to fill to, otherwise fill to the max cohort size.

Hiro::EventLeaderboardDebugRandomScoresRequest scoresRequest;
scoresRequest.id = "leaderboard_1";
scoresRequest.min = "1";
scoresRequest.max = "100";
scoresRequest.subscoreMin = "1";
scoresRequest.subscoreMax = "100";

// Fills cohort with debug players
hiroClient->eventLeaderboardDebugFill(session, fillRequest, onEventLeaderboardDebugFill, onFillError);

// Sets randomly generated scores between a range for other players (does not change the user's score)
hiroClient->eventLeaderboardDebugRandomScores(session, scoresRequest, onEventLeaderboardDebugRandomScores, onScoresError);