Random treasure

Random Treasure
put this script on On Open and OnDestroyed.

//sChest = string SourceChest tag //oChest = Object Destination Chest // grab random object from source Chest // and create a copy of it in Destination chest // the source chests are in the Dungeon Master's Palace // and have unique names void MakeTreasure(string sChest,object oChest){ int nCountItems; int nRandomItem; object oSource; object oItem; string sResRefItem; oSource = GetObjectByTag(sChest); if(!GetIsObjectValid(oSource))return; //count item logic oItem=GetFirstItemInInventory(oSource); nCountItems = 0; while(GetIsObjectValid(oItem)){ nCountItems++; oItem=GetNextItemInInventory(oSource); } //now get random item nRandomItem=Random(nCountItems)+1; oItem=GetFirstItemInInventory(oSource); while(nRandomItem>1){ nRandomItem--; oItem=GetNextItemInInventory(oSource); } sResRefItem = GetResRef(oItem); CreateItemOnObject(sResRefItem,oChest); }

void main {  object oThisChest = OBJECT_SELF; location lThisChest = GetLocation(oThisChest); float fDelay = 10.0; // delay in seconds int nFlag= 0; string sSourceChest; // Source of Treasure nFlag = GetLocalInt(oThisChest, "Used"); sSourceChest = GetLocalString(GetArea(oThisChest),"SourceChest"); if(nFlag > 0) return; // timer in progress //2 pieces of junk, 1 good item //obviously chests with these tags apear in the //Dungeon Masters Palace and have the appropriate //items in them MakeTreasure("cgchestjunk",oThisChest); if(d2 > 1 ) MakeTreasure("cgchestjunk",oThisChest); if(d3 > 1 ) MakeTreasure(sSourceChest,oThisChest); //MakeTreasure("cgchest3",oThisChest); SetLocalInt(oThisChest,"Used",1); // this chest has been // used already, don't do it again

}

How It Works
Build a special area that no player has access too. Load it up with a junk chest, called "cgchestjunk" as it's tag, oddly enough, and a whole wack of other chests. One chest for each area, ,more or less. The tags on these chests must be unique across your entire module, by the way.

go to some area you just created. Go to properties, the advanced tab, variables. Put in the variable "SourceChest" and the tag of one of those chests.

The above script will read the source chest variable from the area it happens to be sitting in, and randomly pick an item from it (and 1-2 items from the junk chest).

So all you gotta do is populate the junk chest and a couple of chests with whatever you think is appropriate for that area.

You changed your mind about what you want available in that area ? Just open up the inventory for the source chest and change the items around.

Works great for dumping those annoying books about Port Llast, and for puting your own "custom" items on the treasure lists to be found in chests.