List Inventory
From libsecondlife
Contents |
Description
This example shows how to make your bot search through its inventory, the information that the snippet provides can be used for inventory management (i.e. deleting items, giving items etc), appearance management (e.g. attaching items), etc.
Prerequisites
The following prerequisites are required in order for you to make your bot illiterate through its inventory
Real World
- This tutorial assumes that you were able to successfully build libsecondlife! If you have not compiled libsl, please follow the instructions on the Getting Started wikipage.
- Also, if you have no experience with the C# (c-sharp) programming language, I highly recommend that you stop now and please follow the list of links to csharp tutorials located here.
- A libsl bot that is able to login successfully. If you don't know how to create a libsl bot, please go to the "How to create a basic libSL bot" wikipage
The Code
Note: We are assuming that our main "SecondLife" variable is named "client." If you have a different name for this variable, please substitute the name accordingly
Note #2: This was taken from one of my bots which has the working code if you have issues feel free to change :)
static void ListObjectsFolder() { //initialize our list to store the folder contents LLUUID inventoryItems; //make a string array to put our folder names in. String[] SearchFolders = { "" }; //Next we grab a full copy of the entire inventory and get it stored into the Inventory Manager client.Inventory.RequestFolderContents(client.Inventory.Store.RootFolder.UUID, client.Self.AgentID, true, true, InventorySortOrder.ByDate); //Next we want to step through the directory structure until we get to the item. SearchFolders[0] = "Objects"; //Now we can grab the details of that folder and store it to our list. inventoryItems = client.Inventory.FindObjectByPath(client.Inventory.Store.RootFolder.UUID, client.Self.AgentID, SearchFolders[0], 1000); // Create the list which we can use to iliterate through List<InventoryBase> myObjects = client.Inventory.FolderContents(inventoryItems, client.Self.AgentID, true, true, InventorySortOrder.ByName, 1000); foreach (InventoryBase item in myObjects) { // Illiterate through our list of items and print them to the console Console.WriteLine("[Inventory Item] Name: " + item.Name + " <==> " + item.UUID.ToString()); // Code that processes each item goes here } }