Page 1 of 1

on_player_setup_blueprint with copy-paste

Posted: Tue Feb 25, 2020 12:46 am
by Deadlock989
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.

Re: on_player_setup_blueprint with copy-paste

Posted: Tue Feb 25, 2020 2:19 pm
by Deadlock989
To clarify, I'm doing stuff like this:

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

Re: on_player_setup_blueprint with copy-paste

Posted: Tue Feb 25, 2020 2:43 pm
by Bilka
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.

Re: on_player_setup_blueprint with copy-paste

Posted: Tue Feb 25, 2020 3:04 pm
by Deadlock989
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.
Thanks, worked like a charm. Didn't realise there was a blueprint in the cursor stack for C&P.

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 ...