Another way is to place invisible gate, then check it's state to see if its opening, and if so are players nearby? But that's still using on_tick. Slow.
If gates triggered an event, however, mods could use that as an alert to potential player proximity.
event.entity = the gate
event.player_index = id of player who opend/closed gate (if applicable) or nil
event.signal = signal that opened/closed gate (if applicable) or nil
Example code:
Code: Select all
script.on_event( defines.events.on_gate_changed_state, function( event )
if event.player_index then
-- player proximity
end
end )
Even without .player_index and .signal, the event would still be useful as a trigger for mods to check for stuff in a given area.
As gates can be opened by signal, this event also enables mods to more easily determine if a train is nearby (mod places train signal, wires it to invisible gate...)