I got this script set from the vault and it works well enough, except that i'm looking to have my treasure chests reset in X amount of time.
What i'm looking for is for someone to tweak the script so that the chests reset every X mins (this is a multiplayer module where re-visiting areas is encouraged, so i want my containers to generate more treasure every hour for example) or if thats too difficult or complicated, maybe someone can recommend me a similar random treasure generation system that has the option to reset the containers every X amount of time.
For referrence, here's the link to the script set on the vault: nwvault.ign.com/View.php
And the actual scripts:
OnOpen:
//::///////////////////////////////////////////////
//:: FileName rk_vt_onopen
//:: Copyright © 2001 Bioware Corp.
//:://////////////////////////////////////////////
/*
Variable treasure container script
Used on OnOpened and OnDeath event of a container
*/
//:://////////////////////////////////////////////
//:: Created By: Ruel Knudson
//:: Created On: 03/15/2005
//:://////////////////////////////////////////////
#include "rk_inc_treasure"
void main()
{
if (GetLocalInt(OBJECT_SELF,"WasUsed")==TRUE)return;
object oPC = GetLastOpenedBy();
object oSource = GetNearestObject(OBJECT_TYPE_STORE);
object oChest = OBJECT_SELF;
RK_GenerateRandomTreasure(oSource,oChest,oPC);
while (Random(100)<=25)
{
RK_GenerateRandomTreasure(oSource,oChest,oPC);
}
SetLocalInt(OBJECT_SELF,"WasUsed",TRUE);
}
Inc Script:
//::///////////////////////////////////////////////
//:: rk_inc_treasure v1.1
//:: Copyright © 2001 Bioware Corp.
//:://////////////////////////////////////////////
/*
A variable treasure system for use with containers
*/
//:://////////////////////////////////////////////
//:: Created By: Ruel Knudson
//:: Created On: 02/16/2005
//:://////////////////////////////////////////////
////Treasure Generation Steps Used In This Script
/*
1. Identify the treasure source (store).
2. Get Number of items in store.
3. Generate random number 1-number of items in store.
4. Get the item from the chest.
5. Decide if the item should be gold. If not generate the item.
6. If items is gold, determine how much of its value will be given
do this by taking a random d100, add the PC level. This is the
percentage of the value that will be given.
7. Determine if there is a chance to make a new item.
8. If we are still making items go to step 5.
*/
//This Function determines how many objects are in the source.
int RK_GetNumberOfItems(object oSource);
//Gets an object from the source
object RK_GetItem(object oSource);
//Determines if the item is gold.
int RK_DetermineIfGold(int nChance);
//Turns an item into gold
//Amount given is determined by a random percentage of
//the base item's value
void RK_MakeGold(object oItem, object oPC, object oChest);
//This will generate a random treasure item(s) from oSource.
//To use make a shop next to the container.
//Place the items you want to appear randomly in the shop.
//Add more instances of items you want to appear more often.
//Add an variable called "GoldChance" on the store that represents
//the chance the item will become gold instead. If 0 no item will be converted
void RK_GenerateRandomTreasure(object oSource, object oChest, object oPC);
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
int RK_GetNumberOfItems(object oSource)
{
object oItem = GetFirstItemInInventory(oSource);
int nNum;
while (oItem!=OBJECT_INVALID)
{
nNum++;
oItem = GetNextItemInInventory(oSource);
}
return nNum;
}
////////////////////////////////////////////////////////
////////////////////////////////////////////////////////
object RK_GetItem(object oSource)
{
int nNumb = RK_GetNumberOfItems(oSource);
nNumb = Random(nNumb);
int nCount;
object oObject = GetFirstItemInInventory(oSource);
while (oObject!=OBJECT_INVALID)
{
if (nCount==nNumb)return oObject;
nCount++;
oObject = GetNextItemInInventory(oSource); }
return OBJECT_INVALID;
}
////////////////////////////////////////////////////////
////////////////////////////////////////////////////////
int RK_DetermineIfGold(int nChance)
{
if (Random(100)>nChance)return FALSE;
return TRUE;
}
////////////////////////////////////////////////////////
////////////////////////////////////////////////////////
void RK_MakeGold(object oItem, object oPC, object oChest)
{
int nValue = GetGoldPieceValue(oItem);
int nPerc = Random(100)+GetHitDice(oPC);
float fPerc = IntToFloat(nPerc)/100;
float fValue = IntToFloat(nValue)*fPerc;
CreateItemOnObject("nw_it_gold001",oChest,FloatToInt(fValue));
}
////////////////////////////////////////////////////////
////////////////////////////////////////////////////////
void RK_GenerateRandomTreasure(object oSource, object oChest, object oPC)
{
object oItem = RK_GetItem(oSource);
int nChance = GetStoreMaxBuyPrice(oSource);
if (RK_DetermineIfGold(nChance)==TRUE)
{
RK_MakeGold(oItem, oPC, oChest);
return;
}
string sRes = GetResRef(oItem);
int nStack = Random(GetItemStackSize(oItem));
if (nStack<1){nStack=1;}
if (GetLocalInt(oSource,GetTag(oItem))==1)
{DestroyObject(oItem);}
CreateItemOnObject(sRes,oChest,nStack);
}
/////////////////////////////////////////////////
////////////////////////////////////////////////
////////////////////////////////////////////////
void bs_07_CreateLoot(object oCreature)
{
int nChance = GetLocalInt(GetModule(),"MonsterLootDrop");
object oObject;
if (GetLocalInt(oCreature,"NoLoot")==TRUE)return;
//Get the items worn on the arms.
oObject = GetItemInSlot(INVENTORY_SLOT_ARMS,oCreature);
if (oObject!=OBJECT_INVALID)
{
if (Random(100)<= nChance)
{SetDroppableFlag(oObject,TRUE);}
}
//Get the creature's arrows.
oObject = GetItemInSlot(INVENTORY_SLOT_ARROWS,oCreature);
if (oObject!=OBJECT_INVALID)
{
if (Random(100)<= nChance)
{SetDroppableFlag(oObject,TRUE);}
}
//Get the creatures belt item.
oObject = GetItemInSlot(INVENTORY_SLOT_BELT,oCreature);
if (oObject!=OBJECT_INVALID)
{
if (Random(100)<= nChance)
{SetDroppableFlag(oObject,TRUE);}
}
//Take the creature's bolts.
oObject = GetItemInSlot(INVENTORY_SLOT_BOLTS,oCreature);
if (oObject!=OBJECT_INVALID)
{
if (Random(100)<= nChance)
{SetDroppableFlag(oObject,TRUE);}
}
//Take the boots while yer at it.
oObject = GetItemInSlot(INVENTORY_SLOT_BOOTS,oCreature);
if (oObject!=OBJECT_INVALID)
{
if (Random(100)<= nChance)
{SetDroppableFlag(oObject,TRUE);}
}
//Get the creature's bullets.
oObject = GetItemInSlot(INVENTORY_SLOT_BULLETS,oCreature);
if (oObject!=OBJECT_INVALID)
{
if (Random(100)<= nChance)
{SetDroppableFlag(oObject,TRUE);}
}
//Get the clothing item worn.
oObject = GetItemInSlot(INVENTORY_SLOT_CHEST,oCreature);
if (oObject!=OBJECT_INVALID)
{
if (Random(100)<= nChance)
{SetDroppableFlag(oObject,TRUE);}
}
//Get the creature's cloak.
oObject = GetItemInSlot(INVENTORY_SLOT_CLOAK,oCreature);
if (oObject!=OBJECT_INVALID)
{
if (Random(100)<= nChance)
{SetDroppableFlag(oObject,TRUE);}
}
//Get the item worn on the head.
oObject = GetItemInSlot(INVENTORY_SLOT_HEAD,oCreature);
if (oObject!=OBJECT_INVALID)
{
if (Random(100)<= nChance)
{SetDroppableFlag(oObject,TRUE);}
}
//Get the weapon in the sheild hand.
oObject = GetItemInSlot(INVENTORY_SLOT_LEFTHAND,oCreature);
if (oObject!=OBJECT_INVALID)
{
if (Random(100)<= nChance)
{SetDroppableFlag(oObject,TRUE);}
}
//Get the item in the left ring finger.
oObject = GetItemInSlot(INVENTORY_SLOT_LEFTRING,oCreature);
if (oObject!=OBJECT_INVALID)
{
if (Random(100)<= nChance)
{SetDroppableFlag(oObject,TRUE);}
}
//Get the item worn on the neck.
oObject = GetItemInSlot(INVENTORY_SLOT_NECK,oCreature);
if (oObject!=OBJECT_INVALID)
{
if (Random(100)<= nChance)
{SetDroppableFlag(oObject,TRUE);}
}
//Get the item in the main weapon hand.
oObject = GetItemInSlot(INVENTORY_SLOT_RIGHTHAND,oCreature);
if (oObject!=OBJECT_INVALID)
{
if (Random(100)<= nChance)
{SetDroppableFlag(oObject,TRUE);}
}
//Get the item in the right ring finger.
oObject = GetItemInSlot(INVENTORY_SLOT_RIGHTRING,oCreature);
if (oObject!=OBJECT_INVALID)
{
if (Random(100)<= nChance)
{SetDroppableFlag(oObject,TRUE);}
}
//Get the rest of the creature's loot from the main inventory.
oObject = GetFirstItemInInventory(oCreature);
while (oObject!=OBJECT_INVALID)
{
if (Random(100)<= nChance)
{SetDroppableFlag(oObject,TRUE);
oObject = GetNextItemInInventory(oCreature);
}
}
}
void bs_07_MakeNew(object oObject)
{
location lLoc = GetLocation(oObject);
string sRes = GetResRef(oObject);
int nType = GetObjectType(oObject);
CreateObject(nType,sRes,lLoc);
}
Modifié par Shiek2005, 15 août 2011 - 05:11 .