Entity corpses without health bar.

Place to get help with not working mods / modding interface.
Post Reply
mrvn
Smart Inserter
Smart Inserter
Posts: 5709
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Entity corpses without health bar.

Post 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 386 times
Ideas?

Bilka
Factorio Staff
Factorio Staff
Posts: 3133
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: Entity corpses without health bar.

Post by Bilka »

Set the time to live of the other ghosts to max uint: https://lua-api.factorio.com/latest/Lua ... me_to_live
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.

mrvn
Smart Inserter
Smart Inserter
Posts: 5709
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: Entity corpses without health bar.

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

mrvn
Smart Inserter
Smart Inserter
Posts: 5709
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: Entity corpses without health bar.

Post 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

Post Reply

Return to “Modding help”