OpenSim.Region.ScriptEngine.Shared.Api.LSL_Api.llGiveInventory C# (CSharp) Method

llGiveInventory() public method

public llGiveInventory ( string destination, string inventory ) : void
destination string
inventory string
return void
        public void llGiveInventory(string destination, string inventory)
        {
            m_host.AddScriptLPS(1);

            UUID destId = UUID.Zero;

            if (!UUID.TryParse(destination, out destId))
            {
                Error("llGiveInventory", "Can't parse destination key '" + destination + "'");
                return;
            }

            TaskInventoryItem item = m_host.Inventory.GetInventoryItem(inventory);

            if (item == null)
            {
                Error("llGiveInventory", "Can't find inventory object '" + inventory + "'");
                return;
            }

            UUID objId = item.ItemID;

            // check if destination is an object
            if (World.GetSceneObjectPart(destId) != null)
            {
                // destination is an object
                World.MoveTaskInventoryItem(destId, m_host, objId);
            }
            else
            {
                ScenePresence presence = World.GetScenePresence(destId);

                if (presence == null)
                {
                    UserAccount account =
                            World.UserAccountService.GetUserAccount(
                            World.RegionInfo.ScopeID,
                            destId);

                    if (account == null)
                    {
                        GridUserInfo info = World.GridUserService.GetGridUserInfo(destId.ToString());
                        if(info == null || info.Online == false)
                        {
                            Error("llGiveInventory", "Can't find destination '" + destId.ToString() + "'");
                            return;
                        }
                    }
                }

                // destination is an avatar
                string message;
                InventoryItemBase agentItem = World.MoveTaskInventoryItem(destId, UUID.Zero, m_host, objId, out message);

                if (agentItem == null)
                {
                    llSay(0, message); 
                    return;
                }

                byte[] bucket = new byte[1];
                bucket[0] = (byte)item.Type;
                //byte[] objBytes = agentItem.ID.GetBytes();
                //Array.Copy(objBytes, 0, bucket, 1, 16);

                GridInstantMessage msg = new GridInstantMessage(World,
                        m_host.OwnerID, m_host.Name, destId,
                        (byte)InstantMessageDialog.TaskInventoryOffered,
                        false, item.Name+". "+m_host.Name+" is located at "+
                        World.RegionInfo.RegionName+" "+
                        m_host.AbsolutePosition.ToString(),
                        agentItem.ID, true, m_host.AbsolutePosition,
                        bucket, true);

                ScenePresence sp;

                if (World.TryGetScenePresence(destId, out sp))
                {
                    sp.ControllingClient.SendInstantMessage(msg);
                }
                else
                {
                    if (m_TransferModule != null)
                        m_TransferModule.SendInstantMessage(msg, delegate(bool success) {});
                }
                
                //This delay should only occur when giving inventory to avatars.
                ScriptSleep(m_sleepMsOnGiveInventory);
            }
        }

Usage Example

        public void TestLlGiveInventoryO2ODifferentOwners()
        {
            TestHelpers.InMethod();
//            log4net.Config.XmlConfigurator.Configure();

            UUID user1Id = TestHelpers.ParseTail(0x1);
            UUID user2Id = TestHelpers.ParseTail(0x2);
            string inventoryItemName = "item1";

            SceneObjectGroup so1 = SceneHelpers.CreateSceneObject(1, user1Id, "so1", 0x10);
            m_scene.AddSceneObject(so1);
            LSL_Api api = new LSL_Api();
            api.Initialize(m_engine, so1.RootPart, so1.RootPart.LocalId, so1.RootPart.UUID);

            // Create an object embedded inside the first
            UUID itemId = TestHelpers.ParseTail(0x20);
            TaskInventoryHelpers.AddSceneObject(m_scene, so1.RootPart, inventoryItemName, itemId, user1Id);

            // Create a second object
            SceneObjectGroup so2 = SceneHelpers.CreateSceneObject(1, user2Id, "so2", 0x100);
            m_scene.AddSceneObject(so2);
            LSL_Api api2 = new LSL_Api();
            api2.Initialize(m_engine, so2.RootPart, so2.RootPart.LocalId, so2.RootPart.UUID);

            // *** Firstly, we test where llAllowInventoryDrop() has not been called. ***
            api.llGiveInventory(so2.UUID.ToString(), inventoryItemName);

            {
                // Item has copy permissions so original should stay intact.
                List<TaskInventoryItem> originalItems = so1.RootPart.Inventory.GetInventoryItems();
                Assert.That(originalItems.Count, Is.EqualTo(1));

                // Should have not copied
                List<TaskInventoryItem> copiedItems = so2.RootPart.Inventory.GetInventoryItems(inventoryItemName);
                Assert.That(copiedItems.Count, Is.EqualTo(0));
            }

            // *** Secondly, we turn on allow inventory drop in the target and retest. ***
            api2.llAllowInventoryDrop(1);
            api.llGiveInventory(so2.UUID.ToString(), inventoryItemName);

            {
                // Item has copy permissions so original should stay intact.
                List<TaskInventoryItem> originalItems = so1.RootPart.Inventory.GetInventoryItems();
                Assert.That(originalItems.Count, Is.EqualTo(1));
    
                // Should now have copied.
                List<TaskInventoryItem> copiedItems = so2.RootPart.Inventory.GetInventoryItems(inventoryItemName);
                Assert.That(copiedItems.Count, Is.EqualTo(1));
                Assert.That(copiedItems[0].Name, Is.EqualTo(inventoryItemName));
            }
        }
All Usage Examples Of OpenSim.Region.ScriptEngine.Shared.Api.LSL_Api::llGiveInventory
LSL_Api