diff --git a/apps/openmw/mwlua/engineevents.cpp b/apps/openmw/mwlua/engineevents.cpp index 7591f68b20..2aafde2264 100644 --- a/apps/openmw/mwlua/engineevents.cpp +++ b/apps/openmw/mwlua/engineevents.cpp @@ -56,6 +56,7 @@ namespace MWLua MWWorld::Ptr actor = getPtr(event.mActor); if (actor.isEmpty() || obj.isEmpty()) return; + mGlobalScripts.onActivate(GObject(obj), GObject(actor)); if (auto* scripts = getLocalScripts(obj)) scripts->onActivated(LObject(actor)); } diff --git a/apps/openmw/mwlua/globalscripts.hpp b/apps/openmw/mwlua/globalscripts.hpp index 9448d626c9..bc2c19e8ee 100644 --- a/apps/openmw/mwlua/globalscripts.hpp +++ b/apps/openmw/mwlua/globalscripts.hpp @@ -20,7 +20,7 @@ namespace MWLua : LuaUtil::ScriptsContainer(lua, "Global") { registerEngineHandlers({ &mObjectActiveHandlers, &mActorActiveHandlers, &mItemActiveHandlers, - &mNewGameHandlers, &mPlayerAddedHandlers }); + &mNewGameHandlers, &mPlayerAddedHandlers, &mOnActivateHandlers }); } void newGameStarted() { callEngineHandlers(mNewGameHandlers); } @@ -28,6 +28,10 @@ namespace MWLua void actorActive(const GObject& obj) { callEngineHandlers(mActorActiveHandlers, obj); } void itemActive(const GObject& obj) { callEngineHandlers(mItemActiveHandlers, obj); } void playerAdded(const GObject& obj) { callEngineHandlers(mPlayerAddedHandlers, obj); } + void onActivate(const GObject& obj, const GObject& actor) + { + callEngineHandlers(mOnActivateHandlers, obj, actor); + } private: EngineHandlerList mObjectActiveHandlers{ "onObjectActive" }; @@ -35,6 +39,7 @@ namespace MWLua EngineHandlerList mItemActiveHandlers{ "onItemActive" }; EngineHandlerList mNewGameHandlers{ "onNewGame" }; EngineHandlerList mPlayerAddedHandlers{ "onPlayerAdded" }; + EngineHandlerList mOnActivateHandlers{ "onActivate" }; }; } diff --git a/apps/openmw/mwlua/luabindings.cpp b/apps/openmw/mwlua/luabindings.cpp index 7c9691e6d0..57431716c4 100644 --- a/apps/openmw/mwlua/luabindings.cpp +++ b/apps/openmw/mwlua/luabindings.cpp @@ -51,7 +51,7 @@ namespace MWLua { auto* lua = context.mLua; sol::table api(lua->sol(), sol::create); - api["API_REVISION"] = 33; + api["API_REVISION"] = 34; api["quit"] = [lua]() { Log(Debug::Warning) << "Quit requested by a Lua script.\n" << lua->debugTraceback(); MWBase::Environment::get().getStateManager()->requestQuit(); diff --git a/docs/source/reference/lua-scripting/engine_handlers.rst b/docs/source/reference/lua-scripting/engine_handlers.rst index a731ceef6f..747714c3b7 100644 --- a/docs/source/reference/lua-scripting/engine_handlers.rst +++ b/docs/source/reference/lua-scripting/engine_handlers.rst @@ -37,7 +37,7 @@ Engine handler is a function defined by a script, that can be called by the engi :widths: 20 80 * - onNewGame() - - New game is started + - New game is started. * - onPlayerAdded(player) - Player added to the game world. The argument is a `Game object`. * - onObjectActive(object) @@ -47,6 +47,8 @@ Engine handler is a function defined by a script, that can be called by the engi * - onItemActive(item) - | Item (Weapon, Potion, ...) becomes active in a cell. | Does not apply to items in inventories or containers. + * - onActivate(object, actor) + - Object is activated by an actor. **Only for local scripts**