From 6db7c30e682850536a8bb550d425f18ec1dbb78b Mon Sep 17 00:00:00 2001 From: Eduardo Dantas Date: Sun, 17 Apr 2022 11:59:52 -0300 Subject: [PATCH] Fixed on death events for monsters that don't have corpses (#305) onDeath events not working for corpseless monsters Added a sanity check to ensure the corpse is not used by monsters that don't have a corpse --- src/creatures/creature.cpp | 2 +- src/lua/creature/creatureevent.cpp | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/creatures/creature.cpp b/src/creatures/creature.cpp index e68cbe7b3ab..b04b95953a1 100644 --- a/src/creatures/creature.cpp +++ b/src/creatures/creature.cpp @@ -759,7 +759,7 @@ bool Creature::dropCorpse(Creature* lastHitCreature, Creature* mostDamageCreatur // Scripting event onDeath for (CreatureEvent* deathEvent : getCreatureEvents(CREATURE_EVENT_DEATH)) { - if (deathEvent && corpse) { + if (deathEvent) { deathEvent->executeOnDeath(this, corpse, lastHitCreature, mostDamageCreature, lastHitUnjustified, mostDamageUnjustified); } } diff --git a/src/lua/creature/creatureevent.cpp b/src/lua/creature/creatureevent.cpp index 8d50382e104..30fc619dcd3 100644 --- a/src/lua/creature/creatureevent.cpp +++ b/src/lua/creature/creatureevent.cpp @@ -377,7 +377,9 @@ bool CreatureEvent::executeOnDeath(Creature* creature, Item* corpse, Creature* k LuaScriptInterface::pushUserdata(L, creature); LuaScriptInterface::setCreatureMetatable(L, -1, creature); - LuaScriptInterface::pushThing(L, corpse); + if (corpse && corpse != 0) { + LuaScriptInterface::pushThing(L, corpse); + } if (killer) { LuaScriptInterface::pushUserdata(L, killer);