From 49021a98b8c694771123788aec884a5217e36f2b Mon Sep 17 00:00:00 2001 From: Luan Santos Date: Sat, 28 Oct 2023 13:56:16 -0700 Subject: [PATCH] deprecate --- src/lua/creature/creatureevent.cpp | 6 ++++++ .../creatures/monster/monster_type_functions.cpp | 9 ++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/lua/creature/creatureevent.cpp b/src/lua/creature/creatureevent.cpp index b1984be2fd6..29feb652036 100644 --- a/src/lua/creature/creatureevent.cpp +++ b/src/lua/creature/creatureevent.cpp @@ -326,8 +326,14 @@ bool CreatureEvent::executeAdvance(std::shared_ptr player, skills_t skil return getScriptInterface()->callFunction(4); } +/** + * @deprecated Prefer using registered onDeath events instead for better performance. + */ void CreatureEvent::executeOnKill(std::shared_ptr creature, std::shared_ptr target, bool lastHit) const { // onKill(creature, target, lastHit) + g_logger().warn("[CreatureEvent::executeOnKill - Creature {} target {} event {}] " + "Deprecated use of onKill event. Use registered onDeath events instead for better performance.", + creature->getName(), target->getName(), getName()); if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[CreatureEvent::executeOnKill - Creature {} target {} event {}] " "Call stack overflow. Too many lua script calls being nested.", diff --git a/src/lua/functions/creatures/monster/monster_type_functions.cpp b/src/lua/functions/creatures/monster/monster_type_functions.cpp index e08d322189c..0db51998ea7 100644 --- a/src/lua/functions/creatures/monster/monster_type_functions.cpp +++ b/src/lua/functions/creatures/monster/monster_type_functions.cpp @@ -13,6 +13,7 @@ #include "io/io_bosstiary.hpp" #include "creatures/combat/spells.hpp" #include "creatures/monsters/monsters.hpp" +#include "creatures/monsters/monster.hpp" #include "lua/functions/creatures/monster/monster_type_functions.hpp" #include "lua/scripts/scripts.hpp" @@ -1002,7 +1003,13 @@ int MonsterTypeFunctions::luaMonsterTypeRegisterEvent(lua_State* L) { // monsterType:registerEvent(name) const auto monsterType = getUserdataShared(L, 1); if (monsterType) { - monsterType->info.scripts.push_back(getString(L, 2)); + auto eventName = getString(L, 2); + monsterType->info.scripts.push_back(eventName); + for (const auto &[_, monster] : g_game().getMonsters()) { + if (monster->getMonsterType() == monsterType) { + monster->registerCreatureEvent(eventName); + } + } pushBoolean(L, true); } else { lua_pushnil(L);