(Lua) Add onActivate handler in global scripts

depth-refraction
Petr Mikheev 2 years ago
parent cd6413c060
commit a72dc6c7a1

@ -56,6 +56,7 @@ namespace MWLua
MWWorld::Ptr actor = getPtr(event.mActor); MWWorld::Ptr actor = getPtr(event.mActor);
if (actor.isEmpty() || obj.isEmpty()) if (actor.isEmpty() || obj.isEmpty())
return; return;
mGlobalScripts.onActivate(GObject(obj), GObject(actor));
if (auto* scripts = getLocalScripts(obj)) if (auto* scripts = getLocalScripts(obj))
scripts->onActivated(LObject(actor)); scripts->onActivated(LObject(actor));
} }

@ -20,7 +20,7 @@ namespace MWLua
: LuaUtil::ScriptsContainer(lua, "Global") : LuaUtil::ScriptsContainer(lua, "Global")
{ {
registerEngineHandlers({ &mObjectActiveHandlers, &mActorActiveHandlers, &mItemActiveHandlers, registerEngineHandlers({ &mObjectActiveHandlers, &mActorActiveHandlers, &mItemActiveHandlers,
&mNewGameHandlers, &mPlayerAddedHandlers }); &mNewGameHandlers, &mPlayerAddedHandlers, &mOnActivateHandlers });
} }
void newGameStarted() { callEngineHandlers(mNewGameHandlers); } void newGameStarted() { callEngineHandlers(mNewGameHandlers); }
@ -28,6 +28,10 @@ namespace MWLua
void actorActive(const GObject& obj) { callEngineHandlers(mActorActiveHandlers, obj); } void actorActive(const GObject& obj) { callEngineHandlers(mActorActiveHandlers, obj); }
void itemActive(const GObject& obj) { callEngineHandlers(mItemActiveHandlers, obj); } void itemActive(const GObject& obj) { callEngineHandlers(mItemActiveHandlers, obj); }
void playerAdded(const GObject& obj) { callEngineHandlers(mPlayerAddedHandlers, obj); } void playerAdded(const GObject& obj) { callEngineHandlers(mPlayerAddedHandlers, obj); }
void onActivate(const GObject& obj, const GObject& actor)
{
callEngineHandlers(mOnActivateHandlers, obj, actor);
}
private: private:
EngineHandlerList mObjectActiveHandlers{ "onObjectActive" }; EngineHandlerList mObjectActiveHandlers{ "onObjectActive" };
@ -35,6 +39,7 @@ namespace MWLua
EngineHandlerList mItemActiveHandlers{ "onItemActive" }; EngineHandlerList mItemActiveHandlers{ "onItemActive" };
EngineHandlerList mNewGameHandlers{ "onNewGame" }; EngineHandlerList mNewGameHandlers{ "onNewGame" };
EngineHandlerList mPlayerAddedHandlers{ "onPlayerAdded" }; EngineHandlerList mPlayerAddedHandlers{ "onPlayerAdded" };
EngineHandlerList mOnActivateHandlers{ "onActivate" };
}; };
} }

@ -51,7 +51,7 @@ namespace MWLua
{ {
auto* lua = context.mLua; auto* lua = context.mLua;
sol::table api(lua->sol(), sol::create); sol::table api(lua->sol(), sol::create);
api["API_REVISION"] = 33; api["API_REVISION"] = 34;
api["quit"] = [lua]() { api["quit"] = [lua]() {
Log(Debug::Warning) << "Quit requested by a Lua script.\n" << lua->debugTraceback(); Log(Debug::Warning) << "Quit requested by a Lua script.\n" << lua->debugTraceback();
MWBase::Environment::get().getStateManager()->requestQuit(); MWBase::Environment::get().getStateManager()->requestQuit();

@ -37,7 +37,7 @@ Engine handler is a function defined by a script, that can be called by the engi
:widths: 20 80 :widths: 20 80
* - onNewGame() * - onNewGame()
- New game is started - New game is started.
* - onPlayerAdded(player) * - onPlayerAdded(player)
- Player added to the game world. The argument is a `Game object`. - Player added to the game world. The argument is a `Game object`.
* - onObjectActive(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) * - onItemActive(item)
- | Item (Weapon, Potion, ...) becomes active in a cell. - | Item (Weapon, Potion, ...) becomes active in a cell.
| Does not apply to items in inventories or containers. | Does not apply to items in inventories or containers.
* - onActivate(object, actor)
- Object is activated by an actor.
**Only for local scripts** **Only for local scripts**

Loading…
Cancel
Save