Detect blueprint making [Resolved]

Place to get help with not working mods / modding interface.
Phenix0cs
Inserter
Inserter
Posts: 22
Joined: Mon Jan 11, 2016 1:30 am
Contact:

Detect blueprint making [Resolved]

Post 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
Last edited by Phenix0cs on Wed Jan 27, 2016 3:33 pm, edited 1 time in total.
User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3716
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: Detect blueprint making

Post by DaveMcW »

If your primary entity is a requester, it should keep requests in blueprints automatically.

There is no blueprint_created event.
Phenix0cs
Inserter
Inserter
Posts: 22
Joined: Mon Jan 11, 2016 1:30 am
Contact:

Re: Detect blueprint making

Post 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.
Phenix0cs
Inserter
Inserter
Posts: 22
Joined: Mon Jan 11, 2016 1:30 am
Contact:

Re: Detect blueprint making

Post 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
User avatar
rk84
Filter Inserter
Filter Inserter
Posts: 556
Joined: Wed Feb 13, 2013 9:15 am
Contact:

Re: Detect blueprint making

Post 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.
Test mode
Searching Flashlight
[WIP]Fluid handling expansion
[WIP]PvP gamescript
[WIP]Rocket Express
Autofill: The torch has been pass to Nexela
Phenix0cs
Inserter
Inserter
Posts: 22
Joined: Mon Jan 11, 2016 1:30 am
Contact:

Re: Detect blueprint making

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

Return to “Modding help”