[1.1.33] Rotated locomotive returns wrong direction
Posted: Sat May 15, 2021 3:24 pm
I am a bit hesitant to post this here since I fear I just did something wrong but I am 99% certain this is not my fault. Anyway I wrote a mod that stops a train if one of its rolling stock gets destroyed and creates a ghost to replace it.
The issue I am having is that the created locomotive ghosts are the wrong way around if the destroyed locomotives got rotated before they got built.
Reproduction steps
If you do it without pressing R the locomotive has the right direction.
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.