question

Ozan Yilmaz avatar image
Ozan Yilmaz asked

How can I grant same stackable items multiple times to a player in one call?

Hello,

Is there a way to grant same stackable items to a player in once call? In our game the players can buy the same item up to 5 times. To not click the buy button 5 times, there is an input field in the game and the players can decide how many of those is going to buy. Currently, I made a loop in Cloudscript, but that calls the same API more than 1.

EDIT: I can't use bundles because there are more than 1 items like this in the game. I'm also thinking of making the items not stackable and make an item custom data that represents how many instances the player has

    //... checking 'args' to see if the parameters are correct

    var newItems = [];
    for(var i = 0; i < parseInt(args.Amount); i++) {
        var newItem = {
            "PlayFabId": currentPlayerId,
            "CatalogVersion": "Items",
            "ItemIds": args.ItemId
        };
        newItems.push(server.GrantItemsToUser(newItem));
    }
    
    //...

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

·
Seth Du avatar image
Seth Du answered

In your scenario, you used GrantItemsToUser API in line 10. The “ItemIds” argument of this API is actually array type. One way to grant same items multiple time in one call would be passing lists of same ItemIds in the argument as below. In addition, you may also need a loop sentence to generate the item list.

{
    "PlayFabId": currentPlayerId,
    "CatalogVersion": "Items",
    "ItemIds": [
        args.ItemId, 
        args.ItemId,
        args.ItemId,
        …
    ]
}

Another way could be to use Modify Item Uses API. However, this API takes an ItemInstanceId as argument. This argument is the Unique instance identifier of the item in player’s inventory, which means that you can only use this API with an item instance that is already in a player’s inventory. For those items that do not exist in player’s inventory, you may use GrantItemsToUser to create an instance for the player first. However, it will require at least 2 API calls, but this is the best solution when there are multiple but also duplicated items to grant.

Please refer to the documents GrantItemsToUser and Modify Item Uses to see the request of these APIs.

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.