Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Object Inventory Organizing Functions!

Christopher Omega
Oxymoron
Join date: 28 Mar 2003
Posts: 1,828
08-20-2003 00:11
CODE

list INVENTORY_CONSTANTS = [INVENTORY_TEXTURE, INVENTORY_SOUND, INVENTORY_OBJECT, INVENTORY_SCRIPT, INVENTORY_LANDMARK, INVENTORY_CLOTHING, INVENTORY_NOTECARD, INVENTORY_BODYPART];


CODE

integer totalInventory() //Returns the total number of object contents.
{
integer ret;
integer i;
for(i = 0; i < llGetListLength(INVENTORY_CONSTANTS); i++)
{
ret += llGetInventoryNumber(llList2Integer(INVENTORY_CONS
TANTS,i));
}
return ret;
}


CODE
cleanInventoryWExclusion(list exclusions, list stuff2keep)
//Cleans out inventory excluding inventory constants (INVENTORY_TEXTURE, etc...) defined in exclusions, and inventory item names defined in stuff2keep.
//Pass two empty lists to clean out all object inventory except task.
{
if(llListFindList(stuff2keep,[llGetScriptName()]) == -1) {stuff2keep += llGetScriptName();}

integer i;
for(i = 0; i < llGetListLength(INVENTORY_CONSTANTS); i++)
{
integer constant = llList2Integer(INVENTORY_CONSTANTS,i);
if(llListFindList(exclusions,[constant]) == -1)
{
integer j;
for(j = llGetInventoryNumber(constant) - 1; j >= 0; j--)
{
string name = llGetInventoryName(constant,j);
if(llListFindList(stuff2keep,[name]) == -1) {llRemoveInventory(name);}
}
}
}
}


CODE

integer getInventoryType(string inventory) //Returns the type of inventory (an integer value) defined by the inventory argument.
{
if(llGetInventoryKey(inventory) == NULL_KEY) return -1;
else
{
integer i;
for(i = 0; i < llGetListLength(INVENTORY_CONSTANTS); i++)
{
integer constant = llList2Integer(INVENTORY_CONSTANTS,i);
integer j;
for(j = 0; j < llGetInventoryNumber(constant); j++)
{
if(inventory == llGetInventoryName(constant,j)) return constant;
}
}
}
return -1;
}



Special thanks to Madox and Ironchef for help with debugging these functions. :)

-Chris

Note #1: The INVENTORY_CONTENTS global list is required in scripts that use these functions; the functions wont... function... without it.

Note #2: If you only decide to use 1 of these functions, feel free to move the global variable INVENTORY_CONTENTS into the function as a local function variable, which frees up script memory.
_____________________
October 3rd is the Day Against DRM (Digital Restrictions Management), learn more at http://www.defectivebydesign.org/what_is_drm
Christopher Omega
Oxymoron
Join date: 28 Mar 2003
Posts: 1,828
Heres another:
08-21-2003 18:59
CODE

list getInventoryDirectory() //returns list, in strides of 2 elements, the first the inventory name, and the second the type of inventory. WARNING: this function may stack-heap when you have more then 200 items in inventory.
{
list ret;

integer j;
for(j = 0; j < llGetListLength(INVENTORY_CONSTANTS); j++)
{
integer constant = llList2Integer(INVENTORY_CONSTANTS,j);
{
integer k;
for(k = 0; k < lllGetInventoryNumber(constant); k++)
{
string name = llGetInventoryName(constant,k);
ret += name;
ret += constant;
}
}
}
return ret;
}


NOTE: this is untested, it might not work.

-Chris
_____________________
October 3rd is the Day Against DRM (Digital Restrictions Management), learn more at http://www.defectivebydesign.org/what_is_drm