Detecting if player is standing on rails

Place to get help with not working mods / modding interface.
IZer0
Manual Inserter
Manual Inserter
Posts: 1
Joined: Fri Dec 06, 2024 10:32 am
Contact:

Detecting if player is standing on rails

Post 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!
Natha
Fast Inserter
Fast Inserter
Posts: 229
Joined: Sun Mar 15, 2015 1:48 pm
Contact:

Re: Detecting if player is standing on rails

Post by Natha »

No, there is no event when player walks above other entities
User avatar
gangerM
Burner Inserter
Burner Inserter
Posts: 18
Joined: Thu Nov 28, 2024 5:32 pm
Contact:

Re: Detecting if player is standing on rails

Post 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.
Pi-C
Smart Inserter
Smart Inserter
Posts: 1742
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: Detecting if player is standing on rails

Post 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.
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!
Post Reply

Return to “Modding help”