question

Ternology avatar image
Ternology asked

How can i Update Player Statistic and Get Player Statistic via Cloudscript?

Hi I am currently working on my 2D MMO Game so I would like to set my Player Statistic through Cloudscript to prevent exploiting or cheating from clients, but I don't know if I am doing the right way of updating the player statistic.

in my Revision, this is the code that I write for setting up the player statistic

handlers.UserRegister = function(args) {
  var updateStatistics = server.UpdatePlayerStatistics({
    PlayFabId: currentPlayerId,
    Statistics: [{
      StatisticName: "Health",
      Value: 100
    }, {
      StatisticName: "MP",
      Value: 0
    }, {
      StatisticName: "Level",
      Value: 1
    }, {
      StatisticName: "Exp",
      Value: 0
    }, {
      StatisticName: "SkillPoints",
      Value: 0
    }, {
      StatisticName: "WalkSpeed",
      Value: 5
    }, {
      StatisticName: "JumpForce",
      Value: 10
    }, {
      StatisticName:  "ExtraJumps",
      Value: 1
    }, {
      StatisticName: "Defence",
      Value: 0
    }, {
      StatisticName: "FinalOutput",
      Value: 0
    }]
  });
}

and in my runtime script, I use ExecuteCloudScript to call the UpdatePlayerStatistic

    public void UpdateUserStatisticSS()
    {
        var request = new ExecuteCloudScriptRequest
        {
            FunctionName = "UserRegister",
            GeneratePlayStreamEvent = true,
        };
        PlayFabClientAPI.ExecuteCloudScript(request, null, null);
    }

then It's work well but it didn't set as a JSON on PlayStream Monitor

and I don't have an idea to get the player statistic so what I'm talking about is if the player successful has the statistic that I set on cloudscript and i want to get it for example i have Statistic [{ StatisticName: "WalkSpeed", Value: 5 }] I want to get the value of the walk speed and set it as a player walk speed on client and if the Player WalkSpeed was changed or let's say the player upgrade is walkspeed it will update the existing WalkSpeed Statistic Value

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

Statistic is not the best resource that PlayFab provides to store those data, like Health, MP, etc. Statistics directly creates leaderboards, and it only makes sense in some specific scenarios that a game needs the Leaderboard for Health or MP.

It is not the common scenario to use Statistics, but still, it is feasible since statistic updates fast. However, the function code you have provided doesn’t have any anti-cheating mechanism as it directly call UpdatePlayerStatistics when executed, and any one knows “UserRegister” function name is able to call it anytime.

I am not sure of detailed genre of your game. Is the real time or near time? Do you host an external server instance or use PlayFab Multiplayer Server 2.0?

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

Ternology avatar image Ternology commented ·

The reason why I ask this question is that I want to experiment how does statistic works using ExecuteCloudScript instead calling it on the client which is not secure and exploitable in my way doing this is like troubleshooting or understand how does it work with client or server so I can move on making the statistic in correct and safe ways which are I am able to do Server Side Logic unless I know what I'm doing and making my game secure I'm using Photon 2 for the Multiplayer

0 Likes 0 ·
Seth Du avatar image Seth Du ♦ Ternology commented ·

If your questions is simply about the usage of "server.UpdatePlayerStatistics" in Cloud Script and "server.UpdatePlayerStatistics" in Unity, the code looks good for me.

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.