Modding:Treasure Tables
This page is a modding page, and follows its own rules and standards separate from the rest of the wiki. |
I'm learning what I'm doing as I go and creating this page to help others learn what they're doing in the future. I won't take offense if it's deleted, I'm not sure if this wiki is the right place for this. Also, for the time being, take everything with a grain of salt. I very well could be wrong.
One of the many types of text files crucial to a mod maker's toolkit are Treasure Tables. Treasure Tables define all inventories in the game- what is in them, and what could be. All chests, traders, and corpses use treasure tables to define their loot. For mods adding items, the main way for them to appear in game is to add them to one treasure table or another. Most commonly, mods that add items just for the sake of it add their items to the tutorial chest, a cartilaginous chest found on the Nautiloid. This page goes over the basics of treasure tables.
Let's look at an excerpt from one of the TreasureTable.txt files in the game:
new treasuretable "Gold_Pocket_Wealthy"
new subtable "10,1;11,1;12,1;13,1"
object category "Gold",1,0,0,0,0,0,0,0
The first line, in a rather self explanatory manner, creates a new treasure table named "Gold_Pocket_Wealthy"
The second line looks much more confusing, but isn't. Every item within a table needs a subtable. If you want 1 potion of healing that's guaranteed to be in the treasure table, it would still need its own subtable. So, with that in mind, a subtable is created. The numbers within the quotation marks denote the weights for how many times the table will be rolled- As an example, the weights for this table start with "10,1", so, with a weight of 1 (equal to everything else in the table), this table could be rolled 10 times. That means we would get 10 of whatever is listed in the table below. Each subsequent numbered pair denotes another quantity & weight pair- "11,1" means there is a weight of 1 that the table will be rolled 11 times, and so on.
The final line, much like the first, is pretty self explanatory. the "object category" that it begins with is necessary for all items within a subtable- it doesn't mean much to us, since it always stays the same, but it means a lot to the code. "Gold" quite obviously means Gold, the game's currency. The 1 is the weight of that item WITHIN the table- so, if there were multiple items, each would have those odds of being picked. If there were gold listed, with a weight of 1, and a potion of healing, with a weight of 2, each time the table was rolled, gold would have a 1/3 chance of being picked, while potions of healing would have a 2/3 chance of being picked. So, if you got a 13 when rolling the table, 2/3 of the time you would get 13 health potions, and 1/3 of the time you would get 13 gold.
Let's look at one more example that showcases a few different concepts:
new treasuretable "Supply_CampFood"
new subtable "0,1;1,1;2,1;3,1"
object category "I_CONS_FOOD_Vegetable_Potato",1,0,0,0,0,0,0,0
object category "I_CONS_FOOD_Vegetable_Carrot",1,0,0,0,0,0,0,0
new subtable "1,1"
object category "T_ST_Food_Sausage",1,0,0,0,0,0,0,0
This table is a bit longer, but since we already understand some of the concepts, we won't need to go over all of it. Also note that this is only a portion of the table from the game code, to showcase important concepts.
the first 2 lines create a new treasure table named "Supply_CampFood" with a 1/4 chance each of getting either 0, 1, 2, or 3 of one of the things listed below it. The first important thing to note is the "I_" that leads the item name. This is not part of the item name in game, and instead notes that it is an item.
So, within the first 4 lines, our treasure table now has either 0, 1, 2, or 3 of either carrots or potatoes. The next line shows another (rather obvious), but important concept- they want something to be guaranteed to roll exactly once, and as such, we now know that the following line is guaranteed to be in the table.
So, the 6th and final line looks a lot like the 3rd and 4th line, with one small difference- The "I_" from the prior has been replaced with "T_" in the latter. This "T_" denotes that the line is calling back to another, previously created table. So, in this case, the line is calling the table "ST_Food_Sausage" Searching through the rest of the text file, you could find that that table looks like this:
new treasuretable "ST_Food_Sausage"
new subtable "1,1"
object category "I_CONS_FOOD_Sausage",2,0,0,0,0,0,0,0
object category "I_CONS_FOOD_Sausage_B",2,0,0,0,0,0,0,0
object category "I_WPN_Salami",3,0,0,0,0,0,0,0
object category "I_CONS_FOOD_Sausage_D",2,0,0,0,0,0,0,0
So, this table has a 2/9 chance of producing "Sausage," a 2/9 chance of producing "Sausage_B," a 1/3 chance of producing "Salami," and a 2/9 chance of producing "Sausage_D"
With all of this info, we can say that our original table, "Supply_CampFood," has not only the 0, 1, 2, or 3 of potatoes or carrots we found before, but also 1 of any of the 4 types of sausage, with the weights listed above.