question

Kim Strasser avatar image
Kim Strasser asked

How can I notify the players if they have won a prize on a leaderboard?

I have a leaderboard and I use this prize table to create the rewards. The players get rewards depending on there leaderboard rank:

I want to notify the player if he/she has won something. In addition, I want to write in this notification what they have won. In my example, I want to write that the player(rank 1) has won 1 ItemTitaniumSword and 1000 GO. How can I do that? How can I find out what the player has won and write it in the notification?

I want that the player gets the notification and the rewards more or less at the same time in my game. I don't want that the notification shows up much later in my game than the rewards.

Are the rewards always automatically granted after a leaderboard reset or is it possible to only grant the rewards to the player after the player clicked on a certain button in my game?

Leaderboards and Statistics
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Seth Du avatar image
Seth Du answered

The RESTful nature of PlayFab determines that, for most cases, data updates are not immediate to the client side because RESTful API is stateless.A rest of Leaderboard without any active actions you have defined, clients cannot sync with server immediately. A common sample of your scenario is [Player receives push notification] -> [player click push notification to open the game, and trigger an inventory updates] -> [player sees the new items].

PlayFab is working on in-game instant message features, though we cannot tell the ETA. Still, There are some work arounds we recommend.

>>write in this notification what they have won

  • 1.Directly add a sending Email template action in each rank actions and define different templates that contains rewards information previously.
  • 2.For each rank, only execute a cloud script functions and pre-define Rewards data in Cloud Script. After items are granted, call SendPushNotification server API. A similar alternative is to define a Rule to monitor the PlayStream custom Events to send push notification and call WritePlayerEvent API call after items are granted.

>> only grant the rewards to the player after the player clicked on a certain button in my game

Yes, you can. First, there always should be a place that can store reward sheet, for example, in Title Data, Cloud Script. Then every reset of leaderboard, the Prize Table doesn’t grant anything, and only update a flag data for the player, for example, run a Cloud Script function to update Player Internal/Read-only Data that store the Prize Rank of this player. Meanwhile, when the player click the “Button” to claim the rewards, it also runs a Cloud Script to check the value of this “Flag” data and grant the prize according to the reward sheet. At last, reset the flag.

4 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Kim Strasser avatar image Kim Strasser commented ·

I want to store the players rank in Player Internal Data but I don't know how to get the players rank in my cloud script function.

My cloud script function fails. I have this event in Game Manager-->Data:

player_triggered_action_executed_cloudscript FAILED: CreateLeaderboardRankInternalData() (revision 296)

"Error": {
      "Message": "JavascriptException",
      "Error": "JavascriptException",
      "StackTrace": "TypeError: Cannot read property 'Rank' of null\n    at handlers.CreateLeaderboardRankInternalData (BFD0A-main.js:22:31)\n    at Object.invokeFunction (Script:116:33)"
    },

How can I get the players rank in CreateLeaderboardRankInternalData?

Is it possible to get other things like the type of the rewards and the rewards Item and amount/quantity in my cloud script function?

handlers.CreateLeaderboardRankInternalData = function (args, context)
{
   var resultdata = server.GetUserInternalData({PlayFabId: currentPlayerId, Keys: "LeaderboardRank"});
   var leaderboardrank = args.Rank;
   //...
}
0 Likes 0 ·
Seth Du avatar image Seth Du ♦ Kim Strasser commented ·

Args doesn't contain any variables, when it is triggered by Prize Table. You need to call GetLeaderboardAroundUser in Cloud Script to get the rank.

0 Likes 0 ·
Kim Strasser avatar image Kim Strasser Seth Du ♦ commented ·

How can I find out which leaderboard(name and version?) is the one that triggered CreateLeaderboardRankInternalData?

For example, I have two different leaderboards "Leaderboard_Level1" and "Leaderboard_Level2". How can I know which of those leaderboards triggered CreateLeaderboardRankInternalData? Because I need the name and version of the leaderboard in GetLeaderboardAroundUser.

0 Likes 0 ·
Show more comments

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.