Page 1 of 1

"On entity attacked" event

Posted: Sat Jun 24, 2017 6:50 pm
by Reika
Exactly as it sounds, ideally cancelable as well. If you are familiar with MinecraftForge, that is the sort of implementation I am describing; right before the entity is dealt damage, the event is fired with information including damage type, amount, and source entity (if any) and ideally can be cancelled to prevent the attack from actually dealing damage. In Minecraft this is used for things like Power Armor, but in Factorio it could be used for, for example, making spawners spawn things on being attacked, or turrets that are only vulnerable to acid, or the like.

Even if cancelability is impossible, the event itself allows for effective cancelability by scheduling healing.

Re: "On entity attacked" event

Posted: Sat Jun 24, 2017 10:13 pm
by Rseding91
We talked about adding an on-attacked event in the past but it was decided against due to performance concerns.

Knowing more about the game now than I did in the past it might be ok to add such an event. Things aren't attacked that frequently even during heavy combat due to projectile speeds and such.

About being able to cancel it: I don't know. Factorio doesn't support any kind of event cancellation as it is now so it depends how much time it would take to alter the core game and if it could be altered without having to re-write large portions of the damage system.

Re: "On entity attacked" event

Posted: Sun Jun 25, 2017 12:47 am
by Reika
Rseding91 wrote:We talked about adding an on-attacked event in the past but it was decided against due to performance concerns.
Given the existence of on_tick, I am not sure this is worth concerning oneself with.

Re: "On entity attacked" event

Posted: Sun Jun 25, 2017 10:11 am
by Rseding91
Reika wrote:
Rseding91 wrote:We talked about adding an on-attacked event in the past but it was decided against due to performance concerns.
Given the existence of on_tick, I am not sure this is worth concerning oneself with.
Where the event originates from isn't the concern: it's how frequently it will be called. on_tick is called at most once per tick per mod subscribed. Any event can do any amount of logic it wants so there's nothing inherently "slow" about on_tick.

Now picture an event that's fired every time an assembling machine makes a bit of progress - even when just 1 mod listens to it it would have considerable overhead due to how frequently it fired.