Author Topic: Will this script work for respawning loot in a container?  (Read 431 times)

Legacy_SuperFly_2000

  • Hero Member
  • *****
  • Posts: 1292
  • Karma: +0/-0
Will this script work for respawning loot in a container?
« on: November 02, 2010, 01:41:43 am »


               

// Treasure OnClose script
//::////////////////////////////////////
#include "x0_i0_treasure"
const float RESTOCK_TREASURE_DELAY = 900.0; // How long until <span class="highlight">chest</span> will <span class="highlight"><span class="highlight">respawn</span></span> treasure (in seconds).
void DestroyChestContents()
{ object oItem = GetFirstItemInInventory();
  while( GetIsObjectValid( oItem))
  { DestroyObject( oItem, (GetHasInventory( oItem) ? 0.2 : 0.1));
    oItem = GetNextItemInInventory();
  }
}
void main()
{
  DelayCommand(60.0, DestroyChestContents());
  DelayCommand( RESTOCK_TREASURE_DELAY +0.01, CTG_SetIsTreasureGenerated( OBJECT_SELF, FALSE));
}

Got it from Pattycake a long time ago.

So I'll be putting this script on the OnCLosed event...

and the usual scripts for generating treasure on the OnOpen even.

(different ones.. such that start with
x0_
x2_
nw_
)
               
               

               
            

Legacy_SuperFly_2000

  • Hero Member
  • *****
  • Posts: 1292
  • Karma: +0/-0
Will this script work for respawning loot in a container?
« Reply #1 on: November 02, 2010, 11:44:13 pm »


               *bump*
               
               

               
            

Legacy_Olblach

  • Newbie
  • *
  • Posts: 14
  • Karma: +0/-0
Will this script work for respawning loot in a container?
« Reply #2 on: November 03, 2010, 01:09:40 am »


               That looks good, you can test if it works by changing the 900 into 9 and the 60 into a 6. That way you don't have to wait 15 minutes until something happens!
               
               

               
            

Legacy_Builder_Anthony

  • Hero Member
  • *****
  • Posts: 786
  • Karma: +0/-0
Will this script work for respawning loot in a container?
« Reply #3 on: November 03, 2010, 01:40:52 am »


               Silicon scouts treasure dystem
               
               

               
            

Legacy_SuperFly_2000

  • Hero Member
  • *****
  • Posts: 1292
  • Karma: +0/-0
Will this script work for respawning loot in a container?
« Reply #4 on: November 03, 2010, 12:03:45 pm »


               Can I add something to the script so that it puts a lock and/or trap back on the chest/container?

I know it is easy for doors. I can close doors after a certain amount...and re-lock them...


Spin off question: If not I guess I would have to put a door in before you reach the chest..so I know how to close and re-lock the door...but how to "re-trap" it?

Edit: Actually we have this also Sir Elric's Random Respawning Traps v2.7 but shouldn't there be an even easier way?
               
               

               


                     Modifié par SuperFly_2000, 03 novembre 2010 - 12:17 .
                     
                  


            

Legacy_Baragg

  • Sr. Member
  • ****
  • Posts: 496
  • Karma: +0/-0
Will this script work for respawning loot in a container?
« Reply #5 on: November 03, 2010, 02:50:17 pm »


               This should work for a trap on the chest:




// Creates a Trap on the object specified.
// - nTrapType: The base type of trap (TRAP_BASE_TYPE_*)
// - oObject: The object that the trap will be created on. Works only on Doors and Placeables.
// - nFaction: The faction of the trap (STANDARD_FACTION_*).
// - sOnDisarmScript: The OnDisarm script that will fire when the trap is disarmed.
//                    If "" no script will fire.
// - sOnTrapTriggeredScript: The OnTrapTriggered script that will fire when the
//                           trap is triggered.
//                           If "" the default OnTrapTriggered script for the trap
//                           type specified will fire instead (as specified in the
//                           traps.2da).
// Note: After creating a trap on an object, you can change the trap's properties
//       using the various SetTrap* scripting commands by passing in the object
//       that the trap was created on (i.e. oObject) to any subsequent SetTrap* commands.
void CreateTrapOnObject(int nTrapType, object oObject, int nFaction=STANDARD_FACTION_HOSTILE, string sOnDisarmScript="", string sOnTrapTriggeredScript="")



I added an average holy trap to your script delayed just a hair more than the restocking delay:




// Treasure OnClose script
//::////////////////////////////////////
#include "x0_i0_treasure"
const float RESTOCK_TREASURE_DELAY = 900.0; // How long until <span class="highlight">chest</span> will <span class="highlight"><span class="highlight">respawn</span></span> treasure (in seconds).
void DestroyChestContents()
{ object oItem = GetFirstItemInInventory();
  while( GetIsObjectValid( oItem))
  { DestroyObject( oItem, (GetHasInventory( oItem) ? 0.2 : 0.1));
    oItem = GetNextItemInInventory();
  }
}
void main()
{
  DelayCommand(60.0, DestroyChestContents());
  DelayCommand( RESTOCK_TREASURE_DELAY +0.01, CTG_SetIsTreasureGenerated( OBJECT_SELF, FALSE));
  DelayCommand( RESTOCK_TREASURE_DELAY +0.02, CreateTrapOnObject(TRAP_BASE_TYPE_AVERAGE_HOLY,
  OBJECT_SELF));
}

               
               

               
            

Legacy_Baragg

  • Sr. Member
  • ****
  • Posts: 496
  • Karma: +0/-0
Will this script work for respawning loot in a container?
« Reply #6 on: November 03, 2010, 02:53:55 pm »


               Here it is with locking:


// Treasure OnClose script
//::////////////////////////////////////
#include "x0_i0_treasure"
const float RESTOCK_TREASURE_DELAY = 900.0; // How long until chest will respawn treasure (in seconds).
void DestroyChestContents()
{ object oItem = GetFirstItemInInventory();
  while( GetIsObjectValid( oItem))
  { DestroyObject( oItem, (GetHasInventory( oItem) ? 0.2 : 0.1));
    oItem = GetNextItemInInventory();
  }
}
void main()
{
  DelayCommand(60.0, DestroyChestContents());
  DelayCommand( RESTOCK_TREASURE_DELAY +0.01, CTG_SetIsTreasureGenerated( OBJECT_SELF, FALSE));
  DelayCommand(RESTOCK_TREASURE_DELAY +0.02, SetLocked(OBJECT_SELF, TRUE));    DelayCommand(RESTOCK_TREASURE_DELAY+0.03,CreateTrapOnObject(TRAP_BASE_TYPE_AVERAGE_HOLY,
  OBJECT_SELF));
}

               
               

               


                     Modifié par Baragg, 03 novembre 2010 - 02:55 .
                     
                  


            

Legacy_SuperFly_2000

  • Hero Member
  • *****
  • Posts: 1292
  • Karma: +0/-0
Will this script work for respawning loot in a container?
« Reply #7 on: November 03, 2010, 07:18:09 pm »


               That looks cool...thanks a lot.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Will this script work for respawning loot in a container?
« Reply #8 on: November 05, 2010, 01:14:38 am »


               

Baragg wrote...

Here it is with locking:


// Treasure OnClose script
//::////////////////////////////////////
#include "x0_i0_treasure"
const float RESTOCK_TREASURE_DELAY = 900.0; // How long until chest will respawn treasure (in seconds).
void DestroyChestContents()
{ object oItem = GetFirstItemInInventory();
  while( GetIsObjectValid( oItem))
  { DestroyObject( oItem, (GetHasInventory( oItem) ? 0.2 : 0.1));
    oItem = GetNextItemInInventory();
  }
}
void main()
{
  DelayCommand(60.0, DestroyChestContents());
  DelayCommand( RESTOCK_TREASURE_DELAY +0.01, CTG_SetIsTreasureGenerated( OBJECT_SELF, FALSE));
  DelayCommand(RESTOCK_TREASURE_DELAY +0.02, SetLocked(OBJECT_SELF, TRUE));    DelayCommand(RESTOCK_TREASURE_DELAY+0.03,CreateTrapOnObject(TRAP_BASE_TYPE_AVERAGE_HOLY,
  OBJECT_SELF));
}


Just pointing out a side effect in this script that you may not like.  

Bad effect would be as follows. 

PC one opens and closes the chest. 
All Items in the Chest get destroyed 60 sec later. 
870 seconds after the chest was closed PC two opens the chest finds nothing and closes it. 
900 seconds after first open the chest sets itself to regenerate treasure. 
925 seconds after first open PC 3 opens the chest and finds new treasure just to watch it dissapear 5 seconds later. because it is 60 sec after PC 2 closeing the chest.  

The script works. But when the timming of PC opening and closeing the chests happen right you may get complaints of treasure vanishing.  

 
               
               

               
            

Legacy_SuperFly_2000

  • Hero Member
  • *****
  • Posts: 1292
  • Karma: +0/-0
Will this script work for respawning loot in a container?
« Reply #9 on: November 05, 2010, 08:58:21 am »


               Well...there will be monster respawns in the area that have about the same respawn time as the containers/chests...so I shouldn't have any players walking through unspawned monster areas...or at least probably not looting while doing it....but sure...that could happen....



Guess there is no way to minimize this also as this is how the system works right....(?).
               
               

               
            

Legacy_Baragg

  • Sr. Member
  • ****
  • Posts: 496
  • Karma: +0/-0
Will this script work for respawning loot in a container?
« Reply #10 on: November 05, 2010, 08:56:54 pm »


               Here this should catch that snag that Lightfoot8 brought up.


// Treasure OnClose script
//::////////////////////////////////////
#include "x0_i0_treasure"
const float RESTOCK_TREASURE_DELAY = 900.0; // How long until chest will respawn treasure (in seconds).

void DestroyChestContents(object oChest = OBJECT_SELF)
{ object oItem = GetFirstItemInInventory(oChest);
  while( GetIsObjectValid( oItem))
  { DestroyObject( oItem, (GetHasInventory( oItem) ? 0.2 : 0.1));
    oItem = GetNextItemInInventory();
  }
}

void RebootTreasure(object oChest)
{
  CTG_SetIsTreasureGenerated( oChest, FALSE);
  SetLocked(oChest, TRUE);
  CreateTrapOnObject(TRAP_BASE_TYPE_AVERAGE_HOLY, oChest);
  SetLocalInt(oChest, "RESET_TREASURE", 0);
}
void main()
{
  int nCheck = GetLocalInt(OBJECT_SELF, "RESET_TREASURE");
  if(nCheck == 1) return;
  else
  {
   SetLocalInt(OBJECT_SELF, "RESET_TREASURE", 1);
   DelayCommand(60.0, DestroyChestContents(OBJECT_SELF));
   DelayCommand(RESTOCK_TREASURE_DELAY, RebootTreasure(OBJECT_SELF));
  }
}

At least I hope my thinking is right on that.
               
               

               


                     Modifié par Baragg, 05 novembre 2010 - 08:58 .