Difference between revisions of "Unpacker On Touch (NewAge)"

From Second Life Wiki
Jump to navigation Jump to search
(Created page with ''''Unpacker On Touch''' Version 1.0 Just Copy and Paste into the object that contains your product and configure the script to your needs! New Motto: Save and Sell! <lsl> ////...')
 
m (<lsl> tag to <source>)
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
'''Unpacker On Touch'''
'''Unpacker On Touch'''
Version 1.0


Just Copy and Paste into the object that contains your product and configure the script to your needs!
Just Copy and Paste into the object that contains your product and configure the script to your needs!
Line 6: Line 5:
New Motto: Save and Sell!
New Motto: Save and Sell!


<lsl>
<source lang="lsl2">
/////////////////////////////////
// NewAge Unpacker On Touch Script
// NewAge Unpacker On Touch Script
// By Asia Snowfall
// By Asia Snowfall
// Version 1.0
string nameOfFolderToBeCreated;
/////////////////////////////////
string messageToSendUponRez;
integer addThisScriptToFolder;
// Configure;
integer typeOfInventoryItemsToBeSent;
integer killAfterCompletion;
string Folder_Name = "New Folder"; // This will be the name of the folder sent to the user
string Show_Name_Of_Folder_On_Completion = "Yes"; // Change to No to not show the folder name when sent
string Show_Name_Message_On_Completion = "Folder will be named <folder>"; // If you have sent Show_Name_Of_Folder_On_Completion to Yes, change this message to however you want, Where you place the tag <folder> is where it will show folder name


string Hover_Text = "Click Me To Unpack Me"; // This text will show above the object to let the user know to click the object
init()
   
{
string Message_On_Touch = "Sending your package now..."; // Message sent when object is rezzed
//  do not use an empty string
   
    nameOfFolderToBeCreated = llGetObjectName();
string Message_On_Sent_Completion = "Your package has been sent to you"; // Message sent when sending is complete
 
//  leave empty to not send a message upon rez
string Send_This_Script_To_Package_Owner = "No"; // Change to yes if you want this script to be sent to the user within the package folder
    messageToSendUponRez = "";
 
string Delete_On_Completion = "Yes"; // Change to no if you don't want the object to delete itself after package is sent
// use INVENTORY_ALL to not apply a filter
    typeOfInventoryItemsToBeSent = INVENTORY_ALL;


string Message_On_Fail_No_Items_To_Send = "Sending Failing, No items to send"; // Will only show if there are no items to send
    addThisScriptToFolder = FALSE;
 
/////////////////////////////////
     killAfterCompletion = TRUE;
integer INVENTORY_TYPE = INVENTORY_ALL;
integer FAIL = FALSE;
/////////////////////////////////
key llGetObjectOwner()
{
     list details = llGetObjectDetails(llGetKey(), [OBJECT_OWNER]);
    return (key)llList2CSV(details);
}
}
 
llSendInventory(key id, integer inventory_type)
try_to_send_items(key inputKey, integer inputType)
{
{
     integer i = 0;
     integer numberOfItems = llGetInventoryNumber(inputType);
     integer items = llGetInventoryNumber(inventory_type);
 
     list to_send;
     string thisScript = llGetScriptName();
     string name;
    string itemName;
     list listOfItemsToSend;
 
     integer i;
     do
     do
     {
     {
         name = llGetInventoryName(inventory_type, i);
         itemName = llGetInventoryName(inputType, i);
         if(llStringLength(name) > 0)
 
         if(itemName != "")
         {
         {
             if(name == llGetScriptName() && llToLower(Send_This_Script_To_Package_Owner) == "yes")
             if(addThisScriptToFolder && itemName == thisScript)
            {
                 listOfItemsToSend += [itemName];
                 to_send += name;
 
            }
             else if(itemName != thisScript)
             else if(name != llGetScriptName())
                 listOfItemsToSend += [itemName];
            {
                 to_send += name;
            }
         }
         }
     }while(i++<items);
     }
     if(llGetListLength(to_send) > 0)
    while(++i < numberOfItems);
 
//  change to number of items in list now
    numberOfItems = llGetListLength(listOfItemsToSend);
 
     if(numberOfItems)
     {
     {
        FAIL = FALSE;
         llGiveInventoryList(inputKey, nameOfCreatedFolder, listOfItemsToSend);
         llGiveInventoryList(llGetObjectOwner(), Folder_Name, to_send);
         llInstantMessage(inputKey,
         llInstantMessage(llGetObjectOwner(), Message_On_Sent_Completion);
                    "/me [" + thisScript + "]: Items have been sent into a folder named '"
                    + nameOfFolderToBeCreated + "' within your inventory.");
     }
     }
     else
     else
    {
         llInstantMessage(inputKey,
        FAIL = TRUE;
            "/me [" + thisScript + "]: Could not find inventory items to send!");
         llInstantMessage(llGetObjectOwner(), Message_On_Fail_No_Items_To_Send);
    }
}
}
 
default
default
{
{
     on_rez(integer x)
     on_rez(integer start_param)
     {
     {
         llResetScript();
         llResetScript();
     }
     }
     state_entry()
 
     touch_start(integer num_detected)
     {
     {
         llSetText(Hover_Text, <1.0,1.0,1.0>, 1.0);
         key owner = llGetOwner();
    }
         key id = llDetectedKey(0);
    touch_start(integer x)
 
    {
    //  if not the owner touching, abort process
         if(llDetectedKey(0) == llGetObjectOwner())
        if (id != owner)
        {
             return;
            llSetText("", ZERO_VECTOR, 0);
 
            llInstantMessage(llGetObjectOwner(), Message_On_Touch);
        if (messageToSendUponRez != "")
            llSendInventory(llGetObjectOwner(), INVENTORY_TYPE);
            llInstantMessage(owner, messageToSendUponRez);
            if(llToLower(Show_Name_Of_Folder_On_Completion) == "yes" && FAIL == FALSE)
 
             {
        try_to_send_items(owner, typeOfInventoryItemsToBeSent);
                integer index = llSubStringIndex(Show_Name_Message_On_Completion, "<folder>");
 
                string message;
        if (killAfterCompletion)
                if(index != -1)
             llDie();
                {
                    message = llDeleteSubString(Show_Name_Message_On_Completion, index, index + llStringLength(Show_Name_Message_On_Completion)-1);
                    message += Folder_Name;
                }
                else
                {
                    message = Show_Name_Message_On_Completion;
                }
                llInstantMessage(llGetObjectOwner(), message);
            }
            if(llToLower(Delete_On_Completion) == "yes")
             {
                llDie();
            }
            else if(llToLower(Delete_On_Completion) == "no")
            {
                llSetText(Hover_Text, <1.0,1.0,1.0>, 1.0);
            }
        }
     }
     }
}
}
</lsl>
</source>

Latest revision as of 09:15, 25 January 2015

Unpacker On Touch

Just Copy and Paste into the object that contains your product and configure the script to your needs!

New Motto: Save and Sell!

// NewAge Unpacker On Touch 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)
    {
        llResetScript();
    }

    touch_start(integer num_detected)
    {
        key owner = llGetOwner();
        key id = llDetectedKey(0);

    //  if not the owner touching, abort process
        if (id != owner)
            return;

        if (messageToSendUponRez != "")
            llInstantMessage(owner, messageToSendUponRez);

        try_to_send_items(owner, typeOfInventoryItemsToBeSent);

        if (killAfterCompletion)
            llDie();
    }
}