Page 1 of 1

Custom power plants?

Posted: Mon Jul 21, 2014 11:31 am
by Forien
Hello there again!

I'm now a little sad as "generator" type NEEDS to have liquid to work. I'm sad that "solar-panel" works only within a day. And that "assembly-machine" can't produce energy.

I would like to see entity type (maybe there is and I just don't know it), which can produce power without fuel (let's say solar-panel 24/7 like geothermal power plant), or which can use any recipe (not only fuel) and produce power with it. If there is something capable of any of the above, please tell me. If not, how can I make it via control (if I may at all).

Re: Custom power plants?

Posted: Mon Jul 21, 2014 5:26 pm
by FreeER
Forien wrote:I'm now a little sad as "generator" type NEEDS to have liquid to work. I'm sad that "solar-panel" works only within a day. And that "assembly-machine" can't produce energy.
Unfortunate facts of Factorio... we're all a little bit saddened by these.
This will need to be done via control.lua, read this topic first where I've answered (practically) the same question, and then if you have further questions feel free to ask :)

Re: Custom power plants?

Posted: Tue Jul 22, 2014 8:15 pm
by Forien
Well, I made it work, but two things are distressing about what I've done.
1) I need to add energy every tick (when it's dark)
2) HUD of plant shows 0W (at night) and doesn't work as expected (efficienty still works as Solar Panel's)

But hey, it works! :D

Re: Custom power plants?

Posted: Wed Jul 23, 2014 6:18 am
by ludsoe
MoPower has wind-turbines, you can tear into the code for that if you want.

Re: Custom power plants?

Posted: Tue Aug 12, 2014 6:17 pm
by tdzl2003
I've tried the same thing. Here's my idea:

you can use an "accumulator" instead of a "solar panel".

It's important because you can save energy with an accumulator, but not with a solar panel.

I'd try this, and it works very well:

Code: Select all

    energy_source =
    {
      type = "electric",
      buffer_capacity = "50kJ",
      usage_priority = "primary-output",
      input_flow_limit = "0kW",
      output_flow_limit = "30kW"
    },

Code: Select all

require "util"
require "defines"

game.oninit( 
  function() 
    glob.staticEnergyGenerators = {} 
  end
)

game.onload(
  function()
    if not glob.staticEnergyGenerators then
      glob.staticEnergyGenerators = {}
    end
  end
)

local function log(d)
	game.getplayer().print(d)
end

game.onevent(
  defines.events.onbuiltentity,
  function(event)
  	log("something built")
    if event.createdentity.name == "wind-generator" then
    	log("generator built")
      table.insert(glob.staticEnergyGenerators, event.createdentity)
    end
  end
)

game.onevent(defines.events.ontick, function(event) 
  if (event.tick % 60 == 0) then
  	log("doing evil")

    for index, reactor in ipairs(glob.staticEnergyGenerators) do
      if not reactor.valid then 
        table.remove(glob.staticEnergyGenerators, index)
      else
      	log("effecting generators")
        reactor.energy = 1000000000
      end
    end
  end
end)

Re: Custom power plants?

Posted: Tue Aug 12, 2014 6:21 pm
by tdzl2003
I'm working on my mod at:
https://github.com/tdzl2003/PTech

You can have a look on my code.

Re: Custom power plants?

Posted: Mon Sep 08, 2014 6:32 am
by tdzl2003
There's a new problem for me.

`onbuiltentity` event will not be invoked if a entity was built by a robot.

Any idea about it?

Re: Custom power plants?

Posted: Tue Sep 09, 2014 7:04 pm
by ludsoe
tdzl2003 wrote:There's a new problem for me.

`onbuiltentity` event will not be invoked if a entity was built by a robot.

Any idea about it?
There's no way around it till the devs update the modding API. You can however use the script interfaces to add a function that can be ran from the in-game console to search for nearby entity's.