Advertisement
LethBaumann

Inventory Counter

Sep 15th, 2018
429
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. integer items_contained;
  2. list inv_types = [0, 1, 3, 5, 6, 7, 10, 13, 20, 21];
  3. list inv_names = ["Textures", "Sounds", "Landmarks", "Clothings", "Objects", "Notecards", "Scripts", "Bodyparts", "Animations", "Gestures"];
  4.  
  5. CountItems()
  6. {
  7.   items_contained = llGetInventoryNumber( INVENTORY_ALL );
  8.   --items_contained; //minus 1, the script itself isn't counted, since its used with the INVENTORY_ALL flag
  9. }
  10.  
  11. processCountInventory()
  12. {
  13.     list objDesc = llParseString2List(llGetObjectDesc(), [";"], []);
  14.     list showList = llParseString2List(llList2String(objDesc, 0), [","], []);
  15.     list excludeFromCount = llParseString2List(llList2String(objDesc, 1), [","], []);
  16.  
  17.     string counted = "ITEM COUNTER";
  18.     integer i = ~llGetListLength(showList);
  19.     while (++i)
  20.     {
  21.         integer showItem = (integer)llList2String(showList, i);
  22.         integer sIndex = llListFindList(inv_types, [showItem]);
  23.         if (~sIndex)
  24.             counted += "\n" + llList2String(inv_names, sIndex) + ": " + (string)llGetInventoryNumber(showItem);
  25.     }
  26.     integer totalCount = llGetInventoryNumber(INVENTORY_ALL);
  27.     for (i = ~llGetListLength(excludeFromCount); ++i;)
  28.     {
  29.         integer exclItem = (integer)llList2String(excludeFromCount, i);
  30.         integer cIndex = llListFindList(inv_types, [(string)exclItem]);
  31.         if (~cIndex)
  32.             totalCount = totalCount - llGetInventoryNumber(exclItem);
  33.     }
  34.  
  35.     counted += "\n \n" + "Total: " + (string)totalCount;
  36.     llSetText(counted, <1,1,0>, 1);
  37. }
  38.  
  39.  
  40. default
  41. {
  42.   state_entry()
  43.   {
  44.     CountItems();
  45.   }
  46.  
  47.   touch_start(integer total_number)
  48.   {
  49.     CountItems();
  50.   }  
  51.   changed(integer change)
  52.     {
  53.         if (change & CHANGED_INVENTORY)
  54.         {
  55.             processCountInventory();
  56.         }
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement