Enemies to attack player inside vehicle

Place to get help with not working mods / modding interface.
Post Reply
PFQNiet
Filter Inserter
Filter Inserter
Posts: 289
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
Smart Inserter
Smart Inserter
Posts: 1639
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
Filter Inserter
Filter Inserter
Posts: 289
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
Smart Inserter
Smart Inserter
Posts: 1639
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!

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Enemies to attack player inside vehicle

Post by eradicator »

PFQNiet wrote:
Sun Oct 18, 2020 4:20 pm
However if the entity is outright set to "destructible = false" then it does not.
Well, then don't do that (at least when a player is in the car). You can even get the corret damage after resistances.

Code: Select all

-- makes everything indestructible
/c script.on_event(defines.events.on_entity_damaged,function(e) game.print(e.final_damage_amount) e.entity.health = 2^42-1 end)
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

Post Reply

Return to “Modding help”