event when player enters area

Things that we aren't going to implement
Post Reply
adamius
Long Handed Inserter
Long Handed Inserter
Posts: 73
Joined: Mon Mar 19, 2018 9:18 am
Contact:

event when player enters area

Post by adamius »

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.
Last edited by adamius on Tue Feb 11, 2020 4:12 am, edited 2 times in total.

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2903
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: event when player enters area

Post by darkfrei »

How it was done in /editor?

adamius
Long Handed Inserter
Long Handed Inserter
Posts: 73
Joined: Mon Mar 19, 2018 9:18 am
Contact:

Re: event when player enters area

Post by adamius »

darkfrei wrote:
Mon Feb 10, 2020 8:25 am
How it was done in /editor?
What was done?

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2903
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: event when player enters area

Post by darkfrei »

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
2020-02-11T00_33_11-Factorio 0.18.3.png (231.22 KiB) Viewed 3606 times

adamius
Long Handed Inserter
Long Handed Inserter
Posts: 73
Joined: Mon Mar 19, 2018 9:18 am
Contact:

Re: event when player enters area

Post by adamius »

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.

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2903
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: event when player enters area

Post by darkfrei »

UPS friendly: place land mine without damage and viewtopic.php?f=25&t=80764

User avatar
Deadlock989
Smart Inserter
Smart Inserter
Posts: 2528
Joined: Fri Nov 06, 2015 7:41 pm

Re: event when player enters area

Post by Deadlock989 »

(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.
Image

Honktown
Smart Inserter
Smart Inserter
Posts: 1025
Joined: Thu Oct 03, 2019 7:10 am
Contact:

Re: event when player enters area

Post by Honktown »

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.
Unless I'm mistaken, a script trigger effect item is now available:
18.0 changelog
Added "script" trigger effect item. It will call the "on_script_trigger_effect" when triggered.
Not listed at the api page, so someone would need to test if it works.
I have mods! I guess!
Link

Rseding91
Factorio Staff
Factorio Staff
Posts: 13209
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: event when player enters area

Post by Rseding91 »

Deadlock989 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.
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 ... _positions
If you want to get ahold of me I'm almost always on Discord.

Rseding91
Factorio Staff
Factorio Staff
Posts: 13209
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: event when player enters area

Post by Rseding91 »

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.

adamius
Long Handed Inserter
Long Handed Inserter
Posts: 73
Joined: Mon Mar 19, 2018 9:18 am
Contact:

Re: event when player enters area

Post by adamius »

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.

Post Reply

Return to “Won't implement”