Alangara_PRC8/_module/nss/ke_randomchest3.nss
Jaysyn904 86feb9ca6f Initial commit
Initial commit.
2024-06-05 21:21:06 -04:00

113 lines
3.4 KiB
Plaintext

void EmptyChest(object oTarget)
{
object oItem = GetFirstItemInInventory(oTarget);
do{
SetPlotFlag(oItem, FALSE);
DestroyObject(oItem, 0.0);
}
while((oItem = GetNextItemInInventory(oTarget)) != OBJECT_INVALID);
}
void CreateObjects(object oSelf)
{
string sItem;
int nRandom;
int nNumOfItems = 0;
int nCounter = 1;
int nPercentage = Random(100) + 1;
/*
Percentage rolls moved here for easy editing
If a 25 or lower is rolled, 3 items are spawned (25%)
If a 50 or lower is rolled, 2 items are spawned (50%)
Otherwise, 1 item is spawned
*/
if (nPercentage <= 25)
nNumOfItems = 3;
else if (nPercentage <= 50)
nNumOfItems = 2;
else if (nPercentage <= 100)
nNumOfItems = 1;
while (nCounter <= nNumOfItems)
{
nRandom = Random(49) + 1;// Edit the number in () to how many cases. Leave +1
switch (nRandom)
{ // Put a case and the tag of each item to be spawned.
case 1: sItem = "it_mpotion003"; break;
case 2: sItem = "it_mpotion008"; break;
case 3: sItem = "it_mpotion011"; break;
case 4: sItem = "it_mpotion024"; break;
case 5: sItem = "it_mpotion020"; break;
case 6: sItem = "it_mpotion017"; break;
case 7: sItem = "it_mpotion014"; break;
case 8: sItem = "it_mpotion003"; break;
case 9: sItem = "it_mpotion008"; break;
case 10: sItem = "it_mpotion011"; break;
case 11: sItem = "it_mpotion024"; break;
case 12: sItem = "it_mpotion020"; break;
case 13: sItem = "it_mpotion017"; break;
case 14: sItem = "it_mpotion014"; break;
case 15: sItem = "potionofblessing"; break;
case 16: sItem = "potionofprayer"; break;
case 17: sItem = "it_mpotion003"; break;
case 18: sItem = "it_mpotion008"; break;
case 19: sItem = "it_mpotion011"; break;
case 20: sItem = "it_mpotion024"; break;
case 21: sItem = "it_mpotion020"; break;
case 22: sItem = "it_mpotion017"; break;
case 23: sItem = "it_mpotion014"; break;
case 24: sItem = "potionofblessing"; break;
case 25: sItem = "potionofprayer"; break;
case 26: sItem = "it_mpotion003"; break;
case 27: sItem = "it_mpotion008"; break;
case 28: sItem = "it_mpotion011"; break;
case 29: sItem = "it_mpotion024"; break;
case 30: sItem = "it_mpotion020"; break;
case 31: sItem = "it_mpotion017"; break;
case 32: sItem = "magmapotion"; break;
case 33: sItem = "criticalresist"; break;
case 34: sItem = "damageresist"; break;
case 35: sItem = "criticalresist"; break;
case 36: sItem = "criticalresist"; break;
case 37: sItem = "damageresist"; break;
case 38: sItem = "damageresist"; break;
case 39: sItem = "magmapotion"; break;
case 40: sItem = "magmapotion"; break;
case 41: sItem = "it_mpotion014"; break;
case 42: sItem = "potionofblessing"; break;
case 43: sItem = "potionofprayer"; break;
case 44: sItem = "7500gold"; break;
case 45: sItem = "5000gold"; break;
case 46: sItem = "5000gold"; break;
case 47: sItem = "5000gold"; break;
case 48: sItem = "7500gold"; break;
case 49: sItem = "10000gold"; break;
default: break;
}
CreateItemOnObject(sItem, oSelf, 1);//Creates the item(s) into chest.
nCounter++;
}
}
void main()
{
object oChest = OBJECT_SELF;
object oItem = GetFirstItemInInventory(oChest);
float fDelay = 3600.0f;//Delay in seconds to reloot the chest.
if (GetLocalInt(oChest,"doonce") == 0)
{
EmptyChest(oChest);//Empties the chest from any left overs
CreateObjects(oChest);
SetLocalInt(oChest,"doonce",1);
DelayCommand(fDelay, SetLocalInt(oChest,"doonce",0));
}
else if (oItem == OBJECT_INVALID)
{
SendMessageToPC(GetLastOpenedBy() , "This chest has been emptied recently." );
}
else
{
SendMessageToPC(GetLastOpenedBy() , "This chest has been used recently." );
}
}