question

John Mac avatar image
John Mac asked

,Get another players Entity token from playfab id in cloudscript

Hello,

I need to make a cloudscript function that a client can call that will edit entity objects for another player. The player has the other players PlayFabID, but I cannot figure out how to go from a PlayFabID to the EntityKey of type "title_player_account" of the other player in cloud script in order to change entity objects. How can this be achieved?

The code snippet below shows the function I need in context.

Any help would be greatly appreciated!

handlers.setobjecttest1 = function (args, context) {
    // I have this
    var anotherPlayersPlayFabID = "EXAMPLEPLAYFABID";

    // This is how I would get the current players entity key
    //var target = context.currentEntity.Entity;
    
    // I want either this function:
    var target = PlayFabIDToEntity(otherPlayersPlayFabID);
    // ... or this Function which just returns the ID
    //  var target = {
    //    Id:PlayFabIDToEntityID(otherPlayersPlayFabID);,
    //    Type:"title_player_account"
    //  
    
    var apirequest = {
        Objects: [
            {
                ObjectName: "ObjectName",
                DataObject: {
                    "TestKey":"TestValue"
                }
            }
        ],
        Entity: target
    }
    return entity.SetObjects(apirequest);
}
CloudScript
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

·
John Mac avatar image
John Mac answered

I believe I have figured it out, it's actually very simple. The function is below:

function PlayFabIDToEntityID(playfabId) {
    var profile = server.GetUserAccountInfo( {PlayFabId: playfabId} );
    return profile.UserInfo.TitleInfo.TitlePlayerAccount.Id;
}
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.

Citrus Yan avatar image Citrus Yan commented ·

GetTitlePlayersFromMasterPlayerAccountIds can also be used to do the trick, and it's especially suitable for handling multiple players.

1 Like 1 ·
John Mac avatar image John Mac Citrus Yan commented ·

Thank you for that info, you're right that is better than my solution.

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.