Difference between revisions of "LlGiveInventoryList"

From Second Life Wiki
Jump to navigation Jump to search
m (Prettier solution. Could be optimized a bit but that would cost readability.)
m
Line 20: Line 20:
** Does ''not'' create a folder.
** Does ''not'' create a folder.
|caveats=
|caveats=
|examples=<lsl>// When any user clicks this object, this script will give a folder containing everything in the objects inventory
|examples=
// This could be used to give away multiple freebies at once.
<lsl>
// when the prim is touched, the script checks all other inventory items whether or not they're copiable
//  copiable items are added to a list, if the list is not empty when all items have been checked
// the prim gives them to the touching avatar within a single folder


default
default
{
{
     touch_start(integer total_number)
     touch_start(integer num_detected)
     {
     {
         list       inventory;
        string thisScript = llGetScriptName();
         integer     num = llGetInventoryNumber(INVENTORY_ALL);
 
        string      script = llGetScriptName();
         list inventoryItems;
         integer     i = 0;
         integer inventoryNumber = llGetInventoryNumber(INVENTORY_ALL);
 
         for (; i < num; ++i) {
 
             string name = llGetInventoryName(INVENTORY_ALL, i);
         integer index;
            //Don't give them the selling script.
        do
             if(name != script)
         {
             string itemName = llGetInventoryName(INVENTORY_ALL, index);
 
             if (itemName != thisScript)
             {
             {
                 if(llGetInventoryPermMask(name, MASK_OWNER) & PERM_COPY)
                 if (llGetInventoryPermMask(itemName, MASK_OWNER) & PERM_COPY)
                 {
                 {
                     inventory += name;
                     inventoryItems += itemName;
                 }
                 }
                 else
                 else
                 {
                 {
                     llSay(0, "Don't have permissions to give you \""+name+"\".");
                     llSay(PUBLIC_CHANNEL, "Unable to copy the item named '" + itemName + "'.");
                 }
                 }
             }
             }
         }
         }
   
        while(++index < inventoryNumber);
         if (llGetListLength(inventory) < 1)
 
        // if the list is empty, the length of the list is 0 (FALSE)
         if (!llGetListLength(inventoryItems))
         {
         {
             llSay(0, "No items to offer.");  
             llSay(PUBLIC_CHANNEL, "No copiable items found, sorry.");
         }
         }
         else
         else
         {
         {
            // give folder to agent, use name of object as name of folder we are giving
             llGiveInventoryList(llDetectedKey(0), llGetObjectName(), inventoryItems);//  3.0 seconds delay
             llGiveInventoryList(llDetectedKey(0), llGetObjectName(), inventory);
         }
         }
     }
     }
}</lsl>
}
This script illustrates how to use llGiveInventoryList and llGiveInventory together to unpack no-copy items from a box. Copiable items will end up in a folder. No-copy items are transferred separately.
</lsl>
<lsl>default
<lsl>
//  script gives items to owner only
//  all copiable items are given within a single folder
//  all no-copy items are transferred seperately (only one time, right? right!)
 
default
{
{
    touch_start(integer total_number)
    touch_start(integer num_detected)
    {
    {
          if(llDetectedKey(0) == llGetOwner())
        key owner = llGetOwner();
          {
        key touchingAvatar = llDetectedKey(0);
              integer y = llGetInventoryNumber(INVENTORY_ALL);
 
              list InvenList = [];
    //  to reduce indentation we invert the
              while(y--)
    //  if-owner-check to if-not-owner
              {
 
                    string InvenName = llGetInventoryName(INVENTORY_ALL, y);
        if(touchingAvatar != owner)
                    if(llGetInventoryPermMask(InvenName, MASK_OWNER) & PERM_COPY)
            return;
                    {
 
                        InvenList += InvenName;
        list inventoryItems;
                    }
        integer inventoryNumber = llGetInventoryNumber(INVENTORY_ALL);
                    else
 
                    {
        integer index;
                        llGiveInventory(llGetOwner(), InvenName);
        do
                    }
        {
              }
            string itemName = llGetInventoryName(INVENTORY_ALL, index);
              llGiveInventoryList(llGetOwner(), llGetObjectName(), InvenList);
 
          }
            if (llGetInventoryPermMask(itemName, MASK_OWNER) & PERM_COPY)
    }
            {
}</lsl>
                inventoryItems += itemName;
            }
            else
            {
                llGiveInventory(owner, itemName);//  2.0 seconds delay
            }
        }
        while(++index < inventoryNumber);
 
        llGiveInventoryList(owner, llGetObjectName(), inventoryItems);//  3.0 seconds delay
    }
}
</lsl>
|helpers
|helpers
|also_functions={{LSL DefineRow||[[llGiveInventory]]}}
|also_functions={{LSL DefineRow||[[llGiveInventory]]}}

Revision as of 13:34, 15 November 2012

Summary

Function: llGiveInventoryList( key target, string folder, list inventory );

Gives inventory items to target, creating a new folder to put them in.

• key target avatar or prim UUID that is in the same region
• string folder folder name to use
• list inventory a list of items in the inventory of the prim this script is in

Specification

target types

Depending upon the type of target this function works differently.

  • Avatar
    • Must be or recently have been within the same Region as sending object. SVC-868
    • Places the inventory items in a newly created folder in the avatars inventory (even if there is a folder by the same name, a new one is created).
  • Prim / Object
    • The prim must be in the same region.
    • Does not create a folder.

Caveats

  • This function causes the script to sleep for 3.0 seconds.
  • If target is not the owner nor shares the same owner, and inventory does not have transfer permissions, an error is shouted on DEBUG_CHANNEL.
  • If inventory permissions do not allow copy, the transfer fails and an error is shouted on DEBUG_CHANNEL.
  • If target is a prim that is not in the same region an error is shouted on DEBUG_CHANNEL.
  • When scripts are copied or moved between inventories, their state does not survive the transfer. Memory, event queue and execution position are all discarded.
  • If inventory is missing from the prim's inventory then an error is shouted on DEBUG_CHANNEL.
All Issues ~ Search JIRA for related Bugs

Examples

<lsl> // when the prim is touched, the script checks all other inventory items whether or not they're copiable // copiable items are added to a list, if the list is not empty when all items have been checked // the prim gives them to the touching avatar within a single folder

default {

   touch_start(integer num_detected)
   {
       string thisScript = llGetScriptName();
       list inventoryItems;
       integer inventoryNumber = llGetInventoryNumber(INVENTORY_ALL);


       integer index;
       do
       {
           string itemName = llGetInventoryName(INVENTORY_ALL, index);
           if (itemName != thisScript)
           {
               if (llGetInventoryPermMask(itemName, MASK_OWNER) & PERM_COPY)
               {
                   inventoryItems += itemName;
               }
               else
               {
                   llSay(PUBLIC_CHANNEL, "Unable to copy the item named '" + itemName + "'.");
               }
           }
       }
       while(++index < inventoryNumber);
       //  if the list is empty, the length of the list is 0 (FALSE)
       if (!llGetListLength(inventoryItems))
       {
           llSay(PUBLIC_CHANNEL, "No copiable items found, sorry.");
       }
       else
       {
           llGiveInventoryList(llDetectedKey(0), llGetObjectName(), inventoryItems);//  3.0 seconds delay
       }
   }

} </lsl> <lsl> // script gives items to owner only // all copiable items are given within a single folder // all no-copy items are transferred seperately (only one time, right? right!)

default {

   touch_start(integer num_detected)
   {
       key owner = llGetOwner();
       key touchingAvatar = llDetectedKey(0);
   //  to reduce indentation we invert the
   //  if-owner-check to if-not-owner
       if(touchingAvatar != owner)
           return;
       list inventoryItems;
       integer inventoryNumber = llGetInventoryNumber(INVENTORY_ALL);
       integer index;
       do
       {
           string itemName = llGetInventoryName(INVENTORY_ALL, index);
           if (llGetInventoryPermMask(itemName, MASK_OWNER) & PERM_COPY)
           {
               inventoryItems += itemName;
           }
           else
           {
               llGiveInventory(owner, itemName);//  2.0 seconds delay
           }
       }
       while(++index < inventoryNumber);
       llGiveInventoryList(owner, llGetObjectName(), inventoryItems);//  3.0 seconds delay
   }

}

</lsl>

See Also

Events

•  changed

Functions

•  llGiveInventory

Deep Notes

All Issues

~ Search JIRA for related Issues
   llGiveInventoryList should be able to work gridwide

Signature

function void llGiveInventoryList( key target, string folder, list inventory );