Creating a Building That Requires No Power?

Place to get help with not working mods / modding interface.
Post Reply
TheLastRonin
Inserter
Inserter
Posts: 23
Joined: Thu Jan 22, 2015 8:22 pm
Contact:

Creating a Building That Requires No Power?

Post by TheLastRonin »

I'm trying to completely remove the power requirements for the lab. If I just comment out the power stuff it seems to throw up errors... If I reduce power to 0watts it still needs 'power' according to the game... Is there any way of having a completely un-powered buildings?

Please take the time to respond. I am trying to do a major overhaul mod and this has been a huge roadblock for me... I'm at a total loss :(.

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

Re: Creating a Building That Requires No Power?

Post by FreeER »

The way Factorio is designed in C++ most entities require power, but if you can make it require 0 power (can't remember off the top of my head if that works) then you could use control.lua to give that building 1 energy when it's created. That would satisfy it's power need (since it doesn't ever use that power). It's a hack sure, but I've used uglier ones :)

Code: Select all

game.onevent(defines.events.onbuiltentity, function(event)
  event.createdentity.energy = 1
end)
game.onevent(defines.events.onrobotbuiltentity, function(event)
  event.createdentity.energy = 1 -- I'm assuming this is createdentity as well, could test with game.player.print(serpent.block(event))
end)
The alternative, if you can't set it not use energy, would be either filling it's energy constantly or creating an invisible entity that could do so (solar panel + accumulator?) right on top of it (along with a pole with a very small range).
<I'm really not active any more so these may not be up to date>
~FreeER=Factorio Modding
- Factorio Wiki
- My Factorio Modding Guide
- Wiki Modding Guide
Feel free to pm me :)
Or drop into #factorio on irc.esper.net

TheLastRonin
Inserter
Inserter
Posts: 23
Joined: Thu Jan 22, 2015 8:22 pm
Contact:

Re: Creating a Building That Requires No Power?

Post by TheLastRonin »

Would I just paste that code into control? How would I link it up to my entity? Sorry I am a code noob.

The entity is called alchemical-lab

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

Re: Creating a Building That Requires No Power?

Post by FreeER »

The previous code would add 1 energy to all created entities, to make it only target your entity you'd add an if statement checking the name like so:
And yes, this would be pasted into the control.lua

Code: Select all

require "defines" -- makes defines table with events available
    game.onevent(defines.events.onbuiltentity, function(event)
      if event.createdentity.name == "alchemical-lab" then
           event.createdentity.energy = 1
      end
    end)
    game.onevent(defines.events.onrobotbuiltentity, function(event)
      -- I'm assuming this is createdentity as well, could test with game.player.print(serpent.block(event))
      if event.createdentity.name == "alchemical-lab" then
           event.createdentity.energy = 1
      end
    end)
TheLastRonin wrote:Sorry I am a code noob.
Everyone starts that way, including me :)

TheLastRonin
Inserter
Inserter
Posts: 23
Joined: Thu Jan 22, 2015 8:22 pm
Contact:

Re: Creating a Building That Requires No Power?

Post by TheLastRonin »

FreeER wrote:The previous code would add 1 energy to all created entities, to make it only target your entity you'd add an if statement checking the name like so:
And yes, this would be pasted into the control.lua

Code: Select all

require "defines" -- makes defines table with events available
    game.onevent(defines.events.onbuiltentity, function(event)
      if event.createdentity.name == "alchemical-lab" then
           event.createdentity.energy = 1
      end
    end)
    game.onevent(defines.events.onrobotbuiltentity, function(event)
      -- I'm assuming this is createdentity as well, could test with game.player.print(serpent.block(event))
      if event.createdentity.name == "alchemical-lab" then
           event.createdentity.energy = 1
      end
    end)
TheLastRonin wrote:Sorry I am a code noob.
Everyone starts that way, including me :)
That didn't work but I had another idea... I can turn the well into a burner and then simply insert a new object that has ridiculous energy output while the well has only '0.1' energy need. So how would I change the code so that instead of giving energy it inserts 1 supercoal when built?

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

Re: Creating a Building That Requires No Power?

Post by FreeER »

TheLastRonin wrote:So how would I change the code so that instead of giving energy it inserts 1 supercoal when built?
instead of "event.createdentity.energy = 1" you'd use "event.createdentity.insert{name='super-coal', count=1}", if that didn't automatically go into the fuel slot (usually does, but thought I'd mention it) you'd use "event.createdentity.getinventory(defines.inventory.fuel).insert{name='super-coal', count=1}"

Post Reply

Return to “Modding help”