on_gate_changed_state
Posted: Wed Oct 19, 2016 12:35 am
Currently the only way that I know of for mods to determine if a player is at specific location is via on_tick(), then iterate players, checking the position of each... Slow.
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:
The actual state of the gate can be determined via the event.entity table if required.
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...)
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...)