Page 1 of 1

Event for item-request-proxy creation/destruction

Posted: Wed Jun 19, 2019 5:21 pm
by Choumiko
Could we get some event when item-request-proxies are created or destroyed?

I want to sort modules in a specific order and right now i'd have to:
  • watch for all kind of events that could create one
  • save them in global
  • check every X ticks if they are still valid and if they are check again later etc until they are invalid and then i can finally do what the mod is supposed to do
Ideally the events would be created when the proxy is already/still valid, so i can get it's target and modules properties

Re: Event for item-request-proxy creation/destruction

Posted: Wed Jun 19, 2019 5:30 pm
by DaveMcW

raise on_entity_created for item_request_proxies

Posted: Sat Aug 31, 2019 8:47 pm
by Optera
Problem:
Blueprint containing an assembler with modules

Bots build the assembler, this raises on_robot_built_entity for the assembler, reviving the ghost and replacing the item_requests the ghost held with an item-request-proxy.
The problem now is how to get that item-request-proxy without doing a surface search for every created entity.

While the proxy knows its target entity the target entity does not know its proxy nor does the creation of the proxy raise an event.

Solution:
raise on_entity_created (or similar) when creating an item-request-proxy

Re: raise on_entity_created for item_request_proxies

Posted: Sat Aug 31, 2019 9:57 pm
by DaveMcW
Surface search is not a problem if you only run it in a small area on build events.

Code: Select all

function on_built(event)
  local entity = event.created_entity or event.entity or event.destination
  if not entity or not entity.valid then return end
  for _, proxy in pairs(entity.surface.find_entities_filtered{type="item-request-proxy", position=entity.position}) do
    script.raise_event(defines.events.script_raised_built, {entity = proxy})
  end
end

Re: raise on_entity_created for item_request_proxies

Posted: Sun Sep 01, 2019 6:15 am
by Optera
You are missing the point.
Surface search has to run on EVERY entity creation to catch potential proxies. Creating avoidable overhead.
Arguing that way we should do away with all creation and removal events and just run surface scans in on_tick to catch created entities.

Regarding your snippet:
Its even more efficient to run

Code: Select all

local proxy = entity.surface.find_entity("item-request-proxy", entity.position)
as there should only ever be a single proxy on top of an entity.

Re: Event for item-request-proxy creation/destruction

Posted: Mon Sep 02, 2019 9:24 am
by Klonan
Merged with similar topic