Unpacker On Rez (NewAge)

From Second Life Wiki
Revision as of 11:14, 18 October 2012 by Kireji Haiku (talk | contribs) (some minor improvements)
Jump to navigation Jump to search

NewAge Auto Unpacker v1.1

Just copy and paste this script into your object that will contain your product and configure the few lines in // Configure; section

<lsl> // NewAge Auto Unpacker Script // By Asia Snowfall string nameOfFolderToBeCreated; string messageToSendUponRez; integer addThisScriptToFolder; integer typeOfInventoryItemsToBeSent; integer killAfterCompletion;

init() { // do not use an empty string

   nameOfFolderToBeCreated = llGetObjectName();

// leave empty to not send a message upon rez

   messageToSendUponRez = "";

// use INVENTORY_ALL to not apply a filter

   typeOfInventoryItemsToBeSent = INVENTORY_ALL;
   addThisScriptToFolder = FALSE;
   killAfterCompletion = TRUE;

}

try_to_send_items(key inputKey, integer inputType) {

   integer numberOfItems = llGetInventoryNumber(inputType);
   string thisScript = llGetScriptName();
   string itemName;
   list listOfItemsToSend;
   integer i;
   do
   {
       itemName = llGetInventoryName(inputType, i);
       if(itemName != "")
       {
           if(addThisScriptToFolder && itemName == thisScript)
               listOfItemsToSend += [itemName];
           else if(itemName != thisScript)
               listOfItemsToSend += [itemName];
       }
   }
   while(++i < numberOfItems);

// change to number of items in list now

   numberOfItems = llGetListLength(listOfItemsToSend);
   if(numberOfItems)
   {
       llGiveInventoryList(inputKey, nameOfCreatedFolder, listOfItemsToSend);
       llInstantMessage(inputKey,
                   "/me [" + thisScript + "]: Items have been sent into a folder named '"
                   + nameOfFolderToBeCreated + "' within your inventory.");
   }
   else
       llInstantMessage(inputKey,
           "/me [" + thisScript + "]: Could not find inventory items to send!");

}

default {

   on_rez(integer start_param)
   {
       key owner = llGetOwner();
       if (messageToSendUponRez != "")
           llInstantMessage(owner, messageToSendUponRez);
       try_to_send_items(owner, typeOfInventoryItemsToBeSent);
       if (killAfterCompletion)
           llDie();
   }

} </lsl>