1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-04 02:41:19 +00:00

Merge branch 'ondeath' into 'master'

Add a death event to the Lua API

See merge request OpenMW/openmw!3555
This commit is contained in:
Zackhasacat 2023-12-06 04:21:56 +00:00
commit 0ff9831c92
5 changed files with 23 additions and 0 deletions

View File

@ -53,6 +53,7 @@ namespace MWBase
virtual void objectActivated(const MWWorld::Ptr& object, const MWWorld::Ptr& actor) = 0;
virtual void useItem(const MWWorld::Ptr& object, const MWWorld::Ptr& actor, bool force) = 0;
virtual void exteriorCreated(MWWorld::CellStore& cell) = 0;
virtual void actorDied(const MWWorld::Ptr& actor) = 0;
virtual void questUpdated(const ESM::RefId& questId, int stage) = 0;
// `arg` is either forwarded from MWGui::pushGuiMode or empty

View File

@ -344,6 +344,13 @@ namespace MWLua
playerScripts->uiModeChanged(argId, false);
}
void LuaManager::actorDied(const MWWorld::Ptr& actor)
{
if (actor.isEmpty())
return;
mLuaEvents.addLocalEvent({ getId(actor), "Died", {} });
}
void LuaManager::useItem(const MWWorld::Ptr& object, const MWWorld::Ptr& actor, bool force)
{
MWBase::Environment::get().getWorldModel()->registerPtr(object);

View File

@ -85,6 +85,7 @@ namespace MWLua
void objectTeleported(const MWWorld::Ptr& ptr) override;
void questUpdated(const ESM::RefId& questId, int stage) override;
void uiModeChanged(const MWWorld::Ptr& arg) override;
void actorDied(const MWWorld::Ptr& actor) override;
MWBase::LuaManager::ActorControls* getActorControls(const MWWorld::Ptr&) const override;

View File

@ -1730,6 +1730,8 @@ namespace MWMechanics
actor.getClass().getCreatureStats(actor).notifyDied();
++mDeathCount[actor.getCellRef().getRefId()];
MWBase::Environment::get().getLuaManager()->actorDied(actor);
}
void Actors::resurrect(const MWWorld::Ptr& ptr) const

View File

@ -6,6 +6,18 @@ Built-in events
Actor events
------------
**Died**
This event is sent to an actor's local script when that actor dies.
.. code-block:: Lua
eventHandlers = {
Died = function()
print('Alas, ye hardly knew me!')
end
}
**StartAIPackage, RemoveAIPackages**
Any script can send to any actor (except player, for player will be ignored) events ``StartAIPackage`` and ``RemoveAIPackages``.