question

dwojda avatar image
dwojda asked

How to grant multiple stackable items in one call?

I would like to be able to grant multiple stackable items to a user in a single API call. I know I can do it using GrantItemsToUser from the Server API passing the same ItemId multiple times but what if I wanted to add e.g. 1000 instances of the same item? If I sent 1000 ids I'm afraid it could exceed a Could Script execution time limit. It is not a problem if a user already has an item, because then I can use ModifyItemUses. Is there any way to grant multiple stackable items without duplicating an ItemId?

apisPlayer Inventory
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.

dwojda avatar image dwojda commented ·

Sorry for the duplicated topic. I don't know how to edit this :P

0 Likes 0 ·

1 Answer

·
brendan avatar image
brendan answered

Can you detail out your gameplay scenario from the perspective of the player? It's usually best to start from a top-down perspective, so that we can target the solution based upon the ultimate goals.

For example, you can give a player multiples of an item via a Bundle or Container, by setting the quantity you want to give the player. Usually, this is used for doing multiple "draws" from a Random Result Table (drop table), but it can also be used this way.

However, I do need to caution you against trying to grant more than about 50 of any item (even if it's stackable) to a player in a single API call, as that will indeed take a non-trivial amount of time and could cause a problem for a Cloud Script. We're working on some improvements to the inventory system which will improve this - particularly for stackable items - but I'm afraid we don't have a date for that currently. If that's a hard requirement for your game, please open a ticket with us via the option on this page.

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

dwojda avatar image dwojda commented ·

In a game I am working on player is rewarded for a win with a chest. So when they win I want to call GrantItemsToUser from Cloud Script. I also keep locally a number of player's chests in case they get them offline. Let's say that a user played offline for a long time and they have 100 chests saved locally but none of them are in a Player Inventory. When there is an Internet connection I would like to synchronize data by granting a lacking number of chests. It would be convienent to just pass the chest's ItemId with a number of chests to add.

0 Likes 0 ·
brendan avatar image brendan ♦♦ dwojda commented ·

First, I need to highlight that allowing the client to be authoritative about the chests earned while offline effectively guarantees that players will cheat, since they'll be able to set that to whatever they want. However, we do understand that that's not critical to all game designs (hence, the reason we make it possible to turn on the virtual currency and statistics calls for the client).

In this case, what I would recommend is that you just keep track of the number of chests locally, and when the player clicks to open one, call Cloud Script to grant one and unlock it. That way, the call rate will be throttled by the rate at which the player can process the chests. Please be sure that you have a mechanic which prevents the player from hammering away at this, causing many requests in a row, as that may cause the client to be throttled or temporarily blocked. Examples would be animations of the chest opening, displaying the items added with an "ok" button, etc.

1 Like 1 ·
dwojda avatar image dwojda brendan ♦♦ commented ·

That solution sound good. I will also keep track of the number of chests in User Data in case the local data are lost somehow. And perhaps the game will support accounts linked with multiple devices so in that case it will have to be stored outside of the device.

I think that a need to grant multpile items to the user still my occur in our project. We have collectible character cards. So far the only planned way to get them is from chests but a need to just grant some to the user may occur. You cautioned me earlier not to grant more than 50 items in a single API call. So if I needed to grant more items I would split items and grant them in several calls. I could not find in your API any request that allows to pass ItemID and the integer number of stackable items to add. I guess if I wanted I would have to do this like this with GrantItemsToUser:

{
                     
"PlayFabId": "1234567890",
"ItemIds": [
"item",
"item",
"item",
"item",
"item", ...
]
}

Maybe you could think about adding a new request called GrantIemToUser with following parameters:

{
                     
"PlayFabId": "1234567890", "ItemId": "item", "Uses": 10
}
0 Likes 0 ·
Show more comments
jeff0rosenberg avatar image jeff0rosenberg commented ·

Is there an ETA on this update? We're going to require it or something like it. Our use case is that a player can complete an encounter to earn loot. There are different tiers of loot, earned depending on how well the player does in the encounter. Our test encounter has the following tiers:

"Tiers": [
    {
        "Threshold": 0.6,
        "Items": {
            "Junk_Scraps": 2
        },
        "Gold": 5
    },
    {
        "Threshold": 0.8,
        "Items": {
            "Junk_Scraps": 3
        },
        "Gold": 5
    },
    {
        "Threshold": 0.95,
        "Items": {
            "Junk_Scraps": 5
        },
        "Gold": 10
    }
]

Each tier can only be awarded once, but if the player aces the encounter on their first try they would get everything in one go. In this test case they would get 20 Gold (VirtualCurrency) and 10x Junk_Scraps (CatalogItem), but that reward amount is arbitrary. Our designers might want to grant many many items.

We can't use Bundles or Containers, because we'd need to maintain multiple economy objects for each encounter. We'd also never be able to create dynamic encounters with generated rewards, or custom encounters with custom rewards.

0 Likes 0 ·
brendan avatar image brendan ♦♦ jeff0rosenberg commented ·

I'm not clear on how what you're describing is related to the earlier discussion. In your case, there would only be two API calls needed (in Cloud Script or a custom game server) - one to grant the number of scraps, and one to add the virtual currency. You would use your table of thresholds to add up the totals, then make one of each call. If there are requirements that make this more complex though, can you detail out what the issue is you're running into?

0 Likes 0 ·
jeff0rosenberg avatar image jeff0rosenberg brendan ♦♦ commented ·

The virtual currency isn't an issue, it's the number of items. In this case the items are stackable, but we might have a large number of stackable or non-stackable items. Specifically:

>However, I do need to caution you against trying to grant more than about 50 of any item (even if it's stackable) to a player in a single API call

I'd like to be able to say "grant 10 Junk Scraps and 1 Boots of Lightning" instead of "grant Junk Scraps, Junk Scraps, Junk Scraps, Junk Scraps, etc, Boots of Lightning".

0 Likes 0 ·
Show more comments
sevdanski avatar image sevdanski commented ·

I have recently got a similar issue and was wondering what the best approach is.

I'm creating an MMO style game with some crafting and it likely that I will be giving the player stackable items in groups of up to 200.

A thought I had was to write a script that takes a list of items codes and counts, loads the player's inventory, figures out the what needs to change, then uses the grant and modify uses commands to manipulate the inventory.

It's not too complicated, but I don't know how much 'better' it might be.

Any advice would be appreciated

0 Likes 0 ·
brendan avatar image brendan ♦♦ sevdanski commented ·

A stack of an item only counts as 1 against the limit of the number of inventory item instances a player can have, so if the player can have more than one of anything, a stack is a good idea. Managing stacks by changing the number of uses remaining on the item (the stack total) is absolutely more efficient than adding/removing the item, as it requires less work on the backend, so that would be a good way to manage the items. We'll be adding an integrated crafting system (one or more VCs/items on the left and right side of an equation, and secure/atomic operations for exchange) down the road after we get the new commerce model in place.

0 Likes 0 ·
sevdanski avatar image sevdanski brendan ♦♦ commented ·

That sounds great. I won't try and squeeze and ETA out of you though.

Would there be any chance of getting a batch version of ModifyItemUses - something that lets you give a set of ids and counts?

I can roll with what I have planned at the moment (loading/looping/etc), but if it could be done on the backend it would be much more efficient.

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.