I would like this script to roll a 1d4 on open and generate qty of item 1 to 4 of item. Right now it always defaults to 1. Look at lines 25, 26 (int iResult). What SHOULD I do here?
// Refilling Chest - Used in OnOpen for the Chest in question
//
// This script causes a chest to refill its contents after a predetermined
// amount of time without recreating itself and destroying the original chest.
//
// -Aviston-
#include “NW_O2_CONINCLUDE”
// This function is called from main() to refill the chests contents. You
// will have to manually make a CreateItemObject() for each object you want
// replaced in the chest.
void FillInventory()
{
object oObject = GetFirstItemInInventory();
// First, do a while loop to destroy any contents that the chest might
// contain
while (oObject != OBJECT_INVALID)
{
DestroyObject(oObject);
oObject = GetNextItemInInventory();
}
// Next, recreate the items you wish the chest to contain. Change the
// blueresref to whatever you wish. You can add as many CreateItemOnObject
// calls as you want and/or the chest’s inventory can hold.
// Roll the dice
int iResult = d4();
CreateItemOnObject(“psalthyrellafung”, OBJECT_SELF, iResult);
}
void main()
{
// Check to see if NW_DO_ONCE is set to 0, if it isn’t, do nothing
if (GetLocalInt(OBJECT_SELF,“NW_DO_ONCE”) != 0)
return;
// Set the respawn_counter to 0, this is used by the OnHeartbeat script
// to decide when it’s time to respawn
SetLocalInt(OBJECT_SELF, “respawn_counter”, 0);
// Set the NW_DO_ONCE variable to 1 to indicate it has now been opened and
// needs to start waiting for a respawn
SetLocalInt(OBJECT_SELF,“NW_DO_ONCE”,1);
ShoutDisturbed();
// If we’ve made it this far, we can now safely repopulate the chest’s
// inventory
FillInventory();
}