question

Dale Strickler avatar image
Dale Strickler asked

I am trying to find a good step by step example for chaining consumables.

I have been struggling to decide if this https://community.playfab.com/questions/6271/stackable-consumable-by-time.html covers what I am looking for. It also references work that was underway at the time so I sm not sure if there is an easier option now.

What I am looking for, in terms of player experience, is a chained powerup. If a player buys a one-hour powerup they will have the power for an hour. If the player buys a bundle of 3 one hour power-ups the power will be active for 3 hours. It should activate on purchase. And one powerup should start as soon as the previous one expires. (It's kind of a stacked timed consumable.)

I have some test code another developer wrote. It is not what I want. It uses containers to start one-hour powerups and you can't buy a new powerup until the last one runs out. And the player needs to start the powerup after buying it rather than it auto-starting on purchase. I have been messing with the code and have it closer but it feels like I am missing something easier.

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

·
brendan avatar image
brendan answered

Yes, if you set up an item with an expiration (consumable by time), and set the "time group name" on the item, any other item added with the same "time group name" will add its time to the expiration for the item. So in your example, set up item "ChainedItem" as a stackable with an expiration of 1 hour, and a "time group name" of "ChainedItem" as well (doesn't have to match, but I figure you want it to be unique, so you might as well use the Item ID). Now, if a player gets one in inventory, it'll have an expiration in one hour. If another is added, it'll stack onto that one and add an hour to the expiration time.

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

Dale Strickler avatar image Dale Strickler commented ·

Perfect. I will give it a try.

0 Likes 0 ·
Dale Strickler avatar image Dale Strickler commented ·

Likely I can figure it out, but do I need to do time remaining math to show how long the stacked powerups will still be active based on the number of "ChainedItems" they have in their inventory, or is there some single call that just gives me the total?

0 Likes 0 ·
Citrus Yan avatar image Citrus Yan Dale Strickler commented ·

The GetUserInventory API returns expiration date for each item, which should meet your needs.

0 Likes 0 ·

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.