Microsoft Azure PlayFab logo
    • Multiplayer
    • LiveOps
    • Data & Analytics
    • Add-ons
    • For Any Role

      • Engineer
      • Designer
      • Executive
      • Marketer
    • For Any Stage

      • Build
      • Improve
      • Grow
    • For Any Size

      • Solo
      • Indie
      • AAA
  • Runs on PlayFab
  • Pricing
    • Blog
    • Forums
    • Contact us
  • Sign up
  • Sign in
  • Ask a question
  • Spaces
    • PlayStream
    • Feature Requests
    • Add-on Marketplace
    • Bugs
    • API and SDK Questions
    • General Discussion
    • LiveOps
    • Topics
    • Questions
    • Articles
    • Ideas
    • Users
    • Badges
  • Home /
  • API and SDK Questions /
avatar image
Question by dwojda · Sep 14, 2016 at 04:58 PM · apisPlayer Inventory

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?

Comment

People who like this

0 Show 1
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image dwojda · Sep 14, 2016 at 04:48 PM 0
Share

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

1 Reply

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by Brendan · Sep 14, 2016 at 05:22 PM

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.

Comment

People who like this

0 Show 14 · Share
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image dwojda · Sep 14, 2016 at 05:42 PM 0
Share

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.

avatar image Brendan ♦♦ dwojda · Sep 14, 2016 at 06:36 PM 1
Share

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.

avatar image dwojda Brendan ♦♦ · Sep 14, 2016 at 07:03 PM 0
Share

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
}
Show more comments
avatar image jeff0rosenberg · Oct 12, 2017 at 08:04 PM 0
Share

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.

avatar image Brendan ♦♦ jeff0rosenberg · Oct 12, 2017 at 08:50 PM 0
Share

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?

avatar image jeff0rosenberg Brendan ♦♦ · Oct 12, 2017 at 09:20 PM 0
Share

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

Show more comments
avatar image Sevdanski · Nov 14, 2018 at 12:36 PM 0
Share

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

avatar image Brendan ♦♦ Sevdanski · Nov 14, 2018 at 10:05 PM 0
Share

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.

avatar image Sevdanski Brendan ♦♦ · Nov 15, 2018 at 04:28 AM 0
Share

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.

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Navigation

Spaces
  • General Discussion
  • API and SDK Questions
  • Feature Requests
  • PlayStream
  • Bugs
  • Add-on Marketplace
  • LiveOps
  • Follow this Question

    Answers Answers and Comments

    3 People are following this question.

    avatar image avatar image avatar image

    Related Questions

    Is there any example script of purchases in iOS with Unity IAP via Playfab? 1 Answer

    Is there a way to get revoked inventory items like in GameManager? 1 Answer

    Change recharge maximum per player 1 Answer

    Questions about transaction API call 1 Answer

    Getting item,How to get ItemInstanceId in GrantItemsToUse 1 Answer

    PlayFab

    • Multiplayer
    • LiveOps
    • Data & Analytics
    • Runs on PlayFab
    • Pricing

    Solutions

    • For Any Role

      • Engineer
      • Designer
      • Executive
      • Marketer
    • For Any Stage

      • Build
      • Improve
      • Grow
    • For Any Size

      • Solo
      • Indie
      • AAA

    Engineers

    • Documentation
    • Quickstarts
    • API Reference
    • SDKs
    • Usage Limits

    Resources

    • Forums
    • Contact us
    • Blog
    • Service Health
    • Terms of Service
    • Attribution

    Follow us

    • Facebook
    • Twitter
    • LinkedIn
    • YouTube
    • Sitemap
    • Contact Microsoft
    • Privacy & cookies
    • Terms of use
    • Trademarks
    • Safety & eco
    • About our ads
    • © Microsoft 2020
    • Anonymous
    • Sign in
    • Create
    • Ask a question
    • Create an article
    • Post an idea
    • Spaces
    • PlayStream
    • Feature Requests
    • Add-on Marketplace
    • Bugs
    • API and SDK Questions
    • General Discussion
    • LiveOps
    • Explore
    • Topics
    • Questions
    • Articles
    • Ideas
    • Users
    • Badges