Page 1 of 1

Create ghost before blueprint research

Posted: Tue Nov 22, 2016 8:28 pm
by gheift
Hello,

can someone give me a hint how I can create a ghost while blueprint is not yet researched. I tried

Code: Select all

/c pos = game.player.position e = game.player.surface.create_entity{name = "entity-ghost", inner_name = "small-electric-pole", force = game.player.force, position = {x = pos.x + 1, y = pos.y + 1}}
This returns the created ghost, but is not placed on the surface. A surface.find_entities_filtered immediately after creating the ghost does not returns it. Do I miss a parameter?

Thanks,
Gerhard

Re: Create ghost before blueprint research

Posted: Tue Nov 22, 2016 11:26 pm
by DaveMcW
Ghosts decay instantly until you increase the time to live.

Code: Select all

/c game.player.force.ghost_time_to_live = 60*60*60

Re: Create ghost before blueprint research

Posted: Wed Nov 23, 2016 12:34 am
by gheift
Thanks, that's an evil hack:

Code: Select all

local function place_ghost(surface, entity)
    local force = entity.force
    local gttl = force.ghost_time_to_live
    force.ghost_time_to_live = 4294967295
    local result = {surface.create_entity(entity)}
    force.ghost_time_to_live = gttl
    return unpack(result)
end