After tinkering around with entity.energy and entity.burner I figured out that BOTH doesnt update the Fuel Bar in the Train.
So, my Code:
Code: Select all
local PowerNeed = 0
local PowerStorage = 0
local PowerPer = 0
if global.SenpaisTrainsList ~= nil and global.SenpaisAccuList ~= nil then
for _, p in pairs( global.SenpaisTrainsList ) do
PowerNeed = PowerNeed + ( p.entity.burner.heat_capacity - p.entity.burner.heat )
end
for _, a in pairs( global.SenpaisAccuList ) do
PowerStorage = PowerStorage + a.energy
end
if PowerStorage >= PowerNeed then
for _, u in pairs( global.SenpaisTrainsList ) do
u.entity.burner.heat = u.entity.burner.heat_capacity
end
PowerPer = PowerNeed / #global.SenpaisAccuList
for _, o in pairs( global.SenpaisAccuList ) do
o.energy = o.energy - PowerPer
end
else
for _, w in pairs( global.SenpaisAccuList ) do
w.energy = 0
end
PowerPer = PowerStorage / #global.SenpaisTrainsList
for _, n in pairs( global.SenpaisTrainsList ) do
n.entity.burner.heat = PowerPer
end
end
end
I hope you fix this and it was hepful.
Greetz,
Luzifer