PoA_PRC8/_module/nss/iorganize.nss
Jaysyn904 8d97886c3f Changed folder name.
Changed folder name.
2022-10-07 21:08:37 -04:00

125 lines
2.8 KiB
Plaintext

//Script Name: iorganize
//////////////////////////////////////////
//Created by: Genisys / Guile
//ON: 7/28/08
/////////////////////////////////////////
/* **Notes**
This script is fired from an OnActivateItem
script, which had to be seperated to prevent
crashing, due to resource intensive loops
and advanced scripting.
*/
////////////////////////////////////////
////NOTE: There is an error in this script when they have more than
////8 items in their inventory, and the items in bags are not being
////taken out of the bags!!! (TOO MANY INSTRUCTIONS ERROR)
//PROTOTYPE (DEFINED)
void RemoveBags()
{
object oCan = GetObjectByTag("ibox");
object oThis;
oThis = GetFirstItemInInventory(oCan);
while(GetIsObjectValid(oThis)==TRUE)
{
//We need to destroy all of the containers inside the box!
if(GetHasInventory(oThis))
{
DestroyObject(oThis,0.0f);
}
//Keep going till we get all of the bags..
oThis = GetNextItemInInventory(oCan);
//Loop End
}
//End Prototype
}
///PROTOTYPE (DEFINED)
int GetCount()
{
object oIC;
object oBarrel;
oBarrel = GetObjectByTag("ibox");
//Now lets deal with the items in the box now..
int nCount = 0;
//Count the # of total items in the barrel..
oIC = GetFirstItemInInventory(oBarrel);
while(GetIsObjectValid(oIC)==TRUE)
{
//We need to destroy all of the containers inside the box!
if(GetHasInventory(oIC))
{
//For now just print the string
PrintString("Bag has items");
nCount++;
//DestroyObject(oMine,0.0f);
}
//If it's not a container then add it to the count..
else
{
nCount++; //Increment the count by 1
}
//continue counting till there are no more items to count..
oIC = GetNextItemInInventory(oBarrel);
//While statment / loop end
}
return nCount;
//End Prototype
}
void main()
{
object oPC = OBJECT_SELF;
object oBox = GetObjectByTag("ibox");
object oCon;
object oMine;
int nBags;
//Remove bags from the box FIRST!
RemoveBags();
//This must be defined after bags are destroyed!
int iCount = GetCount();
if(iCount >7)
{ //Assign 8 items / bag (based upon average size of items)
nBags = iCount / 8; //NOTE: This may be too many, I will test first.
}
//Otherwise just give them one bag..
else
{
nBags = 1;
}
//If we only have 8 items or less, try to put them all in one bag!
if(nBags==1)
{
////////NOTE: This works fine (everything organizes)//////
//Create a bag of holding on the player, and give it a new tagname
//Every bag must have it's own unique tagname so we can id them later..
CreateItemOnObject("nw_it_contain006", oPC, 1, "ibag1");
//Now excute this script if they only get 1 bag
DelayCommand(0.5, ExecuteScript("icontain", oPC));
}
//Otherwise excute this script because there are a lot of items!
else
{
DelayCommand(0.5, ExecuteScript("iseperate", oPC));
}
//Script End
}