Creating ghost entities?

Place to get help with not working mods / modding interface.
Post Reply
ficolas
Smart Inserter
Smart Inserter
Posts: 1068
Joined: Sun Feb 24, 2013 10:24 am
Contact:

Creating ghost entities?

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

kovarex
Factorio Staff
Factorio Staff
Posts: 8078
Joined: Wed Feb 06, 2013 12:00 am
Contact:

Re: Creating ghost entities?

Post by kovarex »

It is not possible now, but I wanted to do it so I will do it :)

User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3700
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: Creating ghost entities?

Post by DaveMcW »

Is this possible yet?

drs9999
Filter Inserter
Filter Inserter
Posts: 831
Joined: Wed Mar 06, 2013 11:16 pm
Contact:

Re: Creating ghost entities?

Post by drs9999 »

Afaik it's still not possible.

User avatar
FreeER
Smart Inserter
Smart Inserter
Posts: 1266
Joined: Mon Feb 18, 2013 4:26 am
Contact:

Re: Creating ghost entities?

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

User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3700
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: Creating ghost entities?

Post by DaveMcW »

Great!

The next question is, how do I set the recipe for a ghost assembling machine? :)

User avatar
FreeER
Smart Inserter
Smart Inserter
Posts: 1266
Joined: Mon Feb 18, 2013 4:26 am
Contact:

Re: Creating ghost entities?

Post 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

Post Reply

Return to “Modding help”