Page 1 of 1

Entity corpses without health bar.

Posted: Sat Sep 14, 2019 8:27 am
by mrvn
I have an entity that is made up of several entities. One of them is placable, destructable and minable and controls the rest. I can place the entity or mine it just fine.

I can also destroy the master entity by e.g. shooting it. In on_entity_died I then kill the other entities as well so they turn into ghosts too. That all works. But now each entity shows the pink health bar for a destroyed entity. I want to only have one health bar for the master entity visible.
health-bars.png
health-bars.png (63.94 KiB) Viewed 598 times
Ideas?

Re: Entity corpses without health bar.

Posted: Sat Sep 14, 2019 8:36 am
by Bilka
Set the time to live of the other ghosts to max uint: https://lua-api.factorio.com/latest/Lua ... me_to_live

Re: Entity corpses without health bar.

Posted: Sat Sep 14, 2019 1:43 pm
by mrvn
Bilka wrote: Sat Sep 14, 2019 8:36 am Set the time to live of the other ghosts to max uint: https://lua-api.factorio.com/latest/Lua ... me_to_live
Doing it before the entity.die() gives:

Code: Select all

Error while running event LogisticTrainOrganizer::on_entity_died (ID 4)
Entity is not ghost, combat robot or highlight box entity.
Doing it after entity.die() gives:

Code: Select all

Error while running event LogisticTrainOrganizer::on_entity_died (ID 4)
LuaEntity API call when LuaEntity was invalid.
I figure I have to do this to the ghost but entity.die() only returns a bool, not the ghost it creates. So now I have to surface.find_entity_filtered(position=entity.position)?

Re: Entity corpses without health bar.

Posted: Sat Sep 14, 2019 2:01 pm
by mrvn

Code: Select all

local function secondary_corpse(event, entity)
  local name = entity.name
  local surface = entity.surface
  local pos = entity.position
  entity.destructible = true
  entity.die(event.force, event.cause)
  ghosts = surface.find_entities_filtered{position=pos}
  for _, ghost in ipairs(ghosts) do
    if (ghost.name == "entity-ghost") and (ghost.ghost_name == name) then
      ghost.time_to_live = 4294967295
    end
  end
end