Factorio is at version 0.17.38 and my question is this:
How can I determine if a ghost was on a tile, when something was built there? And what kind of ghost was that?
To detail and clarify the question: I am not interested in determining if an entity or tile was built BECAUSE of a ghost. I simply want to know if a ghost was on a tile before something was built there.
The context is this: When something is built I want to conditionally allow or disallow it. If it gets disallowed, I want to revert the condition of the tile to the state before something was built there - which also includes placing a ghost, if one was there before.
This question occoured to me here and I am interested in it because of this.
eradicator already gave me great advice, that when something was built by a robot (events on_robot_built_tile and on_robot_built_entity) there must have been a ghost of the same type there before. Naturally right?
Now I am searching for a way to answer this question for the case when a player built something manually.
[0.17.x] Determine if a ghost was on a tile when something was built
Re: [0.17.x] Determine if a ghost was on a tile when something was built
An interesting event is on_put_item. Though from the API doc it seems it does not state what kind of item is being placed down. Which would be handy.
I am thinking of getting into the event chain before something is placed, use LuaSurface to find out if a and what kind of ghost exists where it is placed, remember that for a short while and use it for the case when building is disallowed and the state of the tile gets reverted.
What do you think?
I am thinking of getting into the event chain before something is placed, use LuaSurface to find out if a and what kind of ghost exists where it is placed, remember that for a short while and use it for the case when building is disallowed and the state of the tile gets reverted.
What do you think?
Re: [0.17.x] Determine if a ghost was on a tile when something was built
find_entities_filtered
and
count_entities_filtered
can be used to find ghosts at a certain position, I guess.
so it could work like this:
1. subscribe to on_put_item and on_player_built_entity
2. On on_put_item event get the position, where something was put to, from it.
3. Use LuaSurface::find_entities_filtered(...) with that position, to find out if there is a ghost on that tile.
4. If YES, then store position and type of ghost in dictionary with position as key.
5. When on_player_built_entity is raised, do calculations to decide if building has to be reverted or not.
6. If YES, remove built entity.
7. Lookup if a ghost was stored for that position before. If YES, restore ghost.
8. Remove ghost type and position from dictionary.
Needs a test implementat now for proof of concept.
What search parameters do I have to use for find_entities_filtered if I want to find all ghosts at a position/in an area?
and
count_entities_filtered
can be used to find ghosts at a certain position, I guess.
so it could work like this:
1. subscribe to on_put_item and on_player_built_entity
2. On on_put_item event get the position, where something was put to, from it.
3. Use LuaSurface::find_entities_filtered(...) with that position, to find out if there is a ghost on that tile.
4. If YES, then store position and type of ghost in dictionary with position as key.
5. When on_player_built_entity is raised, do calculations to decide if building has to be reverted or not.
6. If YES, remove built entity.
7. Lookup if a ghost was stored for that position before. If YES, restore ghost.
8. Remove ghost type and position from dictionary.
Needs a test implementat now for proof of concept.
What search parameters do I have to use for find_entities_filtered if I want to find all ghosts at a position/in an area?
- eradicator
- Smart Inserter
- Posts: 5206
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: [0.17.x] Determine if a ghost was on a tile when something was built
type= "tile-ghost"Impatient wrote: ↑Tue May 14, 2019 12:48 pmWhat search parameters do I have to use for find_entities_filtered if I want to find all ghosts at a position/in an area?
ghost_name="whatever your stuff is called" (i.e. "landfill")
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Re: [0.17.x] Determine if a ghost was on a tile when something was built
According to this very old post viewtopic.php?t=3875 , it needsImpatient wrote: ↑Tue May 14, 2019 12:48 pmWhat search parameters do I have to use for find_entities_filtered if I want to find all ghosts at a position/in an area?
Code: Select all
type="ghost"
Re: [0.17.x] Determine if a ghost was on a tile when something was built
++ and thx, like always eradicatoreradicator wrote: ↑Tue May 14, 2019 12:55 pmtype= "tile-ghost"Impatient wrote: ↑Tue May 14, 2019 12:48 pmWhat search parameters do I have to use for find_entities_filtered if I want to find all ghosts at a position/in an area?
ghost_name="whatever your stuff is called" (i.e. "landfill")
- eradicator
- Smart Inserter
- Posts: 5206
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: [0.17.x] Determine if a ghost was on a tile when something was built
I was only 99% sure myself btw, so i just did "/sudo help whatis" and then "/sudo count_ents(10,it)". Because that's exactly the sort of thing i made /sudo for :p.Impatient wrote: ↑Tue May 14, 2019 12:59 pm++ and thx, like always eradicatoreradicator wrote: ↑Tue May 14, 2019 12:55 pmtype= "tile-ghost"Impatient wrote: ↑Tue May 14, 2019 12:48 pmWhat search parameters do I have to use for find_entities_filtered if I want to find all ghosts at a position/in an area?
ghost_name="whatever your stuff is called" (i.e. "landfill")
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.