control.lua get power environment?

Place to get help with not working mods / modding interface.
Post Reply
iUltimateLP
Long Handed Inserter
Long Handed Inserter
Posts: 66
Joined: Sun May 24, 2015 4:41 pm
Contact:

control.lua get power environment?

Post by iUltimateLP »

Hi guys, is it possible to check with the control.lua if a entity has power around him and if yes how much (with around him i mean if its in the range of any electric pole)..
I have my teleporter right now, but I dont find the right class to use. If I put it as a decorative everything works except the animations, but a decorative does not need any power, so if its not possible via the script, which class I can use?
Thanks!

User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5151
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: control.lua get power environment?

Post by Klonan »

Hmm i think you could use something like

Code: Select all


local poles = {}		
		poles =	game.find_entities_filtered{area = {{X -5, Y - 5 }, {X + 5  , Y + 5 }}, name= "medium-electric-pole"}

if poles[1].energy > 0 then do stuff


iUltimateLP
Long Handed Inserter
Long Handed Inserter
Posts: 66
Joined: Sun May 24, 2015 4:41 pm
Contact:

Re: control.lua get power environment?

Post by iUltimateLP »

Klonan wrote:Hmm i think you could use something like

Code: Select all


local poles = {}		
		poles =	game.find_entities_filtered{area = {{X -5, Y - 5 }, {X + 5  , Y + 5 }}, name= "medium-electric-pole"}

if poles[1].energy > 0 then do stuff

Well ok, I should think more :D Thanks!

User avatar
Ranakastrasz
Smart Inserter
Smart Inserter
Posts: 2125
Joined: Thu Jun 12, 2014 3:05 am
Contact:

Re: control.lua get power environment?

Post by Ranakastrasz »

While no way to hook into the power network without searching an entire power network exists that I know of, having your unit be an accumulator, or using a dummy-accumulator (ghost collision mask, no sprite) and setting it's energy to some amount below 100% would let you draw power from a network.

A non-ghost version is in the Forcefield walls mod. https://forums.factorio.com/forum/vie ... =14&t=6862
The forcefield spawner is an accumulator itself, which can only charge, but not discharge, and a script takes power from it as requested, followed by it drawing more power.
My Mods:
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16

Post Reply

Return to “Modding help”