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.