question

Hibnu Hishath avatar image
Hibnu Hishath asked

How to reset statistics data with a predefined value?

In the game I'm working on, I wish to reset a couple of stats daily, but to be initialized with a value. For example, number of powerups left should be reset to be 200 every day.

This can also be used in ranked scenarios where a player gets a MMR of 2500 everytime the stats is reset.

If not possible in playfab console directly, what are some good solutions that the community would recommend?

Player DataLeaderboards 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

·
Sarah Zhang avatar image
Sarah Zhang answered

Could you please tell us what is your specific application scenario? What are “powerups” and “MMR” designed for? PlayFab does not natively support resetting the leaderboard with a pre-defined statistic initial value. If you use the leaderboard resetting feature, you can only reset the statistic value of every player to empty. The statistic is designed to let players participate in the ranking. Would you like to rank players according to their “powerups” or “MMR”? PlayFab leaderboard can only rank players from maximum statistic value to minimum statistic value. If every player has the 200 initial statistic value, the result of ranking would be affected greatly. Because the statistics of the front players would be the same, this may affect the accuracy when calculating rankings for players not in the front.

3 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.

Hibnu Hishath avatar image Hibnu Hishath commented ·

My idea behind this question was to deviate away from the intended design of the statistics + leaderboard system, and trying to repurpose it.

I can defenitely give an example. In my game, players get their powerup reset to 200 everyday and I do not wish to rank them based on powerups left. Powerups are instead used to play the game, and based on their smart Powerup usage a score is calculated, and this is used to ranked them.

In order to give everyone an even playing field, I thought it would be nice to reset powerups back to 200, when the "score" leaderboard is reset. Why go through the hassle of coding it to give powerups when the leaderboard is reset, instead of repurposing a built in functionality.

I'm aware that I can use virtual currencies to create this system, but there are two issue: 1) It recharges gradually, and 2) The virtual currency drop rate cannot be synced with leaderboard reset.

0 Likes 0 ·
Sarah Zhang avatar image Sarah Zhang Hibnu Hishath commented ·

If so, you can consider creating a leaderboard that has nothing to do with ranking but is used to store "PowerUp". You can refer to the following steps to set the players’ statistic initial value daily.

    1. Write a CloudScript function -- UpdatePlayerStatisticsValue.
    2. Create a new Scheduled Tasks. Configure the [Type of task] to [Run action on each player in a segment], configure the [Segment] to [All Players]. Add an action whose type is [Execute Cloud Script], chose the [UpdatePlayerStatisticsValue] as [CloudScript Fucntion]. Choose [Recurring] under the [SCHEDULE], and enter the [Cron expression] in your needs.
    handlers.UpdatePlayerStatisticsValue = function (args, context) {
    
      var updateUserStats = server.UpdatePlayerStatistics
          ({
              PlayFabId: currentPlayerId,
              Statistics: [
                  {
                      "StatisticName": "powerups",
                      "Value": 200
                  }
              ],
          });
    };
    

    Besides, this solution cannot ensure the initializations of “Powerup” and the reset of “score” leaderboard are perfectly synchronized. You can add some version verification mechanism on your own.

    0 Likes 0 ·
    Hibnu Hishath avatar image Hibnu Hishath Sarah Zhang commented ·

    I had a similar approach where I used the cloud script to update values. Upon player login, it compares the last update time (stored as player data) to the current server time and check if it's the later than today. Yeah, it's not perfectly synchronized but it works in my case. But your solution is so much better. So, thank you.

    0 Likes 0 ·

    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.