question

Travis Pettry avatar image
Travis Pettry asked

Set another players entity data

Hi All,

I am working on the send a life to a friend mechanic in my game. Based off of my research the best way to do this task is listed here. There is one step that I do not quite understand, see below.

  • The title adds the Key/Value pair "111":"data" to Player B's "FriendRequests" Shared Group Data object, via Cloud Script. The "data" value could be anything else you need, or even a custom message from the player.

How is this achieved in the new entity system? To my understanding if I make a entity call from the client it only effects the current player. Also, if I make a entity call from the server it only effects the title entity data. How do I set the entity data of another player?

Thank you,

Travis Pettry

entities
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

PlayFab now support entity related actions in Cloud Script via calling ExecuteEntityCloudScript.

For more information, you may refer to makeEntityAPICall function in the default Cloud Script revision:

handlers.makeEntityAPICall = function (args, context) {

    // The profile of the entity specified in the 'ExecuteEntityCloudScript' request.
    // Defaults to the authenticated entity in the X-EntityToken header.

    var entityProfile = context.currentEntity;

    // The pre-defined 'entity' object has functions corresponding to each PlayFab Entity API,
    // including 'SetObjects' (https://api.playfab.com/documentation/Data/method/SetObjects).
    var apiResult = entity.SetObjects({
        Entity: entityProfile.Entity,
        Objects: [
            {
                ObjectName: "obj1",
                DataObject: {
                    foo: "some server computed value",
                    prop1: args.prop1
                }
            }
        ]
    });


    return {
        profile: entityProfile,
        setResult: apiResult.SetResults[0].SetResult
    };
};


As you can see in the code, you can define an entity key to set object for target entity.

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.

Travis Pettry avatar image Travis Pettry commented ·

Hi @SethDu, according to the docs the only entity key I see is the Entity property of SetObjects. When I look up how to get an entity I find there are two ways to obtain an entity object. First is via login, that clearly wont work for setting another users data. Second, is PlayFabAuthenticationAPI.GetEntityToken, I cannot seem to get this one to work, it keeps returning 403 unauthorized. What is the best way to obtain an entity key for anther player?

0 Likes 0 ·
Seth Du avatar image Seth Du ♦ Travis Pettry commented ·

You don't need to know the entity token for target player, you only need to create an entity token for that player. if you are directly using SetObject, you can only set current login player's object, but Cloud Script is able to set other players' because it is like using a title-level entity token.

So basically, you login into any player account, call ExecuteEntityCloudScript, it will work. In the Cloud Script code:

handlers.makeEntityAPICall = function (args) {
 
// create an entity key, set another player's key.
    var target = {
        Id:"xxxxxxxxxxx",
        Type:"title_player_account"
    }

    var apiResult = entity.SetObjects({
        Entity: target,
        Objects: [
            {
                ObjectName: "obj1",
                DataObject: {
                    foo: "some server computed value",
                }
            }
        ]
    });
    return {
        setResult: apiResult.SetResults[0].SetResult
    };
};

There are different type of entity key, normally we will use master_player_account and title_player_account. You may see more information on: https://docs.microsoft.com/en-us/gaming/playfab/features/data/entities/available-built-in-entity-types

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.