Giter VIP home page Giter VIP logo

Comments (8)

Afforess avatar Afforess commented on June 12, 2024 2

There is some documentation of attack_reaction on the factorio wiki, but I learned about it through this thread.

from factorio-stdlib.

Afforess avatar Afforess commented on June 12, 2024 1

@aubergine10 This is a good idea and solid start, but theoretically you can do even better than this. If entities have a trigger defined entity-spawn on death (used for biter spawners dropping alien artifacts), you can update prototypes to spawn an invisible entity on death, look for that spawn event, then use that as a general entity death notification. The only drawback is that prototype for the entity type that you want to notify upon death has to be updated before-hand. However, the advantage is that if the entity dies for any reason, in-game or scripted, it should trigger an event.

I think there should be an API to handle updating the prototype in the data-lifecycle phase and triggering the appropriate entity-death events from that as well.

from factorio-stdlib.

originalfoo avatar originalfoo commented on June 12, 2024

Fleshed it out a bit more: https://github.com/aubergine10/lifecycle-events

from factorio-stdlib.

originalfoo avatar originalfoo commented on June 12, 2024

By entity spawn on death do you mean "loot"? If so, that only happens when an entity .die() but not when it .destroy(). Also, the .die() method already triggers an event - the reason that .die() is unsuitable in most cases is that it causes all kinds of other things to happen - explosions, remnants, etc. The mods currently affected require immediate destruction of the entity (such as a vehicle put on to vehicle train, or creative mode clearing entities from an area)...

Also, by time loot is generated, entity has died - this is part of the problem the events are trying to solve. In mods that don't iterate lists of the entities they create/manage, knowing that "something" died is not sufficient - they need the actual entity so they can perform cleanup (eg. of related spawned entities or data).

If I've misunderstood what you were saying, maybe a pseudo-code example would help illustrate?

from factorio-stdlib.

Afforess avatar Afforess commented on June 12, 2024

I actually meant prototypes attack_reaction, which will trigger on damage or death. I suppose it has exactly the same issue as you've described as loot though.

from factorio-stdlib.

originalfoo avatar originalfoo commented on June 12, 2024

I've never seen attack_reaction in any of the vanilla prototypes or mods - do you have some examples of it?

from factorio-stdlib.

originalfoo avatar originalfoo commented on June 12, 2024

Ah, nice, I can think of several uses for that already :)

IMO there still needs to be an optional event for .destroy() and .create_entity() to improve interoperability between mods.

from factorio-stdlib.

Nexela avatar Nexela commented on June 12, 2024

Closed with 536e9a7

from factorio-stdlib.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.