"On entity attacked" event

Post Reply
User avatar
Reika
Filter Inserter
Filter Inserter
Posts: 582
Joined: Tue May 19, 2015 1:56 am
Contact:

"On entity attacked" event

Post 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.
Image

Rseding91
Factorio Staff
Factorio Staff
Posts: 13209
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: "On entity attacked" event

Post 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.
If you want to get ahold of me I'm almost always on Discord.

User avatar
Reika
Filter Inserter
Filter Inserter
Posts: 582
Joined: Tue May 19, 2015 1:56 am
Contact:

Re: "On entity attacked" event

Post 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.
Image

Rseding91
Factorio Staff
Factorio Staff
Posts: 13209
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: "On entity attacked" event

Post 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.
If you want to get ahold of me I'm almost always on Discord.

Post Reply

Return to “Implemented mod requests”