Lua event on potion brewed by Alchemy
I would like to make a mod that tweaks the way you get Alchemy experience. For this I would need a Lua event that is triggered when a potion is successfully brewed. Something like MWSE's potionBrewed.
I know C++ (well, no mortal truly does), so I could try and implement such a thing myself, but it doesn't seem like there is yet architecture for this category of things. It seems the engine has three main ways to expose API surface to Lua: Engine Handlers, API packages and Event handlers.
Engine Handler?
The set of engine handlers seems rather small. Is it because the script system is just getting started, or is it because you purposefully want to keep it small? If the latter, new things probably don't go here. There is apparently also a future goal to dehardcode as much as possible, and Engine Handler things are (always?) hard coded, so that is a mark against this as well.
I suppose the existence of Skills will never be dehardcoded, so a generic, synchronous, OnSkillAttempt
Engine Handler might not be out of the question. Well, for my case I'd need to know if it succeeded... but the payload could be pre-populated with the success based on the vanilla logic. The handler could then alter the success or leave it be.
API Package?
We want to listen to an event, so if this was an API package, it would presumably be something like this:
local alchemy = require('openmw.alchemy')
alchemy.register( alchemy.EVENTS.potionBrewed, myHandlerFunc );
I think this could make sense? It would allow alchemy to be hard-coded for now and be transparently dehardcoded later. I think?
Event?
Since this is very much an event handler sort of thing, it could just be an event handler.
local function handleBrewed(data)
... -- Do the thing
end
return {
eventHandlers = { OnPotionBrewed = handleBrewed },
}
This approach could also be transparently dehardcoded later. This would probably be the simplest to implement. The downside is that this sort of an interface can not return data, and therefore can not affect the result of the brewing. My use case does not require the capability to affect the output, but I imagine the alchemy API will at some point in the future want to do that. The API package approach could be extended in that direction.
How feasible would it be to create such an event, and which approach would be the best?