Custom power plants?

Place to get help with not working mods / modding interface.
Post Reply
Forien
Inserter
Inserter
Posts: 26
Joined: Sat Jul 19, 2014 9:16 am
Contact:

Custom power plants?

Post 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).
My mods:
- Power Mod (WiP)

User avatar
FreeER
Smart Inserter
Smart Inserter
Posts: 1266
Joined: Mon Feb 18, 2013 4:26 am
Contact:

Re: Custom power plants?

Post 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 :)

Forien
Inserter
Inserter
Posts: 26
Joined: Sat Jul 19, 2014 9:16 am
Contact:

Re: Custom power plants?

Post 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
My mods:
- Power Mod (WiP)

User avatar
ludsoe
Fast Inserter
Fast Inserter
Posts: 243
Joined: Tue Feb 11, 2014 8:16 am
Contact:

Re: Custom power plants?

Post by ludsoe »

MoPower has wind-turbines, you can tear into the code for that if you want.

tdzl2003
Burner Inserter
Burner Inserter
Posts: 12
Joined: Wed Apr 30, 2014 10:40 am
Contact:

Re: Custom power plants?

Post 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)
Last edited by tdzl2003 on Tue Aug 12, 2014 6:26 pm, edited 1 time in total.

tdzl2003
Burner Inserter
Burner Inserter
Posts: 12
Joined: Wed Apr 30, 2014 10:40 am
Contact:

Re: Custom power plants?

Post by tdzl2003 »

I'm working on my mod at:
https://github.com/tdzl2003/PTech

You can have a look on my code.

tdzl2003
Burner Inserter
Burner Inserter
Posts: 12
Joined: Wed Apr 30, 2014 10:40 am
Contact:

Re: Custom power plants?

Post 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?

User avatar
ludsoe
Fast Inserter
Fast Inserter
Posts: 243
Joined: Tue Feb 11, 2014 8:16 am
Contact:

Re: Custom power plants?

Post 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.

Post Reply

Return to “Modding help”