How to detect vehicles running out of fuel

Place to get help with not working mods / modding interface.
UpsideDownFoxxo
Burner Inserter
Burner Inserter
Posts: 10
Joined: Mon Aug 30, 2021 2:19 am
Contact:

How to detect vehicles running out of fuel

Post 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.
User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3724
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: How to detect vehicles running out of fuel

Post 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
Qon
Smart Inserter
Smart Inserter
Posts: 2164
Joined: Thu Mar 17, 2016 6:27 am
Contact:

Re: How to detect vehicles running out of fuel

Post 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.
My mods: Capsule Ammo | HandyHands - Automatic handcrafting | ChunkyChunks - Configurable Gridlines
Some other creations: Combinassembly Language GitHub w instructions and link to run it in your browser | 0~drain Laser
User avatar
disentius
Filter Inserter
Filter Inserter
Posts: 694
Joined: Fri May 12, 2017 3:17 pm
Contact:

Re: How to detect vehicles running out of fuel

Post by disentius »

Another one that looks at train fuel:
https://mods.factorio.com/mod/Train_Control_Signals
Post Reply

Return to “Modding help”