Page 1 of 1

How can detect a player collision with a train?

Posted: Sat Mar 17, 2018 3:54 am
by cdaringe
Hi all:

I just took the first modding tutorial, spent some time reading over the APIs, and studied the events.

I'm trying to make a mod called "Nice Try, Train" that will either halt the train on collision with a player, or have the train completely explode on high speed contact with a player. Kind of a Thor/Hulk situation.

I've found on_damage event, however, some initial testing seems that the event is not called before on_player_died, so I cannot respond and prevent the sudden death.

Can you lend me any tips?

Thanks

Re: How can detect a player collision with a train?

Posted: Sat Mar 17, 2018 8:35 am
by steinio
Hi,

have a look at this mod: viewtopic.php?f=190&t=21725&hilit=Jesus#p136492

This moves the player away from track.

But you are looking for http://lua-api.factorio.com/latest/even ... layer_died

Re: How can detect a player collision with a train?

Posted: Thu Mar 22, 2018 2:16 am
by cdaringe
ah, on_PRE_player_died! how did i miss that! thanks!

hmm. looks like i actually cannot prevent the death. per viewtopic.php?f=28&t=48225&p=291267&hil ... nt#p291267 you are unable to cancel events. because of this, the death event is inevitable.

this is too bad, as it would be much more efficient to detect an upcoming death, test if it was caused by train, then cancel it (or explode the train :)).

Re: How can detect a player collision with a train?

Posted: Thu Mar 22, 2018 9:12 am
by bobingabout
cdaringe wrote:ah, on_PRE_player_died! how did i miss that! thanks!

hmm. looks like i actually cannot prevent the death. per viewtopic.php?f=28&t=48225&p=291267&hil ... nt#p291267 you are unable to cancel events. because of this, the death event is inevitable.

this is too bad, as it would be much more efficient to detect an upcoming death, test if it was caused by train, then cancel it (or explode the train :)).
I've been told that in this event, you should be able to change the player character's health back to a non-zero value to cancel death.

Re: How can detect a player collision with a train?

Posted: Sat Mar 24, 2018 2:08 am
by cdaringe