Author Topic: Random Loot Generation Script Help  (Read 375 times)

Legacy_Shiek2005

  • Full Member
  • ***
  • Posts: 179
  • Karma: +0/-0
Random Loot Generation Script Help
« on: August 15, 2011, 06:07:04 am »


               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 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Random Loot Generation Script Help
« Reply #1 on: August 15, 2011, 06:38:43 am »


               Just add the same Timmer I Gave you in the other post. Just set the local on the chest instead of the PC. 

ex.  

 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"

const int nMinDelay = 30;
void main()
{

  int iMinPerHour = FloatToInt(HoursToSeconds(1)/60);
  int nTStamp =    GetTimeHour()
                 + (GetCalendarDay()-1) * 24
                 + (GetCalendarMonth()-1) * 672
                 +  GetCalendarYear() * 8064;
      nTStamp = nTStamp* iMinPerHour +  GetTimeMinute();

   if ( GetLocalInt(OBJECT_SELF,"tStamp") > nTStamp ) return;

   SetLocalInt(OBJECT_SELF,"tStamp", nTStamp + nMinDelay);


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);
}
}


               
               

               


                     Modifié par Lightfoot8, 15 août 2011 - 05:40 .
                     
                  


            

Legacy_Shiek2005

  • Full Member
  • ***
  • Posts: 179
  • Karma: +0/-0
Random Loot Generation Script Help
« Reply #2 on: August 15, 2011, 05:26:17 pm »


               Thanks, i'll give it a try ^.^

Yup, works, thanks again:happy:
               
               

               


                     Modifié par Shiek2005, 15 août 2011 - 04:42 .
                     
                  


            

Legacy_Fester Pot

  • Hero Member
  • *****
  • Posts: 1698
  • Karma: +0/-0
Random Loot Generation Script Help
« Reply #3 on: August 15, 2011, 05:47:40 pm »


               Loot generation timer scripts should be tied into the area being empty and restocked when the entire dungeon is respawned - monsters and traps - to avoid players from staying in a dungeon waiting for the timers to expire, thus relooting chests without any risk to themselves simply by camping.

You can make rules about it all you want but not every DM is interested in policing dungeons to keep an eye out for this.

FP!
               
               

               
            

Legacy_Shiek2005

  • Full Member
  • ***
  • Posts: 179
  • Karma: +0/-0
Random Loot Generation Script Help
« Reply #4 on: August 16, 2011, 06:34:22 am »


               Thanks for the suggestion, my project is a Multiplayer module, not a PW, so that sort-of behaviour shouldn't be something very major. Also, i find it hard to believe someone would simply camp for an hour or two to wait for treasure respawns '<img'> Though i don't doubt a few players like that might exist.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Random Loot Generation Script Help
« Reply #5 on: August 17, 2011, 04:01:20 am »


               Sometimes the Camping is logging out next to a chest.  Logging back, in a few hours, Jut to get the loot and log back out.