diff --git a/data/events/events.xml b/data/events/events.xml
index 0528ebc..0ae0492 100644
--- a/data/events/events.xml
+++ b/data/events/events.xml
@@ -5,6 +5,7 @@
+
diff --git a/data/events/scripts/creature.lua b/data/events/scripts/creature.lua
index 1fa0b7d..5a52b8f 100644
--- a/data/events/scripts/creature.lua
+++ b/data/events/scripts/creature.lua
@@ -18,3 +18,7 @@ end
function Creature:onHear(speaker, words, type)
if hasEvent.onHear then Event.onHear(self, speaker, words, type) end
end
+
+function Creature:onChangeZone(fromZone, toZone)
+ if hasEvent.onChangeZone then Event.onChangeZone(self, fromZone, toZone) end
+end
diff --git a/data/scripts/eventcallbacks/account_manager.lua b/data/scripts/eventcallbacks/account_manager.lua
index 056df53..0263474 100644
--- a/data/scripts/eventcallbacks/account_manager.lua
+++ b/data/scripts/eventcallbacks/account_manager.lua
@@ -458,7 +458,7 @@ end
---@param days integer
---@param reason string
---@return boolean
-function banIp(player, days, reason)
+local function banIp(player, days, reason)
local ip = player:getIp()
local resultId = db.storeQuery("SELECT 1 FROM `ip_bans` WHERE `ip` = " .. ip)
if resultId then
diff --git a/data/scripts/lib/event_callbacks.lua b/data/scripts/lib/event_callbacks.lua
index 57229af..ef036be 100644
--- a/data/scripts/lib/event_callbacks.lua
+++ b/data/scripts/lib/event_callbacks.lua
@@ -29,6 +29,7 @@ ec.onChangeMount = {}
ec.onAreaCombat = {returnValue = true}
ec.onTargetCombat = {returnValue = true}
ec.onHear = {}
+ec.onChangeZone = {}
-- Party
ec.onJoin = {}
ec.onLeave = {}
diff --git a/src/creature.cpp b/src/creature.cpp
index 979e7b7..ff6abda 100644
--- a/src/creature.cpp
+++ b/src/creature.cpp
@@ -6,15 +6,17 @@
#include "creature.h"
#include "configmanager.h"
+#include "events.h"
#include "game.h"
#include "monster.h"
#include "scheduler.h"
#include
-extern Game g_game;
extern ConfigManager g_config;
extern CreatureEvents* g_creatureEvents;
+extern Events* g_events;
+extern Game g_game;
Creature::Creature() { onIdleStatus(); }
@@ -504,6 +506,7 @@ void Creature::onCreatureMove(Creature* creature, const Tile* newTile, const Pos
}
if (newTile->getZone() != oldTile->getZone()) {
+ g_events->eventCreatureOnChangeZone(this, oldTile->getZone(), newTile->getZone());
onChangeZone(getZone());
}
diff --git a/src/events.cpp b/src/events.cpp
index 4d125ac..27bcfa7 100644
--- a/src/events.cpp
+++ b/src/events.cpp
@@ -48,6 +48,8 @@ bool Events::load()
info.creatureOnTargetCombat = event;
} else if (methodName == "onHear") {
info.creatureOnHear = event;
+ } else if (methodName == "onChangeZone") {
+ info.creatureOnChangeZone = event;
} else {
std::cout << "[Warning - Events::load] Unknown creature method: " << methodName << std::endl;
}
@@ -297,6 +299,33 @@ void Events::eventCreatureOnHear(Creature* creature, Creature* speaker, std::str
scriptInterface.callVoidFunction(4);
}
+void Events::eventCreatureOnChangeZone(Creature* creature, ZoneType_t fromZone, ZoneType_t toZone)
+{
+ // Creature:onChangeZone(fromZone, toZone)
+ if (info.creatureOnChangeZone == -1) {
+ return;
+ }
+
+ if (!scriptInterface.reserveScriptEnv()) {
+ std::cout << "[Error - Events::eventCreatureOnChangeZone] Call stack overflow" << std::endl;
+ return;
+ }
+
+ ScriptEnvironment* env = scriptInterface.getScriptEnv();
+ env->setScriptId(info.creatureOnChangeZone, &scriptInterface);
+
+ lua_State* L = scriptInterface.getLuaState();
+ scriptInterface.pushFunction(info.creatureOnChangeZone);
+
+ LuaScriptInterface::pushUserdata(L, creature);
+ LuaScriptInterface::setCreatureMetatable(L, -1, creature);
+
+ lua_pushinteger(L, fromZone);
+ lua_pushinteger(L, toZone);
+
+ scriptInterface.callVoidFunction(3);
+}
+
// Party
bool Events::eventPartyOnJoin(Party* party, Player* player)
{
diff --git a/src/events.h b/src/events.h
index f44ada1..a213bef 100644
--- a/src/events.h
+++ b/src/events.h
@@ -27,6 +27,7 @@ class Events
int32_t creatureOnAreaCombat = -1;
int32_t creatureOnTargetCombat = -1;
int32_t creatureOnHear = -1;
+ int32_t creatureOnChangeZone = -1;
// Party
int32_t partyOnJoin = -1;
@@ -74,6 +75,7 @@ class Events
ReturnValue eventCreatureOnAreaCombat(Creature* creature, Tile* tile, bool aggressive);
ReturnValue eventCreatureOnTargetCombat(Creature* creature, Creature* target);
void eventCreatureOnHear(Creature* creature, Creature* speaker, std::string_view words, SpeakClasses type);
+ void eventCreatureOnChangeZone(Creature* creature, ZoneType_t fromZone, ZoneType_t toZone);
// Party
bool eventPartyOnJoin(Party* party, Player* player);