Page 1 of 1

Insert blueprints into blueprint-book

Posted: Thu Jan 05, 2017 4:18 am
by OldVamp
I am setting up a custom quick start scenario and would like to start players off with a full (blank) blueprint book.
I cant seem to put together the right combination of words and functions to complete the task during the on_player_created event.
This is what I have:

Code: Select all

  player.insert{name="blueprint-book", count=1}

  local inventories = {player.get_inventory(defines.inventory.player_quickbar), player.get_inventory(defines.inventory.player_main)}
  for _, inv in pairs(inventories) do
    for i=1,#inv do
      local itemStack = inv[i]
      if itemStack.valid_for_read and itemStack.type == "blueprint-book" then
        --now what? I want to insert blueprint count 30 into blueprint-book
      end
    end
  end
Any help would be appreciated.

Re: Insert blueprints into blueprint-book

Posted: Thu Jan 05, 2017 4:34 am
by Nexela
You need to get the equipment grid for the item http://lua-api.factorio.com/latest/LuaE ... tGrid.html
See Below

Re: Insert blueprints into blueprint-book

Posted: Thu Jan 05, 2017 5:01 am
by OldVamp
Nexela wrote:You need to get the equipment grid for the item
That doesn't seem to work
Factorio 0.14.21 wrote:attempt to index field 'grid' (a nil value)

Re: Insert blueprints into blueprint-book

Posted: Thu Jan 05, 2017 5:52 am
by Nexela
Ohhhhhhhhh wrong one I see now :) http://lua-api.factorio.com/latest/LuaI ... _inventory

Code: Select all

  if itemStack.valid_for_read and itemStack.type == "blueprint-book" then
    local itemInv = itemStack.get_inventory(defines.inventory.item_main)
    itemInv.insert("blueprint")
  end

Re: Insert blueprints into blueprint-book

Posted: Thu Jan 05, 2017 6:30 am
by OldVamp
That did the trick.
Thank you very much.

Code: Select all

  player.insert{name="blueprint-book", count=1}

  local inventories = {player.get_inventory(defines.inventory.player_quickbar), player.get_inventory(defines.inventory.player_main)}
  for _, inv in pairs(inventories) do
    for i=1,#inv do
      local itemStack = inv[i]
      if itemStack.valid_for_read and itemStack.type == "blueprint-book" then
        local itemInv = itemStack.get_inventory(defines.inventory.item_main)
        itemInv.insert{name="blueprint", count=30}
      end
    end
  end