| Author |
Sticky: Post
Working Scripts Here |
| Aviston
|
Posted: Monday, 01 July 06:08AM |
This is a script for a chest that refills
its inventory after a set period of time. I believe the popular way of
doing this as of now is to destroy the chest and respawn it. With this
script, the original chest remains in tack and just its contents are
destroyed and refilled. It will also allow a creature to spawn the first
time the chest is opened after it has been reset.
There are a few things that must be edited in order for it to work
properly. First, the value must be changed to how many heartbeats you
want to wait before the chest resets (the default is 6). Second, you
must change the CreateItemOnObject() in the OnOpen script to reflect the
item you want to clone (and add more function calls to
CreateItemOnObject() if you want the chest to contain more than one
item). Lastly, you must uncomment the CreateObject() call in the OnOpen
script and modify it to reflect the creature you want to clone if you
want a creature to spawn. I have added comments throughout the code so
these things should be quite easy to find.
First, the OnHeartbeat script:
NWScript:
void main()
{
if (GetLocalInt(OBJECT_SELF, "NW_DO_ONCE") == 0)
return;
int nCounter = GetLocalInt(OBJECT_SELF, "respawn_counter");
nCounter++;
SetLocalInt(OBJECT_SELF, "respawn_counter", nCounter);
if (nCounter > 6)
SetLocalInt(OBJECT_SELF, "NW_DO_ONCE", 0);
}
Next, the OnOpen script:
NWScript:
#include "NW_O2_CONINCLUDE"
void FillInventory()
{
object oObject = GetFirstItemInInventory();
while (oObject != OBJECT_INVALID)
{
DestroyObject(oObject);
oObject = GetNextItemInInventory();
}
CreateItemOnObject("NW_WAXHN001");
}
void main()
{
if (GetLocalInt(OBJECT_SELF,"NW_DO_ONCE") != 0)
return;
SetLocalInt(OBJECT_SELF, "respawn_counter", 0);
SetLocalInt(OBJECT_SELF,"NW_DO_ONCE",1);
ShoutDisturbed();
FillInventory();
}
|
|