Page 1 of 1

on_entity_damaged event

Posted: Sat May 21, 2016 3:17 am
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

Re: on_entity_damaged event

Posted: Sat May 21, 2016 4:35 am
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.

Re: on_entity_damaged event

Posted: Sat May 21, 2016 4:51 am
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.

Re: on_entity_damaged event

Posted: Sat May 21, 2016 7:37 pm
by Supercheese
You could hack something like this in for specific entities, by using the attack_reaction field in the prototype and listening for the on_trigger_created_entity event in control lua. It's how Rseding does it in Force Fields. ;)

Re: on_entity_damaged event

Posted: Sat Jul 02, 2016 11:43 am
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.

Re: on_entity_damaged event

Posted: Mon Sep 12, 2016 1:32 am
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.

Re: on_entity_damaged event

Posted: Mon Sep 12, 2016 9:35 am
by dstar4138
Additionally, this request could be merged with another:

viewtopic.php?f=28&t=7595