How can detect a player collision with a train?

Place to get help with not working mods / modding interface.
Post Reply
cdaringe
Burner Inserter
Burner Inserter
Posts: 9
Joined: Sat Mar 17, 2018 3:42 am
Contact:

How can detect a player collision with a train?

Post 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

User avatar
steinio
Smart Inserter
Smart Inserter
Posts: 2633
Joined: Sat Mar 12, 2016 4:19 pm
Contact:

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

Post 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
Image

Transport Belt Repair Man

View unread Posts

cdaringe
Burner Inserter
Burner Inserter
Posts: 9
Joined: Sat Mar 17, 2018 3:42 am
Contact:

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

Post 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 :)).

User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7352
Joined: Fri May 09, 2014 1:01 pm
Contact:

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

Post 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.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.


Post Reply

Return to “Modding help”