question

activedreaminc avatar image
activedreaminc asked

How to give player EXP after battle? and How to reward player after level up?

Hi, I have created statistics called EXP and Level. I would like to reward player certain amount of EXP after battle. Which function should I use to implement that?

Also I would like to implement so that after player accumulated certain EXP then the player will Level up and get reward such as gold currency, playable character, gift box, etc. Which function should I use to implement this feature?

Thank you for your help and support,

Best Regards,

Dennis

Active Dream

Player DataLeaderboards and StatisticsPlayer InventoryCharacter DataCharacters
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

Firstly, you can learn about PlayStream Event, Rules and Cloud Script, then combine these functions to implement your features. About the possible workarounds we can give the following simplified steps:

>> I would like to reward player certain amount of EXP after battle. Which function should I use to implement that?

  1. Write a Cloud Script function A that can update player statistics EXP based on the EXP calculation formulas.
  2. In the clients, when players finish a battle, you use the Client API WritePlayerEvent, write a custom Event B.
  3. Set a Rule, set the Event type as your custom event type B. Choose the Execute CloudScript function as the Actions Type, then choose the function A in the Cloud Script Function drop down menu.

>> I would like to implement so that after player accumulated certain EXP then the player will Level up and get reward such as gold currency, playable character, gift box, etc.

  1. Write the corresponding Cloud Script functions.
  2. Set a Rule, set the Event type as the event type com.playfab.player_statistic_changed. Add corresponding Conditions in your need. Choose the Execute CloudScript function as the Actions Type, then choose the corresponding CloudScript functions.
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.

activedreaminc avatar image activedreaminc commented ·

Hi @Sarah Zhang

Thank you for your reply, could give example code for these steps please?

  1. Write a Cloud Script function A that can update player statistics EXP based on the EXP calculation formulas.
  2. In the clients, when players finish a battle, you use the Client API WritePlayerEvent, write a custom Event B.

Thank you for your help and support

Best Regards,

Dennis

Active Dream

0 Likes 0 ·
Sarah Zhang avatar image Sarah Zhang activedreaminc commented ·

1. You can find the sample CloudScript code in your CloudScript revision1. You can also refer to the following code.

handlers.UpdateCurrentPlayerStatistics = function (args, context) {

    var request = {
        PlayFabId: currentPlayerId, Statistics: [{
                StatisticName: "Exp",
                Value: 100
            }]
    };
    
    var playerStatResult = server.UpdatePlayerStatistics(request);
};



2. You can refer to this doc.

0 Likes 0 ·
activedreaminc avatar image activedreaminc Sarah Zhang commented ·

Hi @Sarah Zhang,

Thank you for your help, I have implemented the cloud script successfully. By the way, how to promote and gain audience for the game that I developed?

Thank you for your help and support,

Best Regards,

Dennis

Active Dream

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.