question

David Lindskog avatar image
David Lindskog asked

Custom Data to Container created via drop table

Hi!

First a question about drop tables:

Drop tables can't exist on their own, right? They have to live in a container or a bundle?

If that's the case then I wonder how to do this:

If a user clicks on a button a container is created (only exists to hold the drop table). Lets call it "container_drop_table".

The drop table does its thing and give one of three other containers. "timed_container_small", "timed_container_medium" and "timed_container_large".

So far so good. Ok, BUT I wan't to have some custom data on the newly created timed_container. (slot and time_until_open, but that's not important here). That's easy to do in cloud script if I create the timed_container directly. But how do I pass that data from the container_drop_table via the drop table to the timed_ container?
I tried to use UpdateUserInventoryItemCustomData after I created container_drop_table but that doesn't work. I don't know if my syntax is wrong or the drop table that resides in the middle messes things up.

Or should I scrap the idea of using drop tables here and make my own weighted randomize function through cloud script?

Or something else?

Hope my question is clear enough. English isn't my first language and I apologize if it's a little confusing. This container, in a container, in a container stuff can be a little confusing even when you think in your own language. Like Inception :)

Cheers! /David

CloudScriptdataPlayer Inventory
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Sarah Zhang avatar image
Sarah Zhang answered

>> Drop tables can't exist on their own, right? They have to live in a container or a bundle?

Drop table can exist separately. They do not have to be added to a container or a bundle. You can access drop tables programmatically using these two PlayFab Server API methods:GetRandomResultTables, EvaluateRandomResultTable. Please check this section Using drop tables for more detailed information. If you follow this section Advanced drop table usage (setting up a loot crate), you will need to add the drop table to a bundle to implement the packing and unpacking states of the loot crate.

>> But how do I pass that data from the container_drop_table via the drop table to the timed_ container?

The Items, Bundles, Containers, Drop tables in the PlayFab Catalog are designed to be the content that needs to be pre-defined by developers. They are not suitable to be dynamically generated in the game. They are more like a catalog of goods. And items in the player’s inventory would be the instance items. This is the difference between the content in the Catalog and Inventory. So the custom data of Catalog Containers should be pre-defined in the Game Manager or via corresponding Server/Admin API. It’s rare to pass the data from a drop table to the containers in it.

About the API UpdateUserInventoryItemCustomData. For example, you can let PlayFab evaluate the table for you, and give you a single item result using the EvaluateRandomResultTable API. The itemId that returned can be used to grant the item to users via Server API GrantItemsToUser. Then you can set the custom data of the corresponding instance item in the player’s inventory via UpdateUserInventoryItemCustomData.

For a summary, if you want to set the Catalog content’s custom data, you need to set them before you grant the item to players. If you want to set the custom data of player Inventory’s content, you need to use API UpdateUserInventoryItemCustomData.

>> Or should I scrap the idea of using drop tables here and make my own weighted randomize function through cloud script? Or something else?

It would depend on your game design. Could you please tell us which types of custom data you want to set(more detailed info about “slot”,”time_until_open”)? Is it for an inventory instance content or a catalog content?

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

David Lindskog avatar image
David Lindskog answered

Hi, thanks for a quick reply!

Correct me if I'm wrong but in order to use :GetRandomResultTables, EvaluateRandomResultTable I need to activate the playfab server api which is not recommended?
https://community.playfab.com/questions/35524/how-do-i-access-playfabserverapi.html
So that method is out of the question. Is there another way to interact with drop tables directly?

Sorry, of course I meant the the user instances of the item. If I create a container directly I can do it like this:

handlers.giftTimer = function (args) {
  var time = new Date();
  time.setMinutes(time.getMinutes() + 3);  // this will change to a more dynamic value


    var GrantInventoryToUserResponse = server.GrantItemsToUsers({
       ItemGrants: [{
           
        PlayFabId : currentPlayerId,
        ItemId : "timer_chest_simple",  // Will not be hard coded at a later stage
        Data : 
            {
              newTime : time,
              slot : args.slot   // Set in the client (Unity) for sorting purposes
            }
          }]
    });
};

This works great! The chest gets a 3 minute timer (this will change at a later stage) and the slot tells it where it should live in the client.

However, I would like to give the player a random chest. And I thought that if I use a drop table I don't need to code that myself. And it's easier for someone else to change the values without having to poke around in the code.

So if I can't get the drop table with another method than GetRandomResultTables or EvaluateRandomResultTable how do I do it?

If it's unclear what I'm trying to do, I'll try to communicate that again here:

  1. The player does something in the game (watch an ad etc...)
  2. This triggers a function in PlayFab that gives a random chest. That chest gets 2 custom item values, time and slot.

In number 2 it would be awesome if I could use a drop table somehow.

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.

Sarah Zhang avatar image Sarah Zhang commented ·

As you did for GrantItemsToUsers, you can also call Server API GetRandomResultTables, EvaluateRandomResultTable on CloudScript then let players call Client API ExecuteCloudScript to execute the function. Please check the documentation Writing custom CloudScript for more detailed information about it.

Besides, you can set the Custom Data and if-Consumable for items in Catalog directly. You can set them in the [Edit Item] page. If you set an item as a consumable item, it can be consumed by count and/or time. The value of “slot” can be set as its custom data too. If they need to be reused, you can set them as the properties of the Catalog item instead of setting them as the item instance’s custom data. (If you want to dynamically generated them every time, your solution would be more suitable) Please check this doc Items quickstart for more info about setting properties for Catalog’s items.

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.