Friend and Group Leaderboards

Nakama Leaderboards give players a competitive activity to engage around. As a game grows, massive leaderboards can feel static and more challenging for players to climb the ranks. You can address this with:

Using the leaderboard list API you can pass in a list of user IDs to create a custom leaderboard view.

The following code samples show you how to get leaderboard records for a group’s members or user’s friends.

Creating the leaderboard #

Create a leaderboard on the server that resets every Monday at 00:00.

Code snippet for this language Lua has not been found. Please choose another language to show equivalent examples.

Getting a custom view of the leaderboard #

Define the payload structure for the RPC:

Code snippet for this language Lua has not been found. Please choose another language to show equivalent examples.

Create a helper function that will take an array of user IDs and return an array of those records along with the relative Rank value based on user scores.

Code snippet for this language Lua has not been found. Please choose another language to show equivalent examples.

Getting the group leaderboard view #

Now that you have a general function to get a leaderboard for a list of users, create a function to get a leaderboard for a group.

Define a payload structure for the RPC:

Code snippet for this language Lua has not been found. Please choose another language to show equivalent examples.

Create a function that will get a slice of members from a group and then get the leaderboard for them:

Code snippet for this language Lua has not been found. Please choose another language to show equivalent examples.

Register the function and expose it as a remote procedure that can be called from the client:

Code snippet for this language Lua has not been found. Please choose another language to show equivalent examples.

Getting the friend leaderboard view #

Similarly, create a function to get a leaderboard for a user’s friends.

Define a payload structure for the RPC:

Code snippet for this language Lua has not been found. Please choose another language to show equivalent examples.

Create a function that will get a slice of a user’s friends and then get the leaderboard for them:

Code snippet for this language Lua has not been found. Please choose another language to show equivalent examples.

Register the function and expose it as a remote procedure that can be called from the client:

Code snippet for this language Lua has not been found. Please choose another language to show equivalent examples.