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

Place to get help with not working mods / modding interface.
Post Reply
flame_Sla
Long Handed Inserter
Long Handed Inserter
Posts: 54
Joined: Fri Mar 01, 2019 12:54 pm
Contact:

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

Post 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

Xorimuth
Filter Inserter
Filter Inserter
Posts: 627
Joined: Sat Mar 02, 2019 9:39 pm
Contact:

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

Post 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
My mods
Content: Freight Forwarding | Spidertron Patrols | Spidertron Enhancements | Power Overload
QoL: Factory Search | Remote Configuration | Module Inserter Simplified | Wire Shortcuts X | Ghost Warnings

flame_Sla
Long Handed Inserter
Long Handed Inserter
Posts: 54
Joined: Fri Mar 01, 2019 12:54 pm
Contact:

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

Post 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' ?

User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3700
Joined: Tue May 13, 2014 11:06 am
Contact:

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

Post 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)

flame_Sla
Long Handed Inserter
Long Handed Inserter
Posts: 54
Joined: Fri Mar 01, 2019 12:54 pm
Contact:

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

Post by flame_Sla »

that is, the "grid" is always created empty and it cannot be redefined?

User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3700
Joined: Tue May 13, 2014 11:06 am
Contact:

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

Post 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)

flame_Sla
Long Handed Inserter
Long Handed Inserter
Posts: 54
Joined: Fri Mar 01, 2019 12:54 pm
Contact:

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

Post by flame_Sla »

Thank you very much!


Post Reply

Return to “Modding help”