question

Jeff Gennusa avatar image
Jeff Gennusa asked

Could someone just post cloud script showing how to grant a character to a user?

Could someone just post cloud script showing how to grant a character to a user? I'll figure out how to call the function. I just need the function to create a character for the player who calls it. I need the actual code, because the documentation is horrible for people like me who are new to this system. Please help.

CloudScriptCharacters
10 |1200

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

brendan avatar image
brendan answered

Sure, the most basic form would be:

handlers.grantChar = function (args, context) {
    var grantCharRequest = {
        PlayFabId: currentPlayerId,
        CharacterName: args.characterName,
        CharacterType: args.catalogId
    };
    var result = server.GrantCharacterToUser(grantCharRequest);
    return true;
}

This assumes the client is making the call to ExecuteCloudScript, there's no checking needed to make sure the player should be allowed to call this, and that you've defined the character type in the catalog. The client passes in the ID from the catalog for the character type, and a character name.

For clarity, the character system is designed so that the player can have multiple sub-entities that they use as avatars, like you see in MMOs. And just as the player can have data, statistics, and inventory, the character also has a separate version of those.

1 comment
10 |1200

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

Willy Seminario avatar image Willy Seminario commented ·

@Brendan thank you so much, I really appreciate this answer! I was about to quit because couldnt find the solution to be able to do exactly what you shared.

0 Likes 0 ·
Jeff Gennusa avatar image
Jeff Gennusa answered

This worked for me. Thank you so much.

Now I will build in the character stats and security measures within the cloud script.

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.