I'm trying to put this script in my on open event for my chests to have them respawn after a set time.
Currently it works fine except one little glitch. If I do not take anything out of the chest and wait for the timer to reset, the next time I open it I only get an item and no gold.
Also, I would like to add in the % chance of more than one item being generated and make it up to three. I looked inside nw_o2_coninclude and tried adding it myself but no dice. Any help would be most appreciated.
Thanks in advance!
#include "nw_o2_coninclude"
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();
}
}
void main()
{
float fDelay = 60.0;
if (GetLocalInt(OBJECT_SELF,"NW_DO_ONCE") != 0)
{
return;
}
SetLocalInt(OBJECT_SELF,"NW_DO_ONCE",1);
DelayCommand(fDelay,SetLocalInt(OBJECT_SELF,"NW_DO_ONCE",0));
ShoutDisturbed();
FillInventory();
object oLastOpener = GetLastOpener();
// Custom Drop script for low treasure.
int nDrop = d100(1);
int nWhich = d100(1);
int nRandomize = Random( Random( GetTimeMillisecond() +1) +1); // This makes the random number function behave randomly.
int nMinGPDrop = 10; // Minimum amount of gold to drop.
int nMaxGPDrop = 25; // Maximum amount of gold to drop.
int nGPDrop = Random( nMaxGPDrop -nMinGPDrop +1) +nMinGPDrop;
if (nDrop<100) //or whatever % you want
{
CreateItemOnObject( "nw_it_gold001", OBJECT_SELF, nGPDrop);
}
int nDropChance = d20(1);
int nWhichItem = d20(1);
if (nDropChance<100) //% CHANCE OF DROP
{
switch(nWhichItem)
{
// LOW TREASURE TABLE
case 1: CreateItemOnObject("nw_wamar001");
break;
case 2: CreateItemOnObject("nw_wambo001");
break;
case 3: CreateItemOnObject("nw_wambu001");
break;
case 4: CreateItemOnObject("nw_aarcl011");
break;
case 5: CreateItemOnObject("nw_aarcl005");
break;
case 6: CreateItemOnObject("nw_aarcl009");
break;
case 7: CreateItemOnObject("nw_aarcl001");
break;
case 8: CreateItemOnObject("nw_aarcl002");
break;
case 9: CreateItemOnObject("nw_aarcl012");
break;
case 10: CreateItemOnObject("x0_armhe005");
break;
case 11: CreateItemOnObject("nw_wbwmsl001");
break;
case 12: CreateItemOnObject("nw_it_mring024");
break;
case 13: CreateItemOnObject("nw_it_mring012");
break;
case 14: CreateItemOnObject("nw_wbwmsh002");
break;
case 15: CreateItemOnObject("nw_wbwmxl002");
break;
case 16: CreateItemOnObject("nw_wbwmxh002");
break;
case 17: CreateItemOnObject("nw_wbwmln002");
break;
case 18: CreateItemOnObject("nw_wmgwn006");
break;
case 19: CreateItemOnObject("nw_wmgwn013");
break;
case 20: CreateItemOnObject("x0_it_mring002");
break;
}
}
}