Enemies to attack player inside vehicle

Place to get help with not working mods / modding interface.
Post Reply
PFQNiet
Burner Inserter
Burner Inserter
Posts: 6
Joined: Sat Sep 05, 2020 7:48 pm
Contact:

Enemies to attack player inside vehicle

Post by PFQNiet »

I made the car indestructible. For... reasons.

However biters will try - unsuccessfully - to attack the player driving nearby them. They just attack repeatedly until the car slowly grinds through them.

I'd like to make it so that if enemies attack the car, it is the player inside that takes damage instead. Is there an event that allows this? I don't think on_entity_damaged would work here since the car doesn't take damage, but perhaps I could workaround by having the car be destructible, but resists all damage types 100%. Then I can use the original damage and apply that to the character entity instead.

Any better options/ideas?

Pi-C
Filter Inserter
Filter Inserter
Posts: 880
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: Enemies to attack player inside vehicle

Post by Pi-C »

PFQNiet wrote:
Sun Oct 18, 2020 2:32 am
I don't think on_entity_damaged would work here since the car doesn't take damage
It does take damage -- the damage is just zero! If you log event data you can see that on_entity_damaged will be triggered:

Code: Select all

script.on_event(defines.events.on_entity_damaged, function(event) log("Entity damaged: " .. serpent.block(event)) end)
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

PFQNiet
Burner Inserter
Burner Inserter
Posts: 6
Joined: Sat Sep 05, 2020 7:48 pm
Contact:

Re: Enemies to attack player inside vehicle

Post by PFQNiet »

I just double-checked that, but unfortunately no.

If it has 100% resistance then yes it does indeed trigger a "damaged" event with 0 damage and the original damage listed.

However if the entity is outright set to "destructible = false" then it does not.

Pi-C
Filter Inserter
Filter Inserter
Posts: 880
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: Enemies to attack player inside vehicle

Post by Pi-C »

PFQNiet wrote:
Sun Oct 18, 2020 4:20 pm
If it has 100% resistance then yes it does indeed trigger a "damaged" event with 0 damage and the original damage listed.
That's what I did in Water Turret -- create new damage types and grant all entities that the turrets shouldn't damage 100% resistance against this damage type. Then in data-final-fixes, I went through data.raw.["damage-type"] and gave my dummies 100% resistance against any damage types but my own.
However if the entity is outright set to "destructible = false" then it does not.
OK, that's the crucial difference. I want my dummies to be destructible, but only by my own turrets, so I didn't touch that flag.
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

Post Reply

Return to “Modding help”

Who is online

Users browsing this forum: No registered users