Page 1 of 1

How to detect vehicles running out of fuel

Posted: Tue Apr 05, 2022 6:09 pm
by UpsideDownFoxxo
I wanted to dip my toes into factorio modding, and thought of a (in my mind) rather simple QoL mod:
Make automated vehicles (like trains, maybe even AAI stuff) request fuel through the item delivery system (blue triangle) once they run out of it.
When looking at the forum documentation, i found no premade event, or a way to get the fuel value from a train object.

Re: How to detect vehicles running out of fuel

Posted: Tue Apr 05, 2022 7:15 pm
by DaveMcW
The concept is simple, but the implementation is not. There is no event support. You have to track everything yourself using global.tables and the on_tick event.

For the fuel value, look at locomotive.burner.heat and locomotive.burner.remaining_burning_fuel

Re: How to detect vehicles running out of fuel

Posted: Tue Apr 05, 2022 10:14 pm
by Qon
That is a worthy endeavor, cool idea for a mod! There are probably a lot of people that would like to have that as well. :D
I would recommend on_train_changed_state instead of on_tick to reduce performance impact. Do trains really need to start requesting more fuel while going 10x faster than the bots that are supposed to service them? The train is going to arrive in another roboport network or closer to another chest of fuel before the fuel is delivered anyways.

Re: How to detect vehicles running out of fuel

Posted: Tue Apr 05, 2022 11:00 pm
by robot256

Re: How to detect vehicles running out of fuel

Posted: Thu Apr 07, 2022 9:55 am
by disentius
Another one that looks at train fuel:
https://mods.factorio.com/mod/Train_Control_Signals