Page 1 of 1

Triggering Smoke on Entity

Posted: Mon Jun 09, 2025 4:15 pm
by JDCalvert
Hi all,

I'm trying to alter the smoke generation for a locomotive. I've made a mod (https://mods.factorio.com/mod/jd-speed-limits) to slow down trains on sections of track. At the moment, a train continues to put out a lot of smoke even when travelling at (and maintaining) a low speed. A feature of the mod is that the train uses less fuel when it's maintaining a low speed. I'd like to show that visually by generating less smoke when less power is being used.

My first idea was to turn off the locomotive's smoke entirely, and instead generate it in Lua, ideally making it look exactly the same as the normal smoke. I tried running this each frame as an experiment:

Code: Select all

for _, locomotive in ipairs(train.locomotives.front_movers) do
    locomotive.surface.create_trivial_smoke({name='train-smoke', position=locomotive.position})
end
However, this doesn't give the smoke all the properties that the locomotive's burner does, like telling it how to move. It appears at the locomotive and then runs its animation while remaining static. There aren't any other options to pass into the function (https://lua-api.factorio.com/latest/cla ... vial_smoke) to add these details.

Does anyone have any ideas of how I can achieve this?

Re: Triggering Smoke on Entity

Posted: Mon Jun 09, 2025 4:58 pm
by Osmo
You could modify the drive_over_tie_trigger to produce smoke and remove/reduce smoke from the energy source. https://lua-api.factorio.com/latest/pro ... ie_trigger

Re: Triggering Smoke on Entity

Posted: Wed Jun 11, 2025 10:18 am
by JDCalvert
Hi, thanks for this. I didn't end up using that trigger, but you did get me looking at triggers. In the end, I went for creating a dummy particle which triggers the smoke being created: https://lua-api.factorio.com/stable/pro ... ger_effect. I doubt it's very performant, but it gives me direct control over how much smoke is created, which is just what I wanted.

The only problem now is that, when the train goes over an elevated rail, the smoke still renders where it would if the train were on the ground! I'll have to figure out how to determine the train sprite's height or something, and then render the smoke in the right place.

Re: Triggering Smoke on Entity

Posted: Wed Jun 11, 2025 8:56 pm
by Osmo
If you move it by script, you can use https://lua-api.factorio.com/latest/cla ... #draw_data to get the height. But i don't know if there is a way to do it naturally in a trigger (apart from doing different things in drive_over_tie_trigger and drive_over_elevated_tie_trigger, which you're not using, and understandably so)