Skip to content

Commit

Permalink
Fixed on death events for monsters that don't have corpses (#305)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
dudantas committed Apr 17, 2022
1 parent f50096b commit 6db7c30
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/creatures/creature.cpp
Expand Up @@ -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);
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/lua/creature/creatureevent.cpp
Expand Up @@ -377,7 +377,9 @@ bool CreatureEvent::executeOnDeath(Creature* creature, Item* corpse, Creature* k
LuaScriptInterface::pushUserdata<Creature>(L, creature);
LuaScriptInterface::setCreatureMetatable(L, -1, creature);

LuaScriptInterface::pushThing(L, corpse);
if (corpse && corpse != 0) {
LuaScriptInterface::pushThing(L, corpse);
}

if (killer) {
LuaScriptInterface::pushUserdata<Creature>(L, killer);
Expand Down

0 comments on commit 6db7c30

Please sign in to comment.