Page 1 of 1

Detecting if player is standing on rails

Posted: Fri Dec 06, 2024 10:38 am
by IZer0
Hi I'm new to modding Factorio, and I was wondering if there was a way to detect if the player was standing on top of rails.
I know it's possible to detect the surface beneath the player, but I didn't see any event relating to entities.

Thanks!

Re: Detecting if player is standing on rails

Posted: Fri Dec 06, 2024 5:05 pm
by Natha
No, there is no event when player walks above other entities

Re: Detecting if player is standing on rails

Posted: Fri Dec 06, 2024 5:24 pm
by gangerM
Idea1:
- Make type of prototype from CombatRobot that is always alive and always follows player on the surface.
- Make it being damaged when on rails and set notification on damage on.

Idea2:
Check with surface filter around the player location every tick, but might be a bit resource intensive.

Re: Detecting if player is standing on rails

Posted: Fri Dec 06, 2024 5:43 pm
by Pi-C
IZer0 wrote: Fri Dec 06, 2024 10:38 am … I was wondering if there was a way to detect if the player was standing on top of rails. …
gangerM wrote: Fri Dec 06, 2024 5:24 pm Idea2:
Check with surface filter around the player location every tick, but might be a bit resource intensive.
If you really only want to react to players standing on top of rails, it would be sufficient to look for rails at the player's position once per second (every 60 ticks: Store the position. On the next tick, if old position and current position differ, look for rails. However, if you want to react even if the player is just crossing (i.e., entering and immediately leaving) rails, you'd have to run the above on every tick.