[Updated Question] machine is running + Energy Network Value

Place to get help with not working mods / modding interface.
Post Reply
masshuu
Manual Inserter
Manual Inserter
Posts: 3
Joined: Tue Jan 06, 2015 4:15 am
Contact:

[Updated Question] machine is running + Energy Network Value

Post by masshuu »

[Edited to clarify some stuff]

So I have some custom type = "assembling-machine" machine. The primary thing is I cannot figure out how to tell if it is crafting or not and the wiki isn't the most helpful.

Is there a way to check if an item is being made? Perhaps just getting the number of ingredients in the main slot?


The second and much more awesome thing would be how to check how much energy is available on the network and pull it out of the network.
Basically once built, it has a 1MW drain so it takes a lot of power regardless of if its being used or not. I first needs an activation energy of 100MW.

If so then I either need to be able to then modify the energy requirement.

If you can't modify how much energy it requires could I do the following? \(I'm sure i could, ive not tried however. I know you can set what item drops and the item would be set to place the Machine_Deactivated entitiy.

Have 3 entities:

Machine_Deactivated - Empty crafting list so it can't craft anything
- Checks grid for power availability and when above target, remove and replace entity with Machine_Charging

Machine_Charging - Entity with 100MW drain. Also empty crafting list.
- After one second of existing this is replaced with the Machine_Active

Machine_Active
- Actual machine with recipes.

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

Re: [Updated Question] machine is running + Energy Network V

Post by FreeER »

masshuu wrote:The primary thing is I cannot figure out how to tell if it is crafting or not and the wiki isn't the most helpful.
well, as listed on the wiki for Lua/Entity Assembling Machines you can check what recipe they have set with entity.recipe (assuming entity is a stored reference to an assembling machine gotten through onbuiltentity, onrobotbuiltentity, etc.). Since you need a recipe set to make anything if that is nil, you know the AM isn't crafting. Further (or prior) according to Lua/Entity you can get the energy level of an entity with entity.energy, if it has a very small amount of energy it probably isn't crafting (note: last time I experimented with this energy could be a very tiny non-0 number like 0.00000001 so don't just compare to 0!). Lastly according to Lua/Entity (admittedly this one doesn't have an example) you can get the inventories of an entity with entity.getinventory(inventoryIndex) and that some indexes are listed in the defines. Apparently there isn't anything on defines on the wiki but you can find the file by searching the Factorio directory for defines, opening it reveals that both assemblingmachineinput and assemblingmachineoutput are defined. Thus it is also possible to check if the AM has ingredients and if there are any items sitting in the output (which means an inserter isn't taking them out) via AM.getinventory(defines.inventory.assemblingmachineoutput), and the wiki page for Lua/Inventory reveals an isempty method.
rough example:

Code: Select all

require "defines"
local am = reference-to-assembling-machine
if am.energy > 0.001 and am.recipe ~= nil and not am.getinventory(defines.inventory.assemblingmachineinput).isempty() then
  -- am is fully capable of crafting at this moment, assuming output is not full, which could also be checked...
end
masshuu wrote:check how much energy is available on the network
That is unfortunately the hard (near impossible) one... There's no access to the energy 'networks', only individual entities' energy buffers. Theoretically you could store a list of all the energy entities and poll them when needed but it'd probably be slow... You also can't change the energy requirement of a machine, however, according to Lua/Entity again there is an "active" property which essentially disables an entity, but they still get filled with energy. So you can immediately set AM.active = false and 'steal' it's energy (have a variable for each AM in the glob and increment that by AM.energy, then set AM.energy = 0) until it meets the requirements at which point you set AM.active = true and stop draining the energy.

Hope that helps some.
<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

masshuu
Manual Inserter
Manual Inserter
Posts: 3
Joined: Tue Jan 06, 2015 4:15 am
Contact:

Re: [Updated Question] machine is running + Energy Network V

Post by masshuu »

Thanks.

I think I may wait and see until there is an API added to make it easier/possible to do so.

My intention is a Fusion reactor which works so far, outside the fact that once built I don't like how OP it is (Assuming you can keep H stockpiled and use or store the He which is also a byproduct of the oil processing required.)

Is also missing graphics. so everythings just white square textures.

My goals with the above was:

Reactor needs to be started with the large power requirement ( "Charging" the superconductor fields)
Reactor needs to continue to recive power once started (Imagine Maintaining fields, running cryogenics to keep everything cool )
If the reactor looses power then it blows up ( Containment fields breaking down )

It didn't take me too much time to put it together though, like a few hours. Most of the time spent was numbers to make it balanced with exsisting gameplay. Numbers at least, eg enegry density of coal/solid fuel, build time, crafting energy requirement, its counter productive unless you get some 10 or more of my "Upgraded" steam engines on it or about 40 vanilla steam engines. At that point you break even in terms of energy required to make the Hydrogen.


"Location: Baytown, Tx, USA" Ahaha bit close. Lovley winter we just had. Shame its back to summer again.

Post Reply

Return to “Modding help”