This event runs when the player isn't using a blueprint item but uses copy and paste instead, and the event does contain the "source" entities that are being copied, but LuaPlayer::blueprint_to_setup isn't valid for read like it is for an actual blueprinting setup.
Is there a way of getting at the ghosts of the items about to be pasted? I want to set their tags.
on_player_setup_blueprint with copy-paste
- Deadlock989
- Smart Inserter
- Posts: 2529
- Joined: Fri Nov 06, 2015 7:41 pm
- Deadlock989
- Smart Inserter
- Posts: 2529
- Joined: Fri Nov 06, 2015 7:41 pm
Re: on_player_setup_blueprint with copy-paste
To clarify, I'm doing stuff like this:
This works for bots reviving ghosts, and the player reviving ghosts. It does not work for copy/cut and paste even though the on_player_setup_blueprint event does fire for that, because player.blueprint_to_setup isn't valid. Am I missing something or is there no container for the ghosts-to-be-placed when C&Ping?
Code: Select all
script.on_event(defines.events.on_built_entity, function (event)
-- do stuff with ghosts if they have tags
end, get_filter())
script.on_event(defines.events.on_robot_built_entity, function (event)
-- do stuff with ghosts if they have tags
end, get_filter())
script.on_event(defines.events.script_raised_revive, function (event)
-- do stuff with ghosts if they have tags
end)
script.on_event(defines.events.on_player_setup_blueprint, function (event)
local player = game.players[event.player_index]
if player and player.blueprint_to_setup and player.blueprint_to_setup.valid_for_read then
for index,entity in pairs(event.mapping.get()) do
local stype,sname = get_render_sprite_info(entity)
if stype and sname then
player.blueprint_to_setup.set_blueprint_entity_tag(index, "display-plate-sprite-type", stype)
player.blueprint_to_setup.set_blueprint_entity_tag(index, "display-plate-sprite-name", sname)
player.blueprint_to_setup.set_blueprint_entity_tag(index, "display-plate-sprite-map-marker", get_has_map_marker(entity))
end
end
end
end)
Re: on_player_setup_blueprint with copy-paste
They should have the setup blueprint in their cursor stack, you can access it there. An example of a mod that does this is https://github.com/DaveMcW/blueprint-tr ... a#L87-L108, here you can see that they handle setup blueprints (like copy paste) in on_player_setup_blueprint and in-the-process-of-setting-up blueprints afterwards in on_player_configured_blueprint.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.
- Deadlock989
- Smart Inserter
- Posts: 2529
- Joined: Fri Nov 06, 2015 7:41 pm
Re: on_player_setup_blueprint with copy-paste
Thanks, worked like a charm. Didn't realise there was a blueprint in the cursor stack for C&P.Bilka wrote: Tue Feb 25, 2020 2:43 pm They should have the setup blueprint in their cursor stack, you can access it there. An example of a mod that does this is https://github.com/DaveMcW/blueprint-tr ... a#L87-L108, here you can see that they handle setup blueprints (like copy paste) in on_player_setup_blueprint and in-the-process-of-setting-up blueprints afterwards in on_player_configured_blueprint.
Code: Select all
script.on_event(defines.events.on_player_setup_blueprint, function (event)
local player = game.players[event.player_index]
if player and player.cursor_stack.valid_for_read and player.cursor_stack.name == "blueprint" then
for index,entity in pairs(event.mapping.get()) do ...