Hi, I can’t find anything about group leaderboard and group tournaments (submit score api, and list top leaderboard scores). Is there any resource about that?
Hey @SinaZK.
A feature of both leaderboard and tournaments which you may have noticed is that the score submission (leaderboard record) is tied to an owner ID rather than a user ID. This design allows us to support leaderboard entries who’s owner can be the group ID (for a guild leaderboard) or really any other identifier. The same is available with tournaments. It gives a flexible way to support the feature you want.
I would build your guild leaderboard like so:
- Use an after hook on group create to create the leaderboard with the same ID as the group and mark it authoritative so game clients cannot submit scores directly.
- Whenever you have a score that should be submitted to the guild leaderboard execute that logic as part of an RPC function or a new RPC.
- Handle whatever input checks to prevent cheaters, etc.
- Display the leaderboard for the guild with the usual API in the client sdks.
Hope this helps.
Thanks, I will use this method for my group leaderboards. I got another design question, In leaderboard record table, Why nakama designed to store username but not the display name? Leaderboard list need user display names to show them in game. Now i’m using a custom rpc that joins the leaderboard record list with users table and fetch the users display names. And i know it has heavy cost when my players count goes above 1Mllion.
@SinaZK We store the username because its a unique index and used to generate friend or filtered leaderboard views based on users. The display_name
is non-unique but easy to mirror into the leaderboard record metadata when the record is written. This balance keeps the storage costs low but gives you somewhere to store that info if its important for display purposes in your game.
Now i’m using a custom rpc that joins the leaderboard record list with users table and fetch the users display names. And i know it has heavy cost when my players count goes above 1Mllion.
Yep this will have a huge negative impact on performance in your game. I recommend this approach is changed to follow my advice above.
Ok I got your point, But what was the problem with the owner Id field? It is unique too. Why not using owner Id instead of username?
@SinaZK I don’t follow. What problem do you have now? A leaderboard record has both an owner ID and a username field. You should have no problem with the design I mentioned earlier in the thread.
I got what you said and i don’t have any problem with the design you mentioned. I just got a question about philosophy of having username field in leaderboard record when there is owner id.
@SinaZK I see. Most of the APIs in Nakama are designed with efficiency in mind but also for practical game design that works at scale. It’s very common to use user IDs and usernames across the game server code because its efficient and flexible. Friend leaderboards, player leagues, tournaments, cohort leaderboards, etc all tend to be player orientated so the username field is useful to have by default.
Thank you for you answer.