Page 1 of 1

Player placed ghost vs blueprint ghost.

Posted: Sat Aug 20, 2016 4:01 pm
by bobingabout
I wrote a script to do something when a player places a ghost entity.
The problem is that it's also catching when a player places a blueprint.

Is there any way to tell the difference between a ghost entity placed by the player, and by a player placed blueprint?

(Both seem to trigger the script.on_event(defines.events.on_built_entity) event)

Re: Player placed ghost vs blueprint ghost.

Posted: Sat Aug 20, 2016 4:10 pm
by Nexela
You could check the players cursor stack and see if they are holding a blueprint.

Re: Player placed ghost vs blueprint ghost.

Posted: Sat Aug 20, 2016 5:18 pm
by bobingabout
Good idea. This line seems to work as a check.

Code: Select all

    or (entity.type == "entity-ghost" and entity.ghost_type == "inserter" and not (player.cursor_stack and (player.cursor_stack.type == "blueprint" or player.cursor_stack.type == "blueprint-book")))
Loosely translated, it says "If the player places a ghost of an inserter, and doesn't have a blueprint, or blueprint book in his hand"