Hey guys, I ran across this thread by accident and decided to rework the script to allow for toggling of script delete and also allowing for input of a specific list of items NOT to delete. It's heavily commented for those who'd like to know how I made this. Hope you enjoy~
//Name: Clear Inventory w/ Item Ignore
//Desc: short script that will erase everything in the contents of an object besides
//for a list of objects and the script itself if "delete_this_script = FALSE"
//Author: Yosef Enoch
//Date: Feb 11, 2009
//USER SETTINGS - Edit these settings to suit your needs.
integer delete_this_script = FALSE; //set this to TRUE or FALSE
list dont_delete_these = ["item1", "item2", "item3"]; //list of items NOT to delete
//DO NOT EDIT BELOW HERE UNLESS YOU'RE INTERESTED IN EXPERIMENTING
clearInventory(){
//notify user that action is being taken.
llSay(0, "Clearing Inventory!"

;
//create a variable with the total number of inventory items
//this number will be decreased later throughout the loop.
integer total_inv = llGetInventoryNumber(INVENTORY_ALL);
//if the total number is more than 1, that means there is something besides the script
//so we cycle through, otherwise we we skip to the last part and delete this script.
if(total_inv > 1){
//add script name to list of things not to delete, since even if we do delete this,
//it won't be till the very end.
//Using "

some_list = []) + some_list +" instead of "some_list +"
//reduces memory fragmentation.
dont_delete_these = (dont_delete_these = []) + dont_delete_these + llGetScriptName();
//loop through all inventory names, starting with the highest number (last item)
//and ending with the first item. loops as long as we are not at 0 items.
while(total_inv > 0){
//adding the current item to a string. we use (total_inv - 1) since the
//inventory index starts at 0 so 0 is the first item, 1 is the second item and so on
string current_item = llGetInventoryName(INVENTORY_ALL, total_inv - 1); //
//search the don_delete_these list for the current item and remove the current item
//only if llListFindList returns -1 which means it can't be found on the list.
if(llListFindList(dont_delete_these, [current_item]) == -1){
llRemoveInventory(current_item);
}
//decrease the inventory number to go to the next item.
//very important to prevent the loop from going forever.
--total_inv;
}
}
//if we set delete_this_script to true, delete the script
//if(delete_this_script == TRUE) is the same as if(delete_this_script)
if(delete_this_script){
llRemoveInventory(llGetScriptName());
}
}
default
{
state_entry(){
llSay(0, "Touch me to clear inventory"

;
}
touch_start(integer num_detected){
//on touch start, clear the inventory.
clearInventory();
}
}