Page 1 of 1
Creating ghost entities?
Posted: Sat Mar 15, 2014 9:21 am
by ficolas
There is a "ghost" entity, but Im not sure if it can be created.
Code: Select all
game.createentity{name="ghost", position=game.player.character.selected.position}
Returns that the entity creation failed for an unknown reason, I guess I need to specify wich entity it is what I want to create (if it is possible)
Re: Creating ghost entities?
Posted: Sat Mar 15, 2014 11:15 am
by kovarex
It is not possible now, but I wanted to do it so I will do it

Re: Creating ghost entities?
Posted: Wed Sep 03, 2014 8:55 am
by DaveMcW
Is this possible yet?
Re: Creating ghost entities?
Posted: Wed Sep 03, 2014 10:29 am
by drs9999
Afaik it's still not possible.
Re: Creating ghost entities?
Posted: Wed Sep 03, 2014 12:44 pm
by FreeER
This should be possible via
Code: Select all
game.createentity{name="ghost", position=game.player.selected.position, innername="stone-furnace", force=game.player.force}
innername was actually part of the error message when I tried to create a ghost in 10.8 (I feel fairly sure I've done it earlier when I was testing but not sure exactly when this got added). Obviously position can be any position and innername can be any entity name that the player can make a ghost of (I failed with a name of 'player' but practically everything else I tried worked), createentity typically defaults the force to enemy so that's why I have it specified above as the player's.
However, you'll need the force's ghosttimetolive 'modifier' to be greater than 0 (the default) or the ghost will not appear (though the call does not throw an error), which can be done either through research/tech or (thanks to some updates) with game.player.force.ghosttimetolive = x (if you're placing ghosts for the neutral or enemy forces then you'll need to set it for the proper force via game.forces.y.ghosttimetolive = x).
Re: Creating ghost entities?
Posted: Thu Sep 04, 2014 9:37 am
by DaveMcW
Great!
The next question is, how do I set the recipe for a ghost assembling machine?

Re: Creating ghost entities?
Posted: Thu Sep 04, 2014 2:05 pm
by FreeER
DaveMcW wrote:The next question is, how do I set the recipe for a ghost assembling machine?

you can't, mainly because it's a ghost that will become an assembling machine, not just an assembling machine waiting to be built. Second, I'm not sure that you can set the recipe via code with Lua (you can read it just by accessing entity.recipe which corresponds to the ...force.recipes[recipe_name], but when trying to set it from console I see "LuaEntity::recipe is read only")...I could be wrong (or forgotten how) or it might be changed in an update so what you'd have to do to get the actual assembling machine entity would be to monitor the ghost entity until it was no longer valid and then use game.findentities(filtered) with the position of the old ghost (you'd have to save the position, and use an identifying type or name with filtered) to find the assembling machine that was built (assuming the ghost wasn't canceled in which case findentities(filtered) should return an empty table).
Actually, If I recall correctly an upcoming version of Factorio will have an event to detect when robots build things (and the only thing they can build are ghosts, as far as I know anyways), though I can't guarantee that nor say that it would work exactly as I'd expect (only raising the event after the entity was actually built). Still not certain about setting a recipe however.
Perhaps someone can point out any flaws in my knowledge here

edit: and I did try passing 'recipe = ...' to createentity, it was ignored