Page 1 of 1

Enemies to attack player inside vehicle

Posted: Sun Oct 18, 2020 2:32 am
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?

Re: Enemies to attack player inside vehicle

Posted: Sun Oct 18, 2020 8:49 am
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)

Re: Enemies to attack player inside vehicle

Posted: Sun Oct 18, 2020 4:20 pm
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.

Re: Enemies to attack player inside vehicle

Posted: Sun Oct 18, 2020 4:39 pm
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.

Re: Enemies to attack player inside vehicle

Posted: Thu Oct 22, 2020 3:36 am
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)