Difference between revisions of "LlGetInventoryNumber"

From Second Life Wiki
Jump to navigation Jump to search
m (Replaced <source> with <syntaxhighlight>)
 
(14 intermediate revisions by 9 users not shown)
Line 1: Line 1:
{{LSL_Function
{{LSL_Function
|func_id=146|func_sleep=0.0|func_energy=10.0
|func_id=146|func_sleep=0.0|func_energy=10.0
|func=llGetInventoryNumber|return_type=integer|p1_type=integer|p1_name=type
|func=llGetInventoryNumber|return_type=integer
|p1_type=integer|p1_name=type|p1_desc=INVENTORY_* flag
|func_footnote
|func_footnote
|func_desc
|func_desc
Line 8: Line 9:
|caveats
|caveats
|constants={{LSL Constants Inventory}}
|constants={{LSL Constants Inventory}}
|examples
|examples=<syntaxhighlight lang="lsl2">//                            Item Counter
//                      By Apollia Pirandello
//                              9/19/2007
//
// Public domain.  Free to use and/or modify for any purpose,
// including commercial purposes.
//
// Once you drop this script in any prim, it will immediately
// tell you in an OwnerSay how many items are in that prim,
// minus 1, so the script itself isn't counted.
//
// It will also do that whenever the prim is touched.
//**********SCRIPT BEGINS BELOW**********
 
//****VARIABLE
 
integer items_contained;
 
//****END OF VARIABLE SECTION
//****FUNCTIONS****
 
CountItems()
{
  items_contained = llGetInventoryNumber( INVENTORY_ALL );
  --items_contained; //minus 1, the script itself isn't counted, since its used with the INVENTORY_ALL flag
}
 
SayCount()
{
  llOwnerSay( "This prim contains " + (string)items_contained + " items." );
}
 
//****END OF FUNCTIONS****
//****DEFAULT STATE****
 
default
{
  state_entry()
  {
    CountItems();
    SayCount();
  }
 
  touch_start(integer total_number)
  {
    CountItems();
    SayCount();
  } 
}</syntaxhighlight>
<syntaxhighlight lang="lsl2">objects = llGetInventoryNumber(INVENTORY_OBJECT);</syntaxhighlight>
<syntaxhighlight lang="lsl2">// Inventory Statistic By Zep Palen.
// Here is another use of llGetInventoryNumber to show a statistic in a hovertext
// For this script to work you must add a showlist and an excludelist to the Description of the item this script is in.
// The description field must be filled like follows: [showlist];[Excludelist]
// Example: 0,1,3,5,6,7,10,13,20,21;3,7,10
// in the example all types are shown, but only types 3,7 and 10 are counted as total. You can see in the 2 lists below which number means which type
// -----------------
// This script is free to use and modify as you wish - Zep Palen
// --------------------------
 
list inv_types = [0, 1, 3, 5, 6, 7, 10, 13, 20, 21];
list inv_names = ["Textures", "Sounds", "Landmarks", "Clothings", "Objects", "Notecards", "Scripts", "Bodyparts", "Animations", "Gestures"];
 
processCountInventory()
{
    list objDesc = llParseString2List(llGetObjectDesc(), [";"], []);
    list showList = llParseString2List(llList2String(objDesc, 0), [","], []);
    list excludeFromCount = llParseString2List(llList2String(objDesc, 1), [","], []);
           
    string counted = "ITEM COUNTER";
    integer i = ~llGetListLength(showList);
    while (++i)
    {
        integer showItem = (integer)llList2String(showList, i);
        integer sIndex = llListFindList(inv_types, [showItem]);
        if (~sIndex)
            counted += "\n" + llList2String(inv_names, sIndex) + ": " + (string)llGetInventoryNumber(showItem);
    }
    integer totalCount = llGetInventoryNumber(INVENTORY_ALL);
    for (i = ~llGetListLength(excludeFromCount); ++i;)
    {
        integer exclItem = (integer)llList2String(excludeFromCount, i);
        integer cIndex = llListFindList(inv_types, [(string)exclItem]);
        if (~cIndex)
            totalCount = totalCount - llGetInventoryNumber(exclItem);
    }
   
    counted += "\n \n" + "Total: " + (string)totalCount;
    llSetText(counted, <1,1,0>, 1);
}
 
default
{
    state_entry()
    {
        processCountInventory();
    }
   
    changed(integer change)
    {
        if (change & CHANGED_INVENTORY)
        {
            processCountInventory();
        }
    }
}</syntaxhighlight>
|helpers
|helpers
|also_functions
|also_functions=
{{LSL DefineRow||[[llGetInventoryAcquireTime]]|Returns the time the item was added to the prim's inventory}}
{{LSL DefineRow||[[llGetInventoryName]]|Returns the inventory item's name}}
{{LSL DefineRow||[[llGetInventoryType]]|Tests to see if an inventory item exists and returns its type.}}
{{LSL DefineRow||[[llGetInventoryCreator]]|Returns the inventory item's creator}}
{{LSL DefineRow||[[llGetInventoryPermMask]]|Returns the inventory item's permissions}}
{{LSL DefineRow||[[llGetInventoryKey]]|Returns the inventory item's [[UUID]] (if full perm)}}
|also_events
|also_events
|also_tests
|also_tests=
{{LSL DefineRow||[[llGiveInventory_All_Test]]|}}
|also_articles
|also_articles
|notes
|notes
|permission
|permission
|negative_index
|sort=GetInventoryNumber
|sort=GetInventoryNumber
|cat1=Inventory
|cat1=Inventory

Latest revision as of 08:11, 11 October 2023

Summary

Function: integer llGetInventoryNumber( integer type );
0.0 Forced Delay
10.0 Energy

Returns an integer that is the number of items of a given type in the prims inventory.

• integer type INVENTORY_* flag

Flag Inventory Type
INVENTORY_NONE -1 Item does not exist.
INVENTORY_ALL Any inventory type.
INVENTORY_TEXTURE 0 texture
INVENTORY_SOUND 1 sound
INVENTORY_LANDMARK 3 landmark
INVENTORY_CLOTHING 5 clothing
INVENTORY_OBJECT 6 object
Flag Inventory Type
INVENTORY_NOTECARD 7 notecard
INVENTORY_SCRIPT 10 script
INVENTORY_BODYPART 13 body part
INVENTORY_ANIMATION 20 animation
INVENTORY_GESTURE 21 gesture
INVENTORY_SETTING 56 setting
INVENTORY_MATERIAL 57 material

Examples

//                             Item Counter
//                       By Apollia Pirandello
//                              9/19/2007
//
// Public domain.  Free to use and/or modify for any purpose, 
// including commercial purposes.
//
// Once you drop this script in any prim, it will immediately
// tell you in an OwnerSay how many items are in that prim, 
// minus 1, so the script itself isn't counted.
//
// It will also do that whenever the prim is touched.
//**********SCRIPT BEGINS BELOW**********

//****VARIABLE

integer items_contained;

//****END OF VARIABLE SECTION
//****FUNCTIONS****

CountItems()
{
  items_contained = llGetInventoryNumber( INVENTORY_ALL );
  --items_contained; //minus 1, the script itself isn't counted, since its used with the INVENTORY_ALL flag
}

SayCount()
{
  llOwnerSay( "This prim contains " + (string)items_contained + " items." );
}

//****END OF FUNCTIONS****
//****DEFAULT STATE****

default
{
  state_entry()
  {
    CountItems();
    SayCount();
  }

  touch_start(integer total_number)
  {
    CountItems();
    SayCount();
  }  
}
objects = llGetInventoryNumber(INVENTORY_OBJECT);
// Inventory Statistic By Zep Palen.
// Here is another use of llGetInventoryNumber to show a statistic in a hovertext
// For this script to work you must add a showlist and an excludelist to the Description of the item this script is in.
// The description field must be filled like follows: [showlist];[Excludelist]
// Example: 0,1,3,5,6,7,10,13,20,21;3,7,10
// in the example all types are shown, but only types 3,7 and 10 are counted as total. You can see in the 2 lists below which number means which type
// -----------------
// This script is free to use and modify as you wish - Zep Palen
// --------------------------

list inv_types = [0, 1, 3, 5, 6, 7, 10, 13, 20, 21];
list inv_names = ["Textures", "Sounds", "Landmarks", "Clothings", "Objects", "Notecards", "Scripts", "Bodyparts", "Animations", "Gestures"];

processCountInventory()
{
    list objDesc = llParseString2List(llGetObjectDesc(), [";"], []);
    list showList = llParseString2List(llList2String(objDesc, 0), [","], []);
    list excludeFromCount = llParseString2List(llList2String(objDesc, 1), [","], []);
            
    string counted = "ITEM COUNTER";
    integer i = ~llGetListLength(showList);
    while (++i)
    {
        integer showItem = (integer)llList2String(showList, i);
        integer sIndex = llListFindList(inv_types, [showItem]);
        if (~sIndex)
            counted += "\n" + llList2String(inv_names, sIndex) + ": " + (string)llGetInventoryNumber(showItem);
    }
    integer totalCount = llGetInventoryNumber(INVENTORY_ALL);
    for (i = ~llGetListLength(excludeFromCount); ++i;)
    {
        integer exclItem = (integer)llList2String(excludeFromCount, i);
        integer cIndex = llListFindList(inv_types, [(string)exclItem]);
        if (~cIndex)
            totalCount = totalCount - llGetInventoryNumber(exclItem);
    }
    
    counted += "\n \n" + "Total: " + (string)totalCount;
    llSetText(counted, <1,1,0>, 1);
}

default
{
    state_entry()
    {
        processCountInventory();
    }
    
    changed(integer change)
    {
        if (change & CHANGED_INVENTORY)
        {
            processCountInventory();
        }
    }
}

See Also

Functions

•  llGetInventoryAcquireTime Returns the time the item was added to the prim's inventory
•  llGetInventoryName Returns the inventory item's name
•  llGetInventoryType Tests to see if an inventory item exists and returns its type.
•  llGetInventoryCreator Returns the inventory item's creator
•  llGetInventoryPermMask Returns the inventory item's permissions
•  llGetInventoryKey Returns the inventory item's UUID (if full perm)

Deep Notes

Tests

•  llGiveInventory_All_Test

Signature

function integer llGetInventoryNumber( integer type );