on_entity_damaged event

Vudjun
Burner Inserter
Burner Inserter
Posts: 12
Joined: Fri Mar 04, 2016 8:12 pm
Contact:

on_entity_damaged event

Post by Vudjun »

A suggestion for the event parameters:
- entity - The entity being damaged
- source - The entity doing the damaging
- amount - The amount of damage
- cause - String describing how the damage occurred (e.g. "projectile" / "rocket" / "collision" / "biter")

I need this for my mod to be able to protect entities in an area from damage by other players, so there would have to be a way for the handler to prevent the damage. The best way I've seen this done in other modding APIs is allowing handlers to cancel the event with "event.setCancelled(true)" (A lot of other existing events could use this functionality too)

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

Re: on_entity_damaged event

Post by Rseding91 »

Such an event is unlikely to be added due to performance reasons.

Such an event would be fired hundreds/thousands of times per second during normal combat while not adding a lot of value for the few times it was used.
If you want to get ahold of me I'm almost always on Discord.
Vudjun
Burner Inserter
Burner Inserter
Posts: 12
Joined: Fri Mar 04, 2016 8:12 pm
Contact:

Re: on_entity_damaged event

Post by Vudjun »

Thanks for the response.

I might be able to work around this in my case by having the .destructible property of everything in the area to false when the area is claimed.
Keray
Manual Inserter
Manual Inserter
Posts: 3
Joined: Sun Jun 26, 2016 10:20 pm
Contact:

Re: on_entity_damaged event

Post by Keray »

Rseding91 wrote:Such an event is unlikely to be added due to performance reasons.

Such an event would be fired hundreds/thousands of times per second during normal combat while not adding a lot of value for the few times it was used.
I though of some solution on the top of my head.. Make two types of such event.

First one, specific - has the source of attack, damage, and can be probably modified or cancelled. Would be fired every time an entity takes any damage. But it requires the entity (either attacker or the attacked) to have it defined in their prototype.

Second one, less specific - just tells you which entity was damaged. would be fired for each entity, but if the said entity was attacked in the last 20 ticks, it wont be fired - this way the more generic entities (like aliens and turrets) wont spam thousands of such events per second.

I suggest you implement both, as both are useful in different cases.
dstar4138
Burner Inserter
Burner Inserter
Posts: 8
Joined: Mon Sep 05, 2016 11:00 am
Contact:

Re: on_entity_damaged event

Post by dstar4138 »

Here are some other alternative events with some trade offs. It really depends on the goal of the event and what you want to happen.
  • on_violent_chunk; something even more general, such as an event in a particular map chunk, would abstract around the quantity of entities in the chunk.
  • on_robot_fixed_entity; if an entity is damaged and a construction robot is dispatched to repair it, we could use it as a side-channel for determining damage to an owned entity.
  • on_entity_engaged; fired once when a turret (portable/stationary) starts firing. This would potentially trigger a bunch at the start, but would taper off.
  • on_enemy_engaged; fired once when the bugs initiate an attack (i.e. right when they start to swarm a base/player).
  • on_entity_hit; fired only once, when the entity's health drops below 100.
I personally would just like to have some mechanism to tie into the alert that we already get in-game via the alarm/notification-icon and any of the above could let me replicate it.
dstar4138
Burner Inserter
Burner Inserter
Posts: 8
Joined: Mon Sep 05, 2016 11:00 am
Contact:

Re: on_entity_damaged event

Post by dstar4138 »

Additionally, this request could be merged with another:

viewtopic.php?f=28&t=7595
Post Reply

Return to “Implemented mod requests”