Skip to content

Commit

Permalink
Merge branch 'ondeath' into 'master'
Browse files Browse the repository at this point in the history
Add a death event to the Lua API

See merge request OpenMW/openmw!3555
  • Loading branch information
Zackhasacat committed Dec 6, 2023
2 parents 1073bd9 + efb819b commit 0ff9831
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions apps/openmw/mwbase/luamanager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions apps/openmw/mwlua/luamanagerimp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions apps/openmw/mwlua/luamanagerimp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 2 additions & 0 deletions apps/openmw/mwmechanics/actors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions docs/source/reference/lua-scripting/events.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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``.
Expand Down

0 comments on commit 0ff9831

Please sign in to comment.