question

Miquel avatar image
Miquel asked

Getting player group

Hello,

I have a game where every player can belong to a single group.

I would like to know the group of a given player from Cloud Script.

What is the best way to achieve this?

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

·
Citrus Yan avatar image
Citrus Yan answered

Hi @Miquel,

First of all, you can utilize the Entity Groups feature to implement the group management for your players, please click the link to learn more.

Once you implemented that, ListMembership should do the work of returning the groups of a given player, it can list all groups and roles for an entity, which is a title_player_account entity for your case. Here are some steps you can take to get the groups of a given player:

1.Define a handler in the Cloud Script, hit save and deploy:

handlers.listGroupMembershipForThePlayer = function (args, context){


    var getMemberships = entity.ListMembership({Entity: args.entity});
    
    return getMemberships;
}

2. From the client, call ExecuteCloudScript to execute that function, with the following parameters in the request body:

{
  "FunctionName": "listGroupMembershipForThePlayer",
  "FunctionParameter": {
     "entity": {
                "Id": "39CDE53356C83D6C",
                "Type": "title_player_account"
                }
     
  },
  "RevisionSelection": "Live",
  "GeneratePlayStreamEvent": true
}

3. The response should contain the player’s group info:

"data": {
        "FunctionName": " listGroupMembershipForThePlayer",
        "Revision": 176,
        "FunctionResult": {
            "Groups": [
                {
                    "GroupName": "testGroup1",
                    "Group": {
                        "Id": "7804396E92066CC8",
                        "Type": "group",
                        "TypeString": "group"
                    },
                    "ProfileVersion": 0,
                    "Roles": [
                        {
                            "RoleName": "Administrators",
                            "RoleId": "admins"
                        }
                    ]
                }
            ]
        }

By the way, ListMembership is an entity API, it takes a player’s EntityKey as the parameter, hence it’s different from classic APIs, here is the doc that clarifies these difference you may find helpful.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

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.