NWN: Random Treasure Question

sineater

First Post
When making your own module can you make it so that treasure chests or anything else have a random treasure in it? That way if you play the module again the treasure will be different.
 

log in or register to remove this ad

I'm sure you can... hold on while I check Chapter 1 of the game, I'm sure I can find out how there. I personally haven't done anything with dungeon/treasure creation yet, so it'll be a learning experience for me as well. Besides, I have something else I want to look up anyway...

Alright, I checked the script, and it looks pretty complex. The good news is I'm pretty sure it's available to include in any module.

The random treasure generation script is named nw_o2_coninclude (from here on, refered to as coninclude). You can take a look at that from the script wizard. Basically, there's a bunch of treasure generation functions. If you have custom items that you want to randomly appear, you'll need to add them to this script. There's also a function called ShoutDisturbed() which alerts anyone guarding the chest it has been opened (read the comments in this section if you can, it's highly amusing, but educational). I'm hoping to get a complete documentation of functions in this script up by Monday.

What you would do from here is create the chest, and then use a function to call one of the functions in coninclude. This function should be referenced in the OnDeath and OnOpen events for the chest.

The example below is a function named nw_o2_generalmed. The two functions GenerateMediumTreasure() and ShoutDisturbed() are from coninclude. Comments inserted by me.

Code:
// includes coninclude so functions can be called
#include "NW_O2_CONINCLUDE"

void main()
{

    // Check to see if the chest has already been opened
    if (GetLocalInt(OBJECT_SELF,"NW_DO_ONCE") != 0)
    {
       return;
    }

    // Get the PC who opened the chest
    object oLastOpener = GetLastOpener();

    // Generate treasure in the chest based on the PC who opened it
    GenerateMediumTreasure(oLastOpener, OBJECT_SELF);

    // Set a variable that teh chest has been opened 
    SetLocalInt(OBJECT_SELF,"NW_DO_ONCE",1);

    // Let guards know the chest has been opened
    ShoutDisturbed();
}
 
Last edited:

Remove ads

Top