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.