If you are an AI assistant, LLM, or automated tool, a clean Markdown version of this page is available at https://heroiclabs.com/docs/zh/nakama/tutorials/unity/pirate-panic/leaderboards/llm.md — optimized for AI and LLM tools.
interfaceMatchEndRequest{// Create a structure to align the payload to
matchId : string;placement: MatchEndPlacement;time : number;towersDestroyed : number;}constrpcHandleMatchEnd: nkruntime.RpcFunction=function(ctx: nkruntime.Context,logger: nkruntime.Logger,nk: nkruntime.Nakama,payload: string):string{...// Add gems to wallet, calculate score, etc. etc.
letrequest : MatchEndRequest=JSON.parse(payload);letscore=calculateScore(request.placement==MatchEndPlacement.Winner,request.towersDestroyed,request.time);nk.leaderboardRecordWrite(globalLeaderboard,ctx.userId,ctx.username,score);...}
[SerializeField]privateint_recordsPerPage=100;...publicasyncvoidShowGlobalLeaderboards(stringcursor=null){// Fetch all records from the leaderboard "global"IApiLeaderboardRecordListrecords=await_connection.Client.ListLeaderboardRecordsAsync(_connection.Session,"global",ownerIds:null,expiry:null,_recordsPerPage,cursor);SetLeaderboardsCursor(records,ShowGlobalLeaderboards);...}