neat requester chest

Place to post guides, observations, things related to modding that are not mods themselves.
Post Reply
judos
Filter Inserter
Filter Inserter
Posts: 266
Joined: Mon Dec 08, 2014 11:17 am
Contact:

neat requester chest

Post by judos »

Hello there,

I would like to make some neat logistics items:
- Neat requester chest:
When placed it searches for assembling machines in 3x3 radius. For all assembling machines found it takes the ingredients for their recipes needed and sets these items as filter to request.
I already have this code:

Code: Select all

require "defines"
require "basic-lua-extensions"

game.on_event(defines.events.on_built_entity, function(event)
	if event.created_entity.name == "logistic-chest-requester-neat" then
		debug(serpent.block(event))
	end
end)
Can you help me how to set the requested items for this chest ? I'm a programmer but I don't know the functions which are available to do this.

Thank you for your response!

jorgenRe
Filter Inserter
Filter Inserter
Posts: 535
Joined: Wed Apr 09, 2014 3:32 pm
Contact:

Re: neat requester chest

Post by jorgenRe »

Firstly there is the beloved wiki:
https://forums.factorio.com/wiki/inde ... quest_slot

Secondly when i create mods i like to see how others did things so i would advice you to check out my mod pneumatic tubes:

Now heres what i know works:
Make requests on the requester

Code: Select all

  if found == 0 then
  slotThere = 0
    for slot = 1, 10 do 
      slotInfo = supplier.get_request_slot(slot)
	  if slotInfo ~= nil then 
	    if slotInfo["name"] == name and slotThere == 0 then
	      slotThere = 1
        end
      elseif slotInfo == nil then
   	    --Set where last empty slot was found!
	    emptySlot = slot
	  end
	end
	   if slotThere == 0 then
	     supplier.set_request_slot({name = name, count = need}, emptySlot)
		 slotThere = 1
	   end
  end
PS just change supplier with the selected entity.

Now here is the part im not so good with:
game.player.print(game.player.selected.recipe.name) -- prints the recipe of the selected assembling machine/furnace
From
https://forums.factorio.com/wiki/inde ... Lua/Recipe

Other than that you can do this to check what the ingredients of an entity is using the:

Code: Select all

/c ingredientsTable = game.player.selected.recipe.ingredients 
which is a table of the ingredients
so if you select an assembler and selects position one in the ingredient table and then the name you can do it like so:

Code: Select all

/c game.player.print(game.player.selected.recipe.ingredients[1].name)
which will return the name of the first ingredient

PS its nice to read something from 4 hours into the future :lol: !
Logo
Noticed the told change in FFF #111 so il continue to use my signature ^_^
Thanks for listening to our suggestions, devs :D!
I would jump of joy if we could specify which tiles spawned in a surfaces

judos
Filter Inserter
Filter Inserter
Posts: 266
Joined: Mon Dec 08, 2014 11:17 am
Contact:

Re: neat requester chest

Post by judos »

Ok nice everything works :) The wiki was a great hint. I didn't really know how to find stuff there before.
Code, how I did it
Now another question arose out of this:
I created a new item "logistic-chest-requester-neat" but actually I want an entity for it as well. My idea is to just reuse the standard requester chest entity.
So right now I set in the items.lua:

Code: Select all

place_result = "logistic-chest-requester",
But obviously then in the "game.on_event(defines.events.on_built_entity," I only get events when the standard chest is built.
Now in the wiki I found the method "on_put_item - Called when players uses item to build something. Called before on_built_entity."

How would you connect those to only execute my function, when the modded chest is placed? Is it save to use a global variable? Or is it better to define my custom entity (the same as the default chest) ?

Thank you for your help

SirRichie
Fast Inserter
Fast Inserter
Posts: 244
Joined: Wed Feb 25, 2015 4:50 pm
Contact:

Re: neat requester chest

Post by SirRichie »

Not sure if this might be the wrong question to ask, but why do you place a different entity?

What you would typcially do is create an entity (see the modding tutorial on how to do that in principle) that is based on the chest but has a different name.

judos
Filter Inserter
Filter Inserter
Posts: 266
Joined: Mon Dec 08, 2014 11:17 am
Contact:

Re: neat requester chest

Post by judos »

Hi SirRichie,

Well actually I did it the following way now:

Code: Select all

local neatSmartInserter = deepcopy(data.raw["inserter"]["smart-inserter"])
neatSmartInserter.name = "neat-smart-inserter"
neatSmartInserter.minable.result = "neat-smart-inserter"
data:extend({	neatSmartInserter })
Where can I find your tutorial? Is this a good approach I took ?

Cheers

SirRichie
Fast Inserter
Fast Inserter
Posts: 244
Joined: Wed Feb 25, 2015 4:50 pm
Contact:

Re: neat requester chest

Post by SirRichie »

It is not my tutorial, it is in the wiki: https://forums.factorio.com/wiki/inde ... g_Tutorial
The tutorial is not up to date regarding the modding API, but it is great for getting the idea (focus on Chapter 4).

judos
Filter Inserter
Filter Inserter
Posts: 266
Joined: Mon Dec 08, 2014 11:17 am
Contact:

Re: neat requester chest

Post by judos »

Very good thanks for the link.

I did a first release already on github. See: Github Releases - NeatLogistics

Post Reply

Return to “Modding discussion”