Difference between revisions of "LlGiveInventoryList"

From Second Life Wiki
Jump to navigation Jump to search
(added example)
m (Minimal example)
 
(34 intermediate revisions by 18 users not shown)
Line 1: Line 1:
{{LSL_Function/inventory|inventory|uuid=false|type=list of items}}{{LSL_Function
{{LSL_Function
|inject-2={{Issues/SVC-868}}
{{LSL_Function/give|target|inventory|sim=*|uuid=false|insert=list of items}}
|func_id=231|func_sleep=3.0|func_energy=10.0
|func_id=231|func_sleep=3.0|func_energy=10.0
|func=llGiveInventoryList
|func=llGiveInventoryList
|p1_type=key|p1_name=avatar
|p1_type=key|p1_name=target|p1_desc
|p2_type=string|p2_name=folder
|p2_type=string|p2_name=folder|p2_desc=folder name to use
|p3_type=list|p3_name=inventory
|p3_type=list|p3_name=inventory
|func_footnote
|func_footnote
|return_text
|return_text
|func_desc=Gives '''inventory''' items to '''avatar''' in a '''folder'''
|func_desc=Gives '''inventory''' items to '''target''', creating a new '''folder''' to put them in.
|spec
|spec=
|caveats=*Does not create a folder when '''avatar''' is a prim [[UUID]].
===target types===
**The prim must be in the same sim.
Depending upon the type of '''target''' this function works differently.
|examples=<pre>
* Avatar
// When a user clicks this object, this script will give a folder containing everything in the objects inventory
** Must be in or able to see into the same Region as the sending object, or recently have been so. [[#SVC-868|SVC-868]]
// This can serve as a unpacker script for boxed objects
** 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=
|examples=
<source lang="lsl2">
default
{
    touch_start(integer n)
    {
        key toucher = llDetectedKey(0);
        string folder = "Item Folder";
        list inventory = ["item", "another item"];
        llGiveInventoryList(toucher, folder, inventory);
    }
}
</source>
<source lang="lsl2">
// 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 num_detected)
    {
        string thisScript = llGetScriptName();
        list inventoryItems;
        integer inventoryNumber = llGetInventoryNumber(INVENTORY_ALL);


    touch_start(integer total_number) {
        integer index;
        for ( ; index < inventoryNumber; ++index )
        {
            string itemName = llGetInventoryName(INVENTORY_ALL, index);


        list        inventory;
            if (itemName != thisScript)
        string      name;
             {
        integer    num = llGetInventoryNumber(INVENTORY_ALL);
                if (llGetInventoryPermMask(itemName, MASK_OWNER) & PERM_COPY)
        integer    i;
                 {
       
                    inventoryItems += itemName;
        for (i = 0; i < num; ++i) {
                }
             name = llGetInventoryName(INVENTORY_ALL, i);
                else
            if(llGetInventoryPermMask(name, MASK_NEXT) & PERM_COPY)
                 {
                 inventory += name;
                    llSay(0, "Unable to copy the item named '" + itemName + "'.");
            else
                }
                 llSay(0, "Don't have permissions to give you \""+name+"\".");
            }
         }
         }
       
 
          
         if (inventoryItems == [] )
        //we don't want to give them this script
         {
        i = llListFindList(inventory, [llGetScriptName()]);
             llSay(0, "No copiable items found, sorry.");
        inventory = llDeleteSubList(inventory, i, i);
         }
       
        else
         if (llGetListLength(inventory) < 1) {
        {
             llSay(0, "No items to offer.");  
             llGiveInventoryList(llDetectedKey(0), llGetObjectName(), inventoryItems);   // 3.0 seconds delay
         } else {
            // give folder to agent, use name of object as name of folder we are giving
             llGiveInventoryList(llDetectedKey(0), llGetObjectName(), inventory);
         }
         }
     
     }
     }
}
</source>
<source lang="lsl2">
//  script gives items to owner only
//  all copiable items are given within a single folder
//  all no-copy items are transferred separately (only one time, right? right!)
default
{
    touch_start(integer num_detected)
    {
        key owner = llGetOwner();
        if (llDetectedKey(0) != owner)
            return;


        list inventoryItems;
        integer inventoryNumber = llGetInventoryNumber(INVENTORY_ALL);
        integer index;
        for ( ; index < inventoryNumber; ++index )
        {
            string itemName = llGetInventoryName(INVENTORY_ALL, index);
            if (itemName != llGetScriptName() )
            {
                if (llGetInventoryPermMask(itemName, MASK_OWNER) & PERM_COPY)
                {
                    inventoryItems += itemName;
                }
                else
                {
                    llGiveInventory(owner, itemName);    // 2.0 seconds delay
                }
            }
        }
        if (inventoryItems != [] )
            llGiveInventoryList(owner, llGetObjectName(), inventoryItems);    // 3.0 seconds delay
    }
}
}
</pre>
</source>
|helpers
|helpers
|also_functions=*{{LSLG|llGiveInventory}}
|also_functions={{LSL DefineRow||[[llGiveInventory]]}}
|also_events=*{{LSLG|changed}}
|also_events={{LSL DefineRow||[[changed]]}}
|also_tests
|also_tests
|also_articles
|also_articles
|notes
|notes|cat1=Inventory
|sort=GiveInventoryList
|cat1=Inventory
|cat2
|cat2
|cat3
|cat3
|cat4
|cat4
}}
}}

Latest revision as of 15:54, 1 April 2023

Summary

Function: llGiveInventoryList( key target, string folder, list inventory );
3.0 Forced Delay
10.0 Energy

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 in or able to see into the same Region as the sending object, or recently have been so. 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.

Examples

default
{
    touch_start(integer n)
    {
        key toucher = llDetectedKey(0);
        string folder = "Item Folder";
        list inventory = ["item", "another item"];
        llGiveInventoryList(toucher, folder, inventory);
    }
}
//  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;
        for ( ; index < inventoryNumber; ++index )
        {
            string itemName = llGetInventoryName(INVENTORY_ALL, index);

            if (itemName != thisScript)
            {
                if (llGetInventoryPermMask(itemName, MASK_OWNER) & PERM_COPY)
                {
                    inventoryItems += itemName;
                }
                else
                {
                    llSay(0, "Unable to copy the item named '" + itemName + "'.");
                }
            }
        }

        if (inventoryItems == [] )
        {
            llSay(0, "No copiable items found, sorry.");
        }
        else
        {
            llGiveInventoryList(llDetectedKey(0), llGetObjectName(), inventoryItems);    // 3.0 seconds delay
        }
    }
}
//  script gives items to owner only
//  all copiable items are given within a single folder
//  all no-copy items are transferred separately (only one time, right? right!)

default
{
    touch_start(integer num_detected)
    {
        key owner = llGetOwner();
        if (llDetectedKey(0) != owner)
            return;

        list inventoryItems;
        integer inventoryNumber = llGetInventoryNumber(INVENTORY_ALL);

        integer index;
        for ( ; index < inventoryNumber; ++index )
        {
            string itemName = llGetInventoryName(INVENTORY_ALL, index);
            if (itemName != llGetScriptName() )
            {
                if (llGetInventoryPermMask(itemName, MASK_OWNER) & PERM_COPY)
                {
                    inventoryItems += itemName;
                }
                else
                {
                    llGiveInventory(owner, itemName);    // 2.0 seconds delay
                }
            }
        }

        if (inventoryItems != [] )
            llGiveInventoryList(owner, llGetObjectName(), inventoryItems);    // 3.0 seconds delay
    }
}

See Also

Events

•  changed

Functions

•  llGiveInventory

Deep Notes

Signature

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