Page 1 of 1

More entity event hooks

Posted: Tue Jan 21, 2014 10:09 pm
by Copern
Looking at Lua/Events in the wiki I notice there only seems to be events for the player or game with the exception of "onentitydied". Something I'd like see is events along the lines of...
  • ontimerstarted (smelters/assemblers/miners) contains Entity
  • ontimerfinished (smelters/assemblers/miners) contains Entity
  • onitemcreate (smelters/assemblers/miners) contains ItemStack
  • oninserterpickup (inserters) contains ItemStack
  • oninserterdrop (inserters) contains ItemStack (or maybe ItemEntity?)
  • onsplit (splitters) contains ItemEntity
Possibly others related to accumulators, turrets, etc. These are just examples of course.

Or perhaps a way to attach functions with specific signatures to prototypes. For example, that function would be called any time that type of entity's timer finishes.

Re: More entity event hooks

Posted: Wed Jan 22, 2014 9:29 am
by slpwnd
This would add more modding possibilities but we need to be performance aware. Calling the lua code is quite expensive operation. And there can be many inserters in a big factory calling on pickup every tick. Hmmm but I suppose often you would be interested (for the modding) in calling this only for specific (a few) machines right? That would be doable, because when the event handler is created it could specify an entity filter to be applied to.

Re: More entity event hooks

Posted: Wed Jan 22, 2014 10:22 am
by Dysoch
Onitemcreate is something i want badly. Right now my dynamic system only works with hand crafted items, and only with the item itself.

Could the onplayercrafteditem event be changed to also include the intermediates needed for an item?

Re: More entity event hooks

Posted: Fri Jan 24, 2014 2:51 am
by Copern
slpwnd wrote:This would add more modding possibilities but we need to be performance aware. Calling the lua code is quite expensive operation. And there can be many inserters in a big factory calling on pickup every tick.
I understand, I assumed that would be an issue. The oninserterpickup was probably a bad example. I figured I would throw those in there anyway since it's something that would be nice to have.
slpwnd wrote:Hmmm but I suppose often you would be interested (for the modding) in calling this only for specific (a few) machines right? That would be doable, because when the event handler is created it could specify an entity filter to be applied to.
That is correct, I'd only want to be subscribed to events coming from specific types of entities. No sense for all factories to invoke events when a modder only wants to know the ones from his/her custom factories, right?

Oh, onitemcreate could also contain the entity that created the item.

Re: More entity event hooks

Posted: Fri Jan 24, 2014 8:47 am
by SilverWarior
Is it posible to dynamically assign LUA methods to certain events?
In Objective Pascal events are defined as objects which point to event methods. So when event is fired a quick check is made to see if Event method has been assigned. If it was assignesd method is executed if not nothing happens. So there is practically no performance loss when you have lots of events which doesn't have assigned event methods to them.

Re: More entity event hooks

Posted: Fri Jan 24, 2014 10:03 am
by Copern
SilverWarior wrote:Is it posible to dynamically assign LUA methods to certain events?
That's what I proposed in the OP.
Copern wrote:Or perhaps a way to attach functions with specific signatures to prototypes. For example, that function would be called any time that type of entity's timer finishes.
Basically you would define functions for events in the prototype. If there was no function defined in the prototype, you could avoid the lua call entirely.