Page 1 of 1

A spider mod. The equipment is immediately inserted into the grid.

Posted: Thu Feb 09, 2023 3:22 am
by flame_Sla
I want to make a spider that immediately has equipment inserted into the grid
I understand how to set a new grid

Code: Select all

data:extend(
{
  {
    type = "equipment-grid",
    name = "spidertron-equipment-grid-locked",
    width = 10,
    height = 6,
    locked = true,
    equipment_categories = {"armor"}
  }
}
)
spider1.equipment_grid = "spidertron-equipment-grid-locked"
how to insert the equipment?

Code: Select all

spider1.grid.put({name = "battery-mk2-equipment"})
-- it doesn't work that way

Re: A spider mod. The equipment is immediately inserted into the grid.

Posted: Thu Feb 09, 2023 3:30 am
by Xorimuth
It sounds like might be confusing data and control stages. Your first bit of code is data stage, and your second goes in control. Read https://lua-api.factorio.com/latest/Data-Lifecycle.html if you are unsure.

If that wasn't your problem, then this probably was: newly created items don't get a grid until they have been placed and mined. You can add one yourself with https://lua-api.factorio.com/latest/Lua ... reate_grid

Re: A spider mod. The equipment is immediately inserted into the grid.

Posted: Thu Feb 09, 2023 4:16 am
by flame_Sla
Xorimuth wrote: Thu Feb 09, 2023 3:30 am It sounds like might be confusing data and control stages. Your first bit of code is data stage, and your second goes in control. Read https://lua-api.factorio.com/latest/Data-Lifecycle.html if you are unsure.

If that wasn't your problem, then this probably was: newly created items don't get a grid until they have been placed and mined. You can add one yourself with https://lua-api.factorio.com/latest/Lua ... reate_grid
the spider prototype doesn't have a "grid"
https://wiki.factorio.com/Prototype/SpiderVehicle

1) I can't install the equipment in the grid via 'data.lua' ?
2) how do I install the equipment in the grid for all new spiders via 'control.lua' ?

Re: A spider mod. The equipment is immediately inserted into the grid.

Posted: Thu Feb 09, 2023 5:31 am
by DaveMcW

Code: Select all

script.on_event(defines.events.on_built_entity, function(event)
  if event.created_entity.name == "spidertron" then
    event.created_entity.grid.put{name="battery-mk2-equipment", position={1,1}}
  end
end)

Re: A spider mod. The equipment is immediately inserted into the grid.

Posted: Thu Feb 09, 2023 5:35 am
by flame_Sla
that is, the "grid" is always created empty and it cannot be redefined?

Re: A spider mod. The equipment is immediately inserted into the grid.

Posted: Thu Feb 09, 2023 5:56 am
by DaveMcW
Yes, the grid is always created empty.

It is hard to catch items when they are created because there is no event for it. You could watch the player's inventory though.

Code: Select all

function set_spider_inventory(grid)
  grid.put{name="battery-mk2-equipment", position={1,1}}
end

script.on_event(defines.events.on_built_entity, function(event)
  if event.created_entity.name == "spidertron" then
    set_spider_inventory(event.created_entity.grid)
  end
end)

script.on_event(defines.events.on_player_main_inventory_changed, function(event)
  local inventory = game.get_player(event.player_index).get_main_inventory()
  for i = 1, #inventory do
    if inventory[i].valid_for_read and inventory[i].name == "spidertron" and not inventory[i].grid then
      inventory[i].create_grid()
      set_spider_inventory(inventory[i].grid)
    end
  end
end)

Re: A spider mod. The equipment is immediately inserted into the grid.

Posted: Thu Feb 09, 2023 6:10 am
by flame_Sla
Thank you very much!

Re: A spider mod. The equipment is immediately inserted into the grid.

Posted: Mon Feb 20, 2023 2:58 am
by flame_Sla