on_entity_damaged .weapon, .magazine, .projectile

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5211
Joined: Tue Jul 12, 2016 9:03 am
Contact:

on_entity_damaged .weapon, .magazine, .projectile

Post by eradicator »

What?
Add information about the used weaponry to on_entity_damaged event.

Why?
I'm trying to implement two new weapons that have different effects depending on what they hit (player, biter, building, etc). So i have to implement the damage logic in lua, for which i need to know which weapon (or weapon tier, etc) was used. Currently i use a projectile with a zero damage explosion to raise on_entity_damaged, but the only way to tell apart different weapons seems to be to use different damage types for each of them. It would be easier if the event knew what weapon was used, e.g:

Code: Select all

--hit by a grenade
event.weapon == 'cluser-grenade'
event.magazine == nil

Code: Select all

--shot with a pistol
event.weapon == 'pistol'
event.magazine == 'uranium-rounds-magazine'

Code: Select all

--shot by a laser turret (this could be done by event.cause.name too, or .magazin for ammo-turret)
event.projectile == 'laser'
Rseding91
Factorio Staff
Factorio Staff
Posts: 15545
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: on_entity_damaged .weapon, .magazine, .projectile

Post by Rseding91 »

Due to how the current damage system works in Factorio that information isn't available by the time the event is fired and adding it in would have more overhead than I'm currently willing to add right now. Additionally there isn't always a weapon, magazine, or projectile when something is damaged (a car hitting something for example).

Unless someone can give me more examples of how this information would be useful in mods.
If you want to get ahold of me I'm almost always on Discord.
User avatar
Godmave
Long Handed Inserter
Long Handed Inserter
Posts: 89
Joined: Tue Nov 15, 2016 3:52 pm
Contact:

Re: on_entity_damaged .weapon, .magazine, .projectile

Post by Godmave »

Does the system not know the source and type of the damage? Like car, granate, turret, biter, etc plus laser, fire, physical?
If that is there the only thing that would be new would be the source of bullets, the generator so to speak. If the bullets are entities they could get a source entity assigned.

So you could go:
on_entity_damaged -> source (uranium-ammo) -> generator (pistol)
and know that it was the yellow tank that did the damage, or a machine gun.
If entities knew where they are at the moment (inventory) you could even know who fired it the gun.
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5211
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: on_entity_damaged .weapon, .magazine, .projectile

Post by eradicator »

Shooting of the projectile and impact of the projectile don't happen in the same tick. So the engine needs to store all event relevant info for the flight time of the projectile. So i think what @Rseding91 is saying is simply that he doesn't want to buffer any more info. So currently you only get the entity that fired (player, turrent, etc) and the damage type.
Rseding91 wrote:Additionally there isn't always a weapon, magazine, or projectile when something is damaged (a car hitting something for example).
Cause and force are already optional. I don't see a problem with all of these also being optional.
Post Reply

Return to “Modding interface requests”