No ghost on entity death

Place to get help with not working mods / modding interface.
User avatar
Sirenfal
Long Handed Inserter
Long Handed Inserter
Posts: 50
Joined: Tue Jan 10, 2017 1:42 am
Contact:

No ghost on entity death

Post by Sirenfal »

Is there a way to specify that I do not want an automatic ghost for a particular entity when it dies?

I can do that with a hook like this, but it's not exactly clean-

Code: Select all

script.on_event(defines.events.on_entity_died, function(event)
	if(event.entity.name == 'my_entity') then
		local ent = event.entity
		local surface = ent.surface
		local pos = ent.position
		local corpse = ent.prototype.corpses

		ent.destroy()

		-- this isn't available to prototype information at runtime
		surface.create_entity({
			name='medium-explosion',
			position=pos,
		})

		for corpse_name, _ in pairs(corpse) do
			surface.create_entity({
				name=corpse_name,
				position=pos,
			})
		end

		return
	end
end)
User avatar
aubergine18
Smart Inserter
Smart Inserter
Posts: 1264
Joined: Fri Jul 22, 2016 8:51 pm
Contact:

Re: No ghost on entity death

Post by aubergine18 »

IIRC there's a "not-repairable" flag you can define on entity prototypes - if false, ghosts don't appear on destroy.
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.
Post Reply

Return to “Modding help”