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?
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?
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.
2 People are following this question.