好友与群组排行榜 #
Nakama排行榜为玩家提供了可以参与的竞争性活动。随着游戏的发展,大规模的排行榜可能会让人感觉静止不变,而且玩家也很难提升排名。您可以通过以下方式解决此问题:
- 分桶排行榜
- 群组或好友排行榜
使用排行榜列表API,您可以传入用户ID列表以创建自定义排行榜视图。
以下代码示例向您展示了如何获取群组成员或用户好友的排行榜记录。
创建排行榜 #
在服务器上创建一个每周一00:00重置的排行榜。
Server
|
|
Server
|
|
Code snippet for this language Lua has not been found. Please choose another language to show equivalent examples.
获取排行榜的自定义视图 #
定义RPC的有效负载结构:
Server
|
|
Server
|
|
Code snippet for this language Lua has not been found. Please choose another language to show equivalent examples.
创建一个辅助函数,该函数将获取用户ID阵列并返回这些记录的阵列以及基于用户分数的相对排名值。
Server
|
|
Server
|
|
Code snippet for this language Lua has not been found. Please choose another language to show equivalent examples.
获取群组排行榜视图 #
现在您有了获取用户列表排行榜的通用函数,接下来需要创建一个函数来获取群组的排行榜。
为RPC定义负载结构:
Server
|
|
Server
|
|
Code snippet for this language Lua has not been found. Please choose another language to show equivalent examples.
创建一个函数,该函数将从群组中获取成员切片,然后获取其排行榜:
Server
|
|
Server
|
|
Code snippet for this language Lua has not been found. Please choose another language to show equivalent examples.
注册该函数并将其公开为可以从客户端调用的远程过程:
Server
|
|
Server
|
|
Code snippet for this language Lua has not been found. Please choose another language to show equivalent examples.
获取好友排行榜视图 #
同样,创建一个函数来获取用户好友的排行榜。
为RPC定义负载结构:
Server
|
|
Server
|
|
Code snippet for this language Lua has not been found. Please choose another language to show equivalent examples.
创建一个函数,该函数将获取用户好友切片,然后获取他们的排行榜:
Server
|
|
Server
|
|
Code snippet for this language Lua has not been found. Please choose another language to show equivalent examples.
注册该函数并将其公开为可以从客户端调用的远程过程:
Server
|
|
Server
|
|
Code snippet for this language Lua has not been found. Please choose another language to show equivalent examples.