Page 1 of 1

Detect blueprint making [Resolved]

Posted: Mon Jan 25, 2016 8:48 pm
by Phenix0cs
I made a mod that offer a hybrid chest requester/provider.

My issue is that i need to detect when a blueprint is in the making, so it can keep requests in the blueprint.

Does anyone know a way to detect when a blueprint is made?

My mod: https://forums.factorio.com/forum/vie ... 97&t=19438

Source code: https://github.com/Phenix0cs/Smarter-chests

Re: Detect blueprint making

Posted: Tue Jan 26, 2016 12:04 am
by DaveMcW
If your primary entity is a requester, it should keep requests in blueprints automatically.

There is no blueprint_created event.

Re: Detect blueprint making

Posted: Tue Jan 26, 2016 2:34 am
by Phenix0cs
I know that, but my mod need to disable requests most of the running time.
What I'm looking for is a state that indicate that a blueprint is in the making, I can create my own event if needed.

Re: Detect blueprint making

Posted: Tue Jan 26, 2016 3:04 pm
by Phenix0cs
If it help understand, I will show how i manage to keep requests when the chest is destroyed.

So when I detect that the chest died, I restore the requester slots then destroy the linked entity and cleanup links.

Code: Select all

function entity_died(event)
   if event.entity.name == "logistic-chest-storage2-ui" then
      local pos = position(event.entity)
      local link = global.storage_links[position(event.entity)]
      
      -- Recover requester slots
      for slot = 1,8 do -- TODO Change if number of slots can be retrived
         request = link.requester_slots[slot]
         if request ~= nil then
            event.entity.set_request_slot(request,slot)
         end
      end
      
      link.storage.destroy()
      global.storage_links[position(event.entity)] = nil
      cleanup_links()
   end
end

Re: Detect blueprint making

Posted: Tue Jan 26, 2016 8:58 pm
by rk84
on_built_entity triggers for all "entity-ghost" entities that blueprint produces. You can check player's cursorstack to make sure they are from blueprint.

Re: Detect blueprint making

Posted: Wed Jan 27, 2016 3:08 pm
by Phenix0cs
Thanks rk84, with your hints I was able to figure out how to do it.

Code: Select all

function put_item(event)
   if game.player.cursor_stack.valid_for_read and 
   game.player.cursor_stack.name == "blueprint" then
      -- code goes here
   end
end

script.on_event({defines.events.on_put_item}, put_item)