event when player enters area
event when player enters area
Why
I'm building a scenario to teach people how to play in various ways. One of the aspects is detecting when a player walks/drives into particular areas. There's a bunch of these areas. Right now there's around 30 of them.
How
I'd like some way to have an event triggered when a player enters an area. This would be used in scenarios/mods to detect a player when they move into an area either by walking or driving etc. Other uses might be touch plates or sense areas as used in several other mods that have entrances/doors to buildings.
Example
eg
id = surface.add_area_trigger(area)
on_area_trigger (event)
event.area
event.area_id
Alternatives:
The current alternative is to have code in the on_player_changed_position event handler. My current solution is a handler either in the scenario or a separate mod.
I'm building a scenario to teach people how to play in various ways. One of the aspects is detecting when a player walks/drives into particular areas. There's a bunch of these areas. Right now there's around 30 of them.
How
I'd like some way to have an event triggered when a player enters an area. This would be used in scenarios/mods to detect a player when they move into an area either by walking or driving etc. Other uses might be touch plates or sense areas as used in several other mods that have entrances/doors to buildings.
Example
eg
id = surface.add_area_trigger(area)
on_area_trigger (event)
event.area
event.area_id
Alternatives:
The current alternative is to have code in the on_player_changed_position event handler. My current solution is a handler either in the scenario or a separate mod.
Last edited by adamius on Tue Feb 11, 2020 4:12 am, edited 2 times in total.
Re: event when player enters area
How it was done in /editor?
Re: event when player enters area
I think that here is native support for area/positions in lua snippet in /editor
- Attachments
-
- 2020-02-11T00_33_11-Factorio 0.18.3.png (231.22 KiB) Viewed 4202 times
Re: event when player enters area
No idea. I was able to use the map editor to create areas but actually detecting what happens afterwards is not obvious to me. The wiki page for the map editor says its "easy" but doesn't say anything after that. I can't find an event in lua-api.factorio.com relating to named areas. I'd be expecting something like on_player_* or on_script_*. eg on_script_area or on_script_area_entered as valid guesses.
I'll leave this interface request here and continue exploration of the map editor in a different post.
I'll leave this interface request here and continue exploration of the map editor in a different post.
Re: event when player enters area
UPS friendly: place land mine without damage and viewtopic.php?f=25&t=80764
- Deadlock989
- Smart Inserter
- Posts: 2529
- Joined: Fri Nov 06, 2015 7:41 pm
Re: event when player enters area
(mostly @darkfrei)
Named areas in the editor are purely for iterating over stuff in Lua snippets in the editor, e.g. cloning, destroying etc. They serve no other purpose as far as I know. There's certainly no special event that is triggered by them. I don't know if control.lua can even access them.
Every mod I've ever glanced through which does things like this - e.g. portals, custom AOE effects - uses on_nth_tick or on_player_changed_position.
Land mines are the only "proximity triggered" entity in the game that I know of but you are limited to a circular radius, not a defined rectangular trigger area, and also limited to trigger effects, I don't believe there is any way of running any arbitrary custom script from such a trigger. So it doesn't fit this use case at all.
Named areas in the editor are purely for iterating over stuff in Lua snippets in the editor, e.g. cloning, destroying etc. They serve no other purpose as far as I know. There's certainly no special event that is triggered by them. I don't know if control.lua can even access them.
Every mod I've ever glanced through which does things like this - e.g. portals, custom AOE effects - uses on_nth_tick or on_player_changed_position.
Land mines are the only "proximity triggered" entity in the game that I know of but you are limited to a circular radius, not a defined rectangular trigger area, and also limited to trigger effects, I don't believe there is any way of running any arbitrary custom script from such a trigger. So it doesn't fit this use case at all.
Re: event when player enters area
Unless I'm mistaken, a script trigger effect item is now available:Deadlock989 wrote: ↑Tue Feb 11, 2020 12:32 pm Land mines are the only "proximity triggered" entity in the game that I know of but you are limited to a circular radius, not a defined rectangular trigger area, and also limited to trigger effects, I don't believe there is any way of running any arbitrary custom script from such a trigger. So it doesn't fit this use case at all.
18.0 changelog
Not listed at the api page, so someone would need to test if it works.Added "script" trigger effect item. It will call the "on_script_trigger_effect" when triggered.
I have mods! I guess!
Link
Link
Re: event when player enters area
Named areas in the editor have nothing to do with the snippets editor. They are readable through the existing API: https://lua-api.factorio.com/latest/Lua ... ript_areas https://lua-api.factorio.com/latest/Lua ... _positionsDeadlock989 wrote: ↑Tue Feb 11, 2020 12:32 pm (mostly @darkfrei)
Named areas in the editor are purely for iterating over stuff in Lua snippets in the editor, e.g. cloning, destroying etc. They serve no other purpose as far as I know. There's certainly no special event that is triggered by them. I don't know if control.lua can even access them.
Every mod I've ever glanced through which does things like this - e.g. portals, custom AOE effects - uses on_nth_tick or on_player_changed_position.
Land mines are the only "proximity triggered" entity in the game that I know of but you are limited to a circular radius, not a defined rectangular trigger area, and also limited to trigger effects, I don't believe there is any way of running any arbitrary custom script from such a trigger. So it doesn't fit this use case at all.
If you want to get ahold of me I'm almost always on Discord.
Re: event when player enters area
As for this request; you can already do that by using the player-moved event and checking if they moved into or out of an area. It's exactly what the game would have to do if such an event existed.
If you want to get ahold of me I'm almost always on Discord.
Re: event when player enters area
I've done exactly that in a mod to generalise it. My testing shows I can have a large enough number using this approach with much lower UPS requirements than what I was doing previously.