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
on_entity_damaged event
Re: on_entity_damaged event
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.
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.
Re: on_entity_damaged event
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.
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.
-
- Filter Inserter
- Posts: 841
- Joined: Mon Sep 14, 2015 7:40 am
- Contact:
Re: on_entity_damaged event
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
I though of some solution on the top of my head.. Make two types of such event.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.
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
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.