Hi,
I want to make better loot plugin but I getting errors on adding items to container.
My code:
I want to make better loot plugin but I getting errors on adding items to container.
My code:
List<ItemDefinition> all_items = new List<ItemDefinition>();
List<ItemSlot> slots = new List<ItemSlot>();
System.Random rnd = new System.Random();
int slots_needed = 0;
int items_count = 0;
void Loaded() {
foreach (ItemDefinition it in ItemManager.itemList)
{
all_items.Add(it);
}
}
object OnLootSpawn(LootContainer container)
{
items_count = rnd.Next(1, 30);
slots = container.inventory.availableSlots;
slots_needed = (items_count + slots.Count);
container.inventorySlots = slots_needed;
for (int i = 0; i < items_count; i++)
{
ItemDefinition item_to_add = all_items[rnd.Next(0, (all_items.Count - 1))];
container.inventory.AddItem(item_to_add, -1);
}
return null;
}
Thanks.