Skip to content

Commit

Permalink
deprecate
Browse files Browse the repository at this point in the history
  • Loading branch information
luan committed Oct 28, 2023
1 parent 0e9646e commit 49021a9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/lua/creature/creatureevent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,14 @@ bool CreatureEvent::executeAdvance(std::shared_ptr<Player> 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> creature, std::shared_ptr<Creature> 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.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -1002,7 +1003,13 @@ int MonsterTypeFunctions::luaMonsterTypeRegisterEvent(lua_State* L) {
// monsterType:registerEvent(name)
const auto monsterType = getUserdataShared<MonsterType>(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()) {

Check warning on line 1008 in src/lua/functions/creatures/monster/monster_type_functions.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

[cppcheck] src/lua/functions/creatures/monster/monster_type_functions.cpp#L1008

Unused variable: _
Raw output
src/lua/functions/creatures/monster/monster_type_functions.cpp:1008:Unused variable: _
if (monster->getMonsterType() == monsterType) {
monster->registerCreatureEvent(eventName);
}
}
pushBoolean(L, true);
} else {
lua_pushnil(L);
Expand Down

0 comments on commit 49021a9

Please sign in to comment.