Code: Select all
script.on_event(defines.events.on_entity_died, function(event)
local entity = event.entity
local train = entity.train
-- stops the train
train.speed = 0
-- creates ghost entity
game.surfaces[entity.surface.name].create_entity{
name = "entity-ghost",
inner_name = entity.name,
position = entity.position,
direction = entity.direction,
force = entity.force,
create_build_effect_smoke = false,
}
end, {{filter = "rolling-stock"}})
Reproduction steps
- Paste the code above into control.lua
- Start a game and build some rails
- Take a locomotive item
- Press R
- Build the locomotive
- Shoot the locomotive
- Observe that the created ghost is the wrong way around
If you do it without pressing R the locomotive has the right direction.