Lua way to Shift+Click a blueprint?

Place to get help with not working mods / modding interface.
Post Reply
boernsen2
Inserter
Inserter
Posts: 21
Joined: Thu Dec 02, 2021 5:36 pm
Contact:

Lua way to Shift+Click a blueprint?

Post by boernsen2 »

Hi everyone,

I'm looking for the Lua way to simulate a Shift-Click-Placement of a certain blueprint at a certain position without relying on the mouse pointer. Does anybody have an idea on how that could be achieved?

What I actually want to achieve is that a moving spidertron continuously places a selected blueprint (e.g. by finding its name in my local blueprint book) at its position in the same way I would do manually by keeping Shift+Click pressed while sitting in the spidertron. However, I would like it to do it without my attendance and without having me as a driver.

So far, I am only able to place individual tiles and entities automatically at the spidertron's position and I still have to call a calculated deconstruction area each time, which seems cumbersome as it must not overlap already placed tiles/entities from the previous position. Is there an easier way to emulate the continuous Shift-Click placement?

Every hint is much appreciated!

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

Re: Lua way to Shift+Click a blueprint?

Post by DaveMcW »

Code: Select all

blueprint.build_blueprint{
  surface = spider.surface,
  force = spider.force,
  position = spider.position,
  force_build = true,
}

boernsen2
Inserter
Inserter
Posts: 21
Joined: Thu Dec 02, 2021 5:36 pm
Contact:

Re: Lua way to Shift+Click a blueprint?

Post by boernsen2 »

Waoh, that looks easy. Thank you!

How do I access the blueprints though? Preferably the team blueprint book's ones (alternatively my own blueprint book's ones)?

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

Re: Lua way to Shift+Click a blueprint?

Post by DaveMcW »

Blueprint library has very poor mod support. You need to put the blueprint somewhere on the map. Like in the spidertron, or your character inventory, or a script inventory.

Code: Select all

local blueprint = spider.get_inventory(defines.inventory.spider_trunk).find_item_stack('blueprint')

boernsen2
Inserter
Inserter
Posts: 21
Joined: Thu Dec 02, 2021 5:36 pm
Contact:

Re: Lua way to Shift+Click a blueprint?

Post by boernsen2 »

Many thanks for your replies!

Is there a way to hard-code a constant blueprint in Lua code? (I need some way to ensure it is the correct blueprint)

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

Re: Lua way to Shift+Click a blueprint?

Post by DaveMcW »

Code: Select all

if not global.my_blueprint then
  global.my_blueprint = game.create_inventory(1)[1]
  global.my_blueprint.import_stack("0eNpVjsEKwjAQRP9lzkHaWm3Mr0iRVhdZaLehScVQ8u8m8aKnZYZ5M7tjnDayK4uH2cH3RRzMdYfjpwxT9nywBAP2NENBhjkry8mMCiwPesPUsVcg8eyZvnwR4SbbPNKaAv+kgl1cCi+SF1JBdTgphHJj7ipr5uc5hRetrgCNrtvu0nStbo5nXcX4AYUxP6Q=")
end
If the blueprint is not constant, you should track and recycle/delete old script inventories to avoid memory leaks.

boernsen2
Inserter
Inserter
Posts: 21
Joined: Thu Dec 02, 2021 5:36 pm
Contact:

Re: Lua way to Shift+Click a blueprint?

Post by boernsen2 »

Just realized, I didn't reply. Many many thanks! Works like a charm.

Post Reply

Return to “Modding help”