question

Rizwan Babar avatar image
Rizwan Babar asked

Leaderboard related Questions

There are few things that I want to achieve with the leaderboards system.

  1. I want to reset Leaderboard at 20:00 GMT+0 (current time zone of my account) every day via cloud script as a scheduled task but I couldn't find any thread with an example to achieve that.
  2. I want to give this function parameters of field name and value when it will execute through prize table action but I am not sure how to exactly do that.
  3. Is it possible to make a cloud function that returns the total number of players in a specific leaderboard when it is called? If yes, I'd appreciate an example.

I've searched lot of threads for solution to these but couldn't find any so I'll be thankful if I could get solution to these.

Regards.

Player DataCloudScriptTitle DataLeaderboards and Statisticsscheduled tasks
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

>> I want to reset Leaderboard at 20:00 GMT+0 (current time zone of my account) every day via cloud script as a scheduled task but I couldn't find any thread with an example to achieve that.

Currently, we do not suggest using Scheduled Tasks and Cloud Script to reset the leaderboard. We would suggest you call the Admin API IncrementPlayerStatisticVersion regularly on an administrative tool that can run stably to reset the leaderboard using the customize frequencies.

>> I want to give this function parameters of field name and value when it will execute through prize table action but I am not sure how to exactly do that.

To pass the parameters to function, the CloudScript function must contains the incoming parameter args, and we also suggest you reserve the parameter context. Please check our documentation -- https://docs.microsoft.com/en-us/gaming/playfab/features/automation/cloudscript/writing-custom-cloudscript for more information. Please also check the default Revision 1 of your title’s CloudScript (that contains many CloudScript function samples), and the documentations https://docs.microsoft.com/en-us/gaming/playfab/features/data/playerdata/how-to-modify-read-only-internal-player-data, https://docs.microsoft.com/en-us/gaming/playfab/features/automation/actions-rules/using-cloudscript-actions-with-playstream. For your case, the function could be something like this.

handlers.Winner = function (args, context) {
    var fieldName = args.fieldName;
    var fieldValue = args.fieldValue;

    var updateUserDataResult = server.UpdateUserInternalData({
        PlayFabId: currentPlayerId,
        Data: {
            fieldName: fieldValue
        }
    });
    return updateUserDataResult;
};

>> Is it possible to make a cloud function that returns the total number of players in a specific leaderboard when it is called? If yes, I'd appreciate an example.

You can refer to the sample of this thread -- https://community.playfab.com/questions/38373/how-do-you-get-total-number-of-entries-in-a-leader.html to get the total number of players for a specific leaderboard.

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.

Rizwan Babar avatar image Rizwan Babar commented ·

Thank you for your response. I think calling IncrementPlayerStatisticVersion might cost additional hardware since it will need a machine to execute that call everyday at that specific time. I am thinking to set its reset frequency to daily but award leaderboard players through scheduled tasks at my required time. I have created a cloud function which I will execute using scheduled task at 20:00 GMT+0 everyday. The purpose of this function is to first get the entry fee amount as argument and then multiply it with total entries in leaderboard at that time. Then it will find 60% of result and award that amount in title data of user. Here's what I've achieved so far:

I've typed 10 as assumed player count but I want to find entries count in leaderboard and use it here instead of 10.

I tried your segment method and created a segment with leaderboard value > 0. I tried making a function like this:

I feel like I probably did it wrong way. So could you tell me how can I give players in that created segment of leaderboard to my previous function in place of 10?

Also how can I execute this function only for top 1 player of leaderboard?

0 Likes 0 ·
c1.png (31.3 KiB)
c2.png (7.0 KiB)
Rizwan Babar avatar image Rizwan Babar commented ·

Update: I managed to get count of players in segment of that leaderboard.

Now all I want to know is, how can I execute this only for top 1 player of leaderboard?

0 Likes 0 ·
c3.png (37.3 KiB)
Sarah Zhang avatar image Sarah Zhang Rizwan Babar commented ·

As you said you can use the Prize Table, please navigate to this document -- Using Prize Tables - PlayFab | Microsoft Docs for more information about how to execute the Cloud Script function for the specific rankings.

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.