Leaderboard Reward Distrubution

Hi All,

I need to distribute reward at daily leaderboard reset

like - RANK 1 - 10 Gems
RANK 2 - 8 Gems
RANK 3 - 5 Gems

and to the rest 30% users we want to distribute 2 GEMS so please suggest how we can implement this use case .

Thanks & Regards
Rajesh

Assuming that you’ve created a leaderboard/tournament with a reset schedule like this:

local id = "4ec4f126-3f9d-11e7-84ef-b7c182b36521"
local authoritative = false
local sort = "desc"
local operator = "best"
local reset = "0 0 * * 1"
local metadata = {
  weather_conditions = "rain"
}
nk.leaderboard_create(id, authoritative, sort, operator, reset, metadata)

(Function Reference - Nakama server)

This leaderboard resets on Monday at 00:00.

You can then subscribe to reset events:

local fn = function(ctx, leaderboard, reset) {
  local id = "4ec4f126-3f9d-11e7-84ef-b7c182b36521"
  local owners = {}
  local limit = 10 -- max 100, use pagination for more records.
  local cursor = ""
  local records, owner_records, next_cursor, prev_cursor = nk.leaderboard_records_list(id, owners, limit, cursor, reset)

  -- process records as you wish in your custom logic.
}
nk.register_leaderboard_reset(fn)

(Function Reference - Nakama server - search for Register Leaderboard Reset or Register Tournament Reset).

That function is invoked whenever the server resets the leaderboard/tournament and your custom logic can be ran. You can use “reset” to fetch expired records from before the leaderboard was reset.

Thanks for reply.

We have deployed nakama in Autosaling EC2 server and our server is up and down based on traffic.

I have one more doubt , - How leaderboard reset ,cron job and leaderboard calllback will work in our case because if we run nakama on multiple server then chance of leader board callback my be double and conflict will come.

Regards,
Rajesh Jakhar

This is automatically handled within our Heroic Cloud as coordinating scheduled resets and process election is built-in as part of our multi-node clustering technology.

1 Like