question

Kim Strasser avatar image
Kim Strasser asked

Displaying another players amount of virtual currency?

Is it possible to get another players amount of virtual currency?

For example: Player_A clicks on the display name of player_B. Then, I want to display the game progress and statistics of player_B in my game.

Is it possible to display player_Bs virtual currencies when player_A clicks on his display name? Can I use GetUserInventory to get another players amount of virtual currencies?

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

·
Rick Chen avatar image
Rick Chen answered

You could write a CloudScript function that calls the GetUserInventory, which returns not only the virtual currency, but also the player’s inventory. If you only want to get the virtual currency, you could use GetPlayerCombinedInfo on CloudScript and only set the "GetUserVirtualCurrency" to true. Then player_A can get player_B’s virtual currency by calling the CloudScript with ExecuteCloudScript API.

4 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.

Kim Strasser avatar image Kim Strasser commented ·

Is it possible to get the user inventory of more than one person simultaneously?

For example:

The player has 20 friends. Would it be possible to get the user inventory of these 20 friends in one GetUserInventory API call?

I use this CloudScript code to get one players inventory:

handlers.LoadSaveGame = function (args, context)
{
var currencygo = 0;
var elementxyz = false;
var elementabc = false;

var result = server.GetUserInventory(
{
       PlayFabID: "xxx"
});

if ((result != null) && (result.Error == null))
{
    currencygo = result.VirtualCurrency["GO"];
    
    result.Inventory.forEach(element => {
    if (element.ItemId == "xyz")
    {
      elementxyz = true;
    }
    if (element.ItemId == "abc")
    {
      elementabc = true;
    }
}

var inventory = {
        "Currencygo": currencygo,
"Elementxyz": elementxyz, "Elementabc": elementabc }; return inventory; }

Is it possible to enter more than one PlayFabId in the GetUserInventory API call?

0 Likes 0 ·
Rick Chen avatar image Rick Chen ♦ Kim Strasser commented ·

No, it is not possible to get multiple users’ inventory at once. The GetUserInventory API returns all items in a user’s inventory, it would be huge data to return if request multiple users who have many items at once. Could you please describe your scenario? Why would you want to get 20 friends’ inventory in one call?

0 Likes 0 ·
Kim Strasser avatar image Kim Strasser Rick Chen ♦ commented ·

I want that the player can see the currencies and "statistics" of other players. But I only display the currencies and "statistics" when the player clicks on the display name of another player. In my game, it's only possible to display one players currencies and "statistics" at once. "statistics" is a ReadOnlyData key/value pair where I save things like total amounts of achievements.

Can I use client API GetPlayerCombinedInfo to get all currencies and the ReadOnlyData key/value pair "statistics" from other players?

string key = "statistics";
var result = await PlayFabClientAPI.GetPlayerCombinedInfoAsync(new GetPlayerCombinedInfoRequest()
{
  PlayFabId = playfabid,
  InfoRequestParameters = new GetPlayerCombinedInfoRequestParams()
  {
    GetUserVirtualCurrency = true,
    GetUserReadOnlyData = true,
    UserReadOnlyDataKeys = new List<string> { key }
  }
});

Does it matter if a player would call GetPlayerCombinedInfo approximately 10-15 times in 1 minute?

Should I try to reduce the API calls so that a player can not call client API GetPlayerCombinedInfo more than "xx" times in 1 minute? How many times should it be allowed to call GetPlayerCombinedInfo?

0 Likes 0 ·
Show more comments

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.