Merge branch 'ondeath' into 'master'

Add a death event to the Lua API

See merge request OpenMW/openmw!3555
macos_ci_fix
Zackhasacat 1 year ago
commit 0ff9831c92

@ -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

@ -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);

@ -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;

@ -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

@ -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``.

Loading…
Cancel
Save