Few improvement suggestions:
As it stands, this is not a library. It's part of luna.lua. Consider following
this tutorial to modify it as a library that can be loaded with require(libraryname), exposing things that can be modified as fields in the library table (myLibraryTable.maxDisappearTimer = 1280, for example). The benefits of having it as a library would be that users wouldn't have to manually merge this with their existing luna.lua file and wouldn't have to worry about file conflicts.
It's generally good practice to keep all variables defined local at the library scope (or in a more contained scope if you don't need it across functions). This is so that other scripts don't also have access to the variable without explicitly requesting it.
Enforcing layer and event names seems a little iffy. To reduce the amount of work the user has to do to get this to work, consider removing the use of events except for the goaway and comeback events and exposing the layer name and goaway/comeback event name to seek as a variable (myLibraryTable.layerName = "Toxic"). If you want to provide an optional default behaviour for the events (in case someone would want them to do nothing in the editor) you can
easily show/hide layers with the layer reference (myLayer:toggle(true) for a toggle without smoke). Just an idea.
The warning would need to be offloaded to lua too, which is fairly easy to do, considering all SMBX-internal sounds can be played simply with SFX.play(index), where index is the internal numerical index of the sound file. You can find all sound indices in data/_templates/sounds.ini, and also expose this as a configurable variable to the user (myLibraryTable.warnSound = 24). Alternatively, making the name of this configurable follows the same procedure as the other two.
Just a few things to consider if you intend to iterate upon this idea. I think for a first script this is pretty awesome! Layer loops are very common and I hope you're learning a lot from this exercise. I'll briefly mention this advanced idea that might pique your interest as well:
Something events cannot do but lua can is explicitly stop an "event loop". Maybe such a feature would be useful ;p
Looking forward to more from you!