Advertisement
Bugs_Larnia

LSL: Simple object giver

Jan 13th, 2021 (edited)
772
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Simple object giver - by Bugs Larnia
  2. // Created 2009-12-19
  3. // 2019-12-6 - BL: Replaced llInstantMessage by llRegionSayTo and updated variable names
  4.  
  5. // This script will give all inventory, except this script to anyone who touches the container
  6. // This script is freeware and may be distributed and used freely
  7. // Please keep annotations
  8.  
  9. list glInventory;
  10.  
  11. // This user defined function (UDF) puts the inventory in a list
  12. GetInventoryList()
  13. {
  14.     integer i;
  15.     glInventory = [];
  16.    
  17.     // Build the list of things to give
  18.     for (i = 0; i < llGetInventoryNumber(INVENTORY_ALL); ++i)
  19.     {
  20.         glInventory += llGetInventoryName(INVENTORY_ALL, i);
  21.     }
  22.    
  23.     // Delete this giver script from the list
  24.     i = llListFindList(glInventory, [llGetScriptName()]);
  25.     if (~i)
  26.     {
  27.         glInventory = llDeleteSubList(glInventory, i, i);
  28.     }      
  29. }
  30.  
  31. SayTo(key pkId, string psMsg)
  32. {
  33.     if (pkId == NULL_KEY)
  34.     {
  35.         return;
  36.     }
  37.     llRegionSayTo(pkId, 0, psMsg);
  38. }
  39.  
  40. default
  41. {
  42.     state_entry()
  43.     {
  44.         GetInventoryList(); // Build the inventory list
  45.     }
  46.    
  47.     changed(integer piChange)
  48.     {
  49.         // Make sure the list is rebuilt when a new object is dropped in or removed
  50.         if (piChange & CHANGED_INVENTORY)
  51.         {
  52.             GetInventoryList();
  53.         }
  54.        
  55.         // Reset script on owner change
  56.         if (piChange & CHANGED_OWNER)
  57.         {
  58.             llResetScript();
  59.         }
  60.     }
  61.  
  62.     touch_start(integer piNum)
  63.     {
  64.         integer iLength = llGetListLength(glInventory); // Get the list length
  65.         string sFolder = llGetObjectName(); // Folder name
  66.        
  67.         key kId = llDetectedKey(0); // Get toucher's key
  68.        
  69.         // If more items, then give a folder
  70.         if (iLength > 1)
  71.         {
  72.             llGiveInventoryList(kId, sFolder, glInventory);
  73.             SayTo(kId, "Please look in your inventory for a folder called: " + sFolder);
  74.         }
  75.         // If only one item, just give the item
  76.         else if (iLength == 1)
  77.         {
  78.             string sName = llList2String(glInventory, 0);
  79.             llGiveInventory(kId, sName);
  80.             SayTo(kId, "Please look in your inventory for an item called: " + sName);
  81.         }
  82.         // No items present; inform the toucher
  83.         else
  84.         {
  85.             SayTo(kId, "Sorry, there seems to be no inventory present.");
  86.         }
  87.     }
  88.    
  89.     on_rez(integer piParam)
  90.     {
  91.         llResetScript();
  92.     }
  93. }
  94.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement