question

Joe Hopkins avatar image
Joe Hopkins asked

How to implement Clash Royal style season stats using PlayFab's Leaderboard Prize Table.

We would like to implement seasons like Clash Royal....

When a new season starts anyone with over 3000 trophies should be set back down to 3000. But for each trophy taken away, they receive a permanent "Legend" trophy that can be seen in their profile.

So for any player with greater than 3000 trophies: NUM_TROPHIES - 3000 should be added to their NUM_LEGEND_TROPHIES stat. And then their NUM_TROPHIES be set to 3000.

How can we accomplish this using PlayFab? Thanks!

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

·
brendan avatar image
brendan answered

The Prize Table functionality performs custom actions for up to N players, based on their position in the leaderboard (where N is based on your service tier). Since you'd want this to be for a potentially unlimited number of players, your best bet would be to use Cloud Script. You could do this one of two ways:

1. The simplest would be to have the player call a script that evaluates their trophies when they see that they're in a new season. That would make sure that the player is always up-to-date with the current season, since if they sign in right after the season starts, they'll make the call and get their values updated. Now, if you're showing players the trophies in a leaderboard, that would mean that players who don't sign in for a long time would have a previous season's trophy total showing, and they wouldn't have their legend trophies score up-to-date until they sign in - not sure if those limitations would work for you.

2. Alternately, you could create a segment for all users with > 3000 trophies, and run a scheduled task at the end of each season which walks through that segment and updates their scores appropriately. In that case, all players would get updated, but there would be a chance that a player could sign in right after you start the new season, but before their scores have been updated (the number of players in that segment will determine how long it takes to complete the process).

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

Joe Hopkins avatar image Joe Hopkins commented ·

Thanks Brendan! Can the seasons be setup using the PlayFab dashboard? The only documentation I found was below, but it requires some complex cloud scripting:

https://api.playfab.com/docs/tutorials/landing-tournaments/using-resettable-statistics-and-leaderboards

0 Likes 0 ·
brendan avatar image brendan Joe Hopkins commented ·

You can set the reset period on a leaderboard in the dashboard, but from your description you have more complex, title-specific needs around your seasons (evaluation of the trophies, in particular).

0 Likes 0 ·
Joe Hopkins avatar image Joe Hopkins commented ·

I think option 2 would be the best. Is it possible to automatically run a scheduled task at the end of each season? Also, can we have automatically reseting leaderboards in the free version of PlayFab?

0 Likes 0 ·
brendan avatar image brendan Joe Hopkins commented ·

Yes, the free tier includes the ability to run one scheduled task at a time, and a small number of statistics (leaderboards) which can be set up as resetting leaderboards. Please do bear in mind though, that the tasks cannot run at infinite speed - they process one player at a time, so if you have a large number of players, it's very likely that some will sign in and play the game after the season ends, but before their account has been processed for their trophy count.

0 Likes 0 ·
Joe Hopkins avatar image Joe Hopkins commented ·

For 5000 users in a segment are we talking minutes or hours?

0 Likes 0 ·
brendan avatar image brendan Joe Hopkins commented ·

That depends upon the complexity of the task being run. If it's running a Cloud Script, the script's running time would be how you would calculate the time required (players are processed one at a time, with the max rate in the free tier being 10 players per second).

0 Likes 0 ·
Joe Hopkins avatar image Joe Hopkins commented ·

Also, is there a way for the client to know how much time until the scheduled task will run. Kind of like how a client knows how long until the season is over.

0 Likes 0 ·
brendan avatar image brendan Joe Hopkins commented ·

You could store information in Title Data on upcoming tasks, but if you mean knowing how long until the task has completed for each user then no, there's no simple way to calculate that.

0 Likes 0 ·
Joe Hopkins avatar image Joe Hopkins commented ·

Hey Brendan, I have another idea that I think is simple but effective:

1. I setup NUM_TROPHIES as a leaderboard stat that resets weekly.

2. Whenever a player sets the NUM_TROPHIES stat, they will also set another stat NUM_TROPHIES_HIDDEN with the same value.

3. In the NUM_TROPHIES leaderboard display I will show a timer (using the PlayFab API) that says how much time is left in the season.

4. When the leaderboard gets reset (season ends), once the player logs in the client will set NUM_TROPHIES to the NUM_TROPHIES_HIDDEN value. However if NUM_TROPHIES_HIDDEN is higher than 3000, anything above 3000 will be added to their NUM_LEGEND_TROPHIES and NUM_TROPHIES will be set to 3000.

5. If the user clicks to see the leaderboards, they will see it for the new season. But if they click a button for to see the previous season, they can see the previous season NUM_TROPHIES correct?

What do you think of this idea? The advantage over option 1 is that players who have not logged in will not take up the leaderboard spots in a new season.

Is there documentation on how to show a leaderboard of the previous season (before the reset)?

Thanks for all the help!

0 Likes 0 ·
brendan avatar image brendan Joe Hopkins commented ·

So if I understand your proposed model, you would have two leaderboards - NUM_TROPHIES and NUM_TROPHIES_HIDDEN. The player would always post to both when updating statistics. NUM_TROPHIES would reset weekly, and NUM_TROPHIES_HIDDEN would never reset. Instead, whenever the client interacts with the score, you would check if a season has ended (which may happen during gameplay, or if a player hasn't signed in for a long time, several seasons may have passed). If so, you would check if the hidden score is over 3000, add to their legend trophies as needed, and set their trophies score correctly. Yes, that should work fine, and have the advantage that players who stop playing will no longer show up on the list, as you say.

To get the previous version, simply set the Version parameter in the call to query the leaderboard to the previous version number (you get the version number for the leaderboard in every response). However, please note that a player who skips playing for a week would have a score of 0 in the previous week's leaderboard.

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.