[Request] event.onentitydamaged / event.onattack

Choumiko
Smart Inserter
Smart Inserter
Posts: 1352
Joined: Fri Mar 21, 2014 10:51 pm
Contact:

[Request] event.onentitydamaged / event.onattack

Post by Choumiko »

I would like to propose 1 and/or 2 new events:
onentitydamaged : event contains the entity, the damage(amount/type) and the entity that caused the damage (if there is one)

onattack : contains unit group, engaging turrets (basicly the info the player already gets shown to the right of the toolbar when biters attack. I guess there's something like an event already in the factorio source for this

Possible use cases: buildings do certain things (e.g. spawn combat robots, stop/start trains, whatever is modable) when an entity in their area get's damaged.
Choumiko wrote:I just got the idea for something like The Fat Controller: When being attacked, click a button and your camera switches to the attack. As i really like seeing those biters get killed but rarely am close enough :cry:
(quoted from https://forums.factorio.com/forum/vie ... =25&t=7507)
I'm sure there are loads of other uses

User avatar
L0771
Filter Inserter
Filter Inserter
Posts: 516
Joined: Tue Jan 14, 2014 1:51 pm
Contact:

Re: [Request] event.onentitydamaged / event.onattack

Post by L0771 »

Choumiko wrote:onentitydamaged : event contains the entity, the damage(amount/type) and the entity that caused the damage (if there is one)
I want add event.tick and event.playerindex if the entity that cause damage is a player (else nil), to continue with the same format of all others events.

Rahjital
Filter Inserter
Filter Inserter
Posts: 435
Joined: Thu May 29, 2014 10:44 am
Contact:

Re: [Request] event.onentitydamaged / event.onattack

Post by Rahjital »

I don't think the onattack event is possible since that's not how the game mechanics work. When biters get the order to attack, they can be kilometres away from your base, and the event getting triggered at that time wouldn't be very usefull. For turrets attacking biters, you could simply use event.onentitydamaged again.

A better thing would be event.onentityattacking, which would trigger whenever anything attacks. It's needed because weapons can have splash damage (rocket launcher, mines), create many projectiles at one (shotgun) or have other ways of damaging many entities (flamethrower), and because even projectiles that are guaranteed to hit (like laser bolts or worm spit) take some time to travel. It should contain the attacking entity, the target entity, a table of all projectiles and possibly damage value too.
L0771 wrote:I want add event.tick and event.playerindex if the entity that cause damage is a player (else nil), to continue with the same format of all others events.
You could use game.tick for time and loop through players characters to see if any of them is the event.damagedentity. Only events that actually concern players (and only players) have event.playerindex.

Choumiko
Smart Inserter
Smart Inserter
Posts: 1352
Joined: Fri Mar 21, 2014 10:51 pm
Contact:

Re: [Request] event.onentitydamaged / event.onattack

Post by Choumiko »

Rahjital wrote:A better thing would be event.onentityattacking, which would trigger whenever anything attacks. It's needed because weapons can have splash damage (rocket launcher, mines), create many projectiles at one (shotgun) or have other ways of damaging many entities (flamethrower), and because even projectiles that are guaranteed to hit (like laser bolts or worm spit) take some time to travel. It should contain the attacking entity, the target entity, a table of all projectiles and possibly damage value too.
That's what i meant with " (basicly the info the player already gets shown to the right of the toolbar when biters attack. I guess there's something like an event already in the factorio source for this)" An event that gets triggered the first time the triangle thingy pops up, it already shows "X turrets engaged with the enemy, y objects being damaged" so a lot of the info is gathered already

event.tick makes sense i guess. As for playerindex, with multiplayer in development, maybe entities should have .isPlayer() or just .getplayerindex() simply returning nil if not a player? I haven't gotten into MP-safe modding yet, so no clue if this makes sense.

Rahjital
Filter Inserter
Filter Inserter
Posts: 435
Joined: Thu May 29, 2014 10:44 am
Contact:

Re: [Request] event.onentitydamaged / event.onattack

Post by Rahjital »

Choumiko wrote: That's what i meant with " (basicly the info the player already gets shown to the right of the toolbar when biters attack. I guess there's something like an event already in the factorio source for this)" An event that gets triggered the first time the triangle thingy pops up, it already shows "X turrets engaged with the enemy, y objects being damaged" so a lot of the info is gathered already
I don't know how Factorio works, but those warning signs are most likely done simply by storing the last tick a turret shot or a player entity was damaged and displaying the warning based on that. Implementing such a thing is no hard thing and the code is probably too simple to have any event associated to it.

The onentityattacked event would have to fire every single time anything shoots/bites/spits/attacks to be useful, not simply whenever those triangles show up. Limiting it to show you a biter attack would be trivial to do in Lua, so there's no need to limit the event for that.

Degraine
Filter Inserter
Filter Inserter
Posts: 282
Joined: Wed Aug 13, 2014 10:49 am
Contact:

Re: [Request] event.onentitydamaged / event.onattack

Post by Degraine »

I would like this as well. It'd be very handy for a certain application I have in mind.

Post Reply

Return to “Implemented mod requests”