question

Bernhard Hofer avatar image
Bernhard Hofer asked

Remove Character from Player

Hello, im creating a RPG game where I can create and delete characters from each users ..

character adding works fine ..

But I have a problem with deleting characters .. Because I have to delete it with the characterId ..

How can I access my character Id when I create a character ?

And is the function for deleting right ? Because im pretty new at CloudScripting and have no idea ..

handlers.removeChar = function(args, context)
{
    var removeCharRequest =
    {
        PlayFabID:
        currentPlayerId,
        
        CharacterId:
        args.characterName,
        
        SaveCharacterInventory:
        args.DeleteCharacterFromUser,
    };
    
    var result = server.DeleteCharacterFromUser(removeCharRequest);
    
    return true;
}
    private void DeleteCharacterFromUser(SavedGame savedGame)
    {
        var request = new ExecuteCloudScriptRequest()
        {
            FunctionName = "removeChar",
            FunctionParameter = new { CharacterId = savedGame.MyCharacterName, deleteInventory = true }
        };


        PlayFabClientAPI.ExecuteCloudScript(request, removeCharacterSuccess, removeCharacterError);
    }
handlers.grantChar = function(args, context)
{
    var grantCharRequest =
    {
        PlayFabID:
        currentPlayerId,
        
        CharacterName:
        args.characterName,
        
        CharacterType:
        args.catalogId
    };
    
    var result = server.GrantCharacterToUser(grantCharRequest);
    
    return true;
}
    private void AddCharacterToPlayer(string charName)
    {
        var request = new ExecuteCloudScriptRequest()
        {
            FunctionName = "grantChar",
            FunctionParameter = new {characterName = charName, catalogId = classes[classIndex] }          
        };


        PlayFabClientAPI.ExecuteCloudScript(request, addCharacterSuccess, addCharacterError);
    }
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.

Bernhard Hofer avatar image Bernhard Hofer commented ·

Ok I have created now this function ..

But how I can find the characterID based on the name from the character ?

    private void GetCharacterID()
    {
        var request = new ListUsersCharactersRequest();


        request.PlayFabId = PlayfabManager.MyInstance.MyPlayFabID;


        PlayFabClientAPI.GetAllUsersCharacters(request, onAccess, onError);
    }


    private void onError(PlayFabError obj)
    {
        print("Hat nicht funktioniert");
    }


    private void onAccess(ListUsersCharactersResult obj)
    {


    }
0 Likes 0 ·

1 Answer

·
Citrus Yan avatar image
Citrus Yan answered

GetAllUsersCharacters returns a list of CharacterResult for the user, each entry, representing one of the user’s characters, contains the CharacterName along with its associated CharacterId and CharacterType type string which you can use to find the CharacterId based on the name of the character.

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.