The default treasure generation script seems to be gp_treasure_op_de. It seems to check variables set on the container it is called from. It includes some of the X2 scripts from HotU. I spent some time walking through how this all works.
Note: After playing with this system a bit more, I've found that:
1. The base chance is 50%. This means that unless you set the base chance on an area, you'll get just a few gold just over 50% of the time.
2. The magic treasure type tends to give one or two +1 weapons for a level 1 PC. This may be a bit over-powered for low-level mods.
3. For better customization, consider lordniah's FRW base module's implementation of the NWN1: SoU treasure scripts (For more see http://www.wendersnaven.com/node/98).
Here is the header comment, which explains the basics:
// gp_treasure_op_de
/*
Spawns in general purpose treasure and gold based on variables:
TreasureClass - one of three values. Default is low
const int X2_DTS_CLASS_LOW = 0; //Treasure Class Low
const int X2_DTS_CLASS_MEDIUM = 1; //Treasure Clas Medium
const int X2_DTS_CLASS_HIGH = 2; //Treasure Class High
TreasureType - add desired types together. For example, gold + disposable = 5
Defualt is 5 (gold + disp)
Note that you cannot add the same type more than once (i.e. no gold+gold).
const int X2_DTS_TYPE_DISP = 1;
const int X2_DTS_TYPE_AMMO = 2;
const int X2_DTS_TYPE_GOLD = 4; // actually gold and gems
(not allowed) const int X2_DTS_TYPE_ITEM = 8; // char specific Item (ignores treasure class)
const int X2_DTS_TYPE_MAGIC = 16; // random magic items
const int X2_DTS_TYPE_MUNDANE = 32; // random mundane items
This script should be placed in the container's OnOpen and OnDeath events.
If bashed, disposeable will be dropped and broken item generated.
If no treasures are generated, 1d20 gold will be created.
*/
This allows module authors to quickly create random treasure of different types by setting both the "TreasureClass" integer variable and the "TreasureType" integer variable on the container. "TreasureClass" uses a simple 0, 1, or 2. "TreasureType" uses a single number that adds up the type values you want for the container. For example, ammo (2) + gold (4) + magic items (16) would be a value of 22.
An important thing to note is that X2_DTS_TYPE_ITEM (8) is not allowed. Here is the reason given in a comment further down in the script: "these don't scale and are to dangerous for balance reasons to have in the standard treasure generation."
Our script then calls DTSGenerateTreasureOnContainer(), which is located in "x2_inc_treasure." This script first calls gets a random number of items to create based on the call to DTSGetMaxItems().
Looking at DTSGetMaxItems(), we see that it first looks for the module-level integer variable "X2_DTS_MAXITEMS." If it can't find it, it uses a default of 2. Note that this variable is not set in the switches file or in the default "On Module Load" file, which means the value will be 2 unless you have specifically set it.
Returning to DTSGenerateTreasureOnContainer(), the next step is to call DTSGenerateTreasureItems() for each item we are going to create. This function checks the chances for each of the types of items we told it to create with the variables set on the container. The chance is defined by DTSGetBaseChance(). The default is defined as 50 in the constants at the top of the file, but these can be overridden at the area and module level with the variable "X2_DTS_BASECHANCE." If a class and chance condition is met based on a randomized number, an item is created by DTSGetRandomItemResRef().
Looking at DTSGetRandomItemResRef(), we see that we first have to get the name of the .2da file we want to reference using DTSGet2DANameByType(). This file looks for a module-level string variable, and uses a default if it can't find one.
The variables it looks for are:
(Note that these match the constants uses for the treasure type.)
The default .2da files that will be used are:
Remember that all these files can be found in Data/2da.zip, in your NWN2 programs files ("C:\Program Files\Atari\Neverwinter Nights 2\Data" by default). Extracting the .zip files to your desktop and opening the .2da files in Microsoft Excel, will reveal how these are laid out. For example, looking at the random magic .2da file (des_treas_magic.2da), will show that the low class items are all +1, the medium class items are +1 and +2, and the high class items are +2, +3 and +4. There is also a very high column, which is probably left over from the epic levels in NWN1: HotU.