How do you make a chest require energy to use?
For example have a chest that has a drain of 5kW, but if it does not have any power inserters can not use that chest.
Make chest require energy
Re: Make chest require energy
Not easily.
1. Create an electric-energy-source to drain 5kW.
2. Use a control.lua script to add/remove the drainer when a chest is built/destroyed.
3. Use a control.lua script to enable/disable the chest if the drainer is out of energy, firing every tick.
It's a lot of work to set up, and eats a lot of UPS to run.
1. Create an electric-energy-source to drain 5kW.
2. Use a control.lua script to add/remove the drainer when a chest is built/destroyed.
3. Use a control.lua script to enable/disable the chest if the drainer is out of energy, firing every tick.
It's a lot of work to set up, and eats a lot of UPS to run.
- eradicator
- Smart Inserter
- Posts: 5211
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: Make chest require energy
If the energy buffer is large enough you can check a lot less often, simply by calculating the minimum time it will be able to run off the buffer alone. Also i don't think you can "deactivate the chest", you'll have to deactivate the inserters.DaveMcW wrote: and eats a lot of UPS to run.
Definetly not a beginners mod, unless you like a really diabolic challenge :).
Re: Make chest require energy
That seems complicated.DaveMcW wrote:Not easily.
1. Create an electric-energy-source to drain 5kW.
2. Use a control.lua script to add/remove the drainer when a chest is built/destroyed.
3. Use a control.lua script to enable/disable the chest if the drainer is out of energy, firing every tick.
It's a lot of work to set up, and eats a lot of UPS to run.
Re: Make chest require energy
It is Chests are not meant to take power because that adds a ton of overhead to moving items around which happens frequently so if you want to make the game do it you have to use extreme workarounds.tat3rjr wrote:That seems complicated.DaveMcW wrote:Not easily.
1. Create an electric-energy-source to drain 5kW.
2. Use a control.lua script to add/remove the drainer when a chest is built/destroyed.
3. Use a control.lua script to enable/disable the chest if the drainer is out of energy, firing every tick.
It's a lot of work to set up, and eats a lot of UPS to run.
If you want to get ahold of me I'm almost always on Discord.
- bobingabout
- Smart Inserter
- Posts: 7352
- Joined: Fri May 09, 2014 1:01 pm
- Contact:
Re: Make chest require energy
It is, and I would really suggest you not try and do it, however, the fact that someone can tell you the basic steps on how proves that it can be done if you really want it.tat3rjr wrote:That seems complicated.
Re: Make chest require energy
https://lua-api.factorio.com/latest/events.html
Code: Select all
function on_built_entity OR on_robot_built_entity
Place on this surface in this position new accumulator, that can take energy only
Add this chest and this accumulator to the global.elements
end
Code: Select all
function on_tick
if global.elements isn't empty then take the next element
if the accumulator in the element has power, then take some energy, if not, then find all inserters about it and disable them. Set flag disabled = true
if it was disabled, but now we have power, then find all inserters and enable them. Set flag disabled = false
end
Code: Select all
function on_player_mined_entity OR on_robot_mined
Find this element, delete accumulator, enable inserters, delete this element from global
end
Re: Make chest require energy
Performance optimization: if you have only one chest and it needs every tick 1 kJ, then it needs 60 kW power supply.
If you have two chests, then one tick will be calculated only one of them, take 2 kJ every
second tick and you have also 60 kW.
If you have 7 of them, then just take 7 kJ every 7th tick.
Just check that your accumulator is much bigger than the energy per tick. For 600 chests you are need at least 600 kJ accumulator, then you can calculate 2 chests per tick. Or just make bigger accumulator.
If you have two chests, then one tick will be calculated only one of them, take 2 kJ every
second tick and you have also 60 kW.
If you have 7 of them, then just take 7 kJ every 7th tick.
Just check that your accumulator is much bigger than the energy per tick. For 600 chests you are need at least 600 kJ accumulator, then you can calculate 2 chests per tick. Or just make bigger accumulator.