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?
Enemies to attack player inside vehicle
Re: Enemies to attack player inside vehicle
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!
Re: Enemies to attack player inside vehicle
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.
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.
Re: Enemies to attack player inside vehicle
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.
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.However if the entity is outright set to "destructible = false" then it does not.
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!
- eradicator
- Smart Inserter
- Posts: 5206
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: Enemies to attack player inside vehicle
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.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.