Beispiel #1
0
        public void UpdateInventory(InventoryContainer container)
        {
            var inventories = Cache.Character.Metadata.Inventories;

            if (inventories.All(self => self.Seed != container.Seed))
            {
                return;
            }

            inventories.RemoveAll(self => self.Seed == container.Seed);
            inventories.Add(container);
        }
Beispiel #2
0
        public static bool Give(InventoryContainer container, InventoryItem item, int slot = -1)
        {
            if (slot == -1)
            {
                if (container.Slots.All(self => self != null && self.Seed != "__none"))
                {
                    return(false);
                }

                var index = -1;

                foreach (var entry in container.Slots)
                {
                    index++;

                    if (entry != null && entry.Seed != "__none")
                    {
                        continue;
                    }

                    item.Slot = index;

                    break;
                }
            }
            else
            {
                item.Slot = slot;
            }

            try
            {
                container.Slots[item.Slot] = item;
                container.Commit();

                Cache.Player.Sound.PlayFrontend(item.IsWeapon() ? "PICK_UP_WEAPON" : "PICK_UP",
                                                item.IsWeapon() ? "HUD_FRONTEND_CUSTOM_SOUNDSET" : "HUD_FRONTEND_DEFAULT_SOUNDSET");

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Beispiel #3
0
        public void RegisterContainer(InventoryContainer inventory)
        {
            if (inventory.Slots.Length < inventory.SlotAmount)
            {
                var modified = inventory.Slots.ToList();

                for (var i = inventory.Slots.Length; i < inventory.SlotAmount; i++)
                {
                    modified.Add(new EmptyItem
                    {
                        Slot = i
                    });
                }

                inventory.Slots = modified.ToArray();
            }

            Registry.Add(inventory);

            API.SendNuiMessage(new JsonBuilder().Add("Operation", "REGISTER_INVENTORY").Add("Inventory", inventory)
                               .Build());
        }
Beispiel #4
0
 public static void RemoveAll(InventoryContainer container, Predicate <InventoryItem> predicate)
 {
     container.Slots.Where(self => self != null).Where(predicate.Invoke).ToList()
     .ForEach(self => container.Slots[self.Slot] = null);
     container.Commit();
 }