question

brendan avatar image
brendan asked

How do I create an item that contains something random?

Brendan Vanous
started a topic on Sat, 09 August 2014 at 1:29 PM

I'd like to make an item for my game which, when opened, gives the user a random inventory item.

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

Best Answer
Brendan Vanous said on Sat, 09 August 2014 at 1:29 PM

The first step is to create a RandomResultTable, using Admin/UpdateRandomResultTables. The key identifier for a table is its TableId (which is used next, in setting up the catalog item which will provide the random drop to the user), and it contains a set of TableResultNode objects which define the possible results - which can be either items from the title catalog or other RandomResultTables, as specified for each entry by the ResultItemType.

The chance of the returned item resolving into a particular entry is determined by the Weight values they are given in the table. The Weight values used can be in any numeric range the developer desires, as they are normalized.

Here's an example of a RandomResultTable (using the JSON definition):

{
   "TableId": "DropTable 1",
   "Nodes": [
   {
      "ResultItemType": "ItemId",

      "ResultItem": "Common Sword",
      "Weight": 80
   },
   {
      "ResultItemType": "ItemId",
      "ResultItem": "Uncommon Sword",
      "Weight": 15
   },
   {
      "ResultItemType": "ItemId",
      "ResultItem": "Rare Sword",
      "Weight": 5
   }
   ]
}

Here, the Weight values add up to 100, making the chance of getting each .8, .15, and .05. Since the Weight values are normalized, this means that if the developer wanted to add another item to this table with a Weight of 10, the chances of each would then be (roughly) .727 (80/110), .136 (15/110), .091 (10/110), and .045 (5/110). This allows developers to quickly update tables without having to go through each item and update its Value.

Next, the RandomResultTable is added as a CatalogItem, using Admin/UpdateCatalogItems or Admin/SetCatalogItems. The table can be added as part of either a Bundle, which is an item that can contain any number of CatalogItem or RandomResultTable objects, as well as a virtual currency balance, all of which is added to the user's inventory when the Bundle is added, or a Container, which can contain all the same things as a Bundle, but requires a "Key" item from the user's inventory to open. The "Key" for a Container can be any CatalogItem the developer chooses, and it is removed from the player's inventory when it is used to open the Container.


1 Comment
Brendan Vanous said on Sat, 09 August 2014 at 1:29 PM

The first step is to create a RandomResultTable, using Admin/UpdateRandomResultTables. The key identifier for a table is its TableId (which is used next, in setting up the catalog item which will provide the random drop to the user), and it contains a set of TableResultNode objects which define the possible results - which can be either items from the title catalog or other RandomResultTables, as specified for each entry by the ResultItemType.

The chance of the returned item resolving into a particular entry is determined by the Weight values they are given in the table. The Weight values used can be in any numeric range the developer desires, as they are normalized.

Here's an example of a RandomResultTable (using the JSON definition):

{
   "TableId": "DropTable 1",
   "Nodes": [
   {
      "ResultItemType": "ItemId",

      "ResultItem": "Common Sword",
      "Weight": 80
   },
   {
      "ResultItemType": "ItemId",
      "ResultItem": "Uncommon Sword",
      "Weight": 15
   },
   {
      "ResultItemType": "ItemId",
      "ResultItem": "Rare Sword",
      "Weight": 5
   }
   ]
}

Here, the Weight values add up to 100, making the chance of getting each .8, .15, and .05. Since the Weight values are normalized, this means that if the developer wanted to add another item to this table with a Weight of 10, the chances of each would then be (roughly) .727 (80/110), .136 (15/110), .091 (10/110), and .045 (5/110). This allows developers to quickly update tables without having to go through each item and update its Value.

Next, the RandomResultTable is added as a CatalogItem, using Admin/UpdateCatalogItems or Admin/SetCatalogItems. The table can be added as part of either a Bundle, which is an item that can contain any number of CatalogItem or RandomResultTable objects, as well as a virtual currency balance, all of which is added to the user's inventory when the Bundle is added, or a Container, which can contain all the same things as a Bundle, but requires a "Key" item from the user's inventory to open. The "Key" for a Container can be any CatalogItem the developer chooses, and it is removed from the player's inventory when it is used to open the Container.

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

Sergey Rudenko avatar image Sergey Rudenko commented ·

@Brendan quick clarification question:) - does the API prevent "drop" of an item that player already has? I mean a situation when player has certain sword and now the drop table contains it and its no fun to gt the same item?

A workaround I was thinking about - is to allow "crushing" of items that you already have into a currency...

0 Likes 0 ·
brendan avatar image brendan Sergey Rudenko commented ·

We don't currently provide built-in support for fallbacks on drop tables for cases where a player already has an item. Your "crushing" duplicates concept, to give them currency, would be a good interim solution for until we have this.

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.