diff --git a/src/server/game/Entities/Creature/Creature.cpp b/src/server/game/Entities/Creature/Creature.cpp index 6b5bc14e9..81caf4e77 100644 --- a/src/server/game/Entities/Creature/Creature.cpp +++ b/src/server/game/Entities/Creature/Creature.cpp @@ -1416,6 +1416,7 @@ void Creature::SaveToDB(uint32 mapid, uint8 spawnMask, uint32 phaseMask) trans->Append(stmt); WorldDatabase.CommitTransaction(trans); + sScriptMgr->OnCreatureSaveToDB(this); } void Creature::SelectLevel(bool changelevel) diff --git a/src/server/game/Entities/GameObject/GameObject.cpp b/src/server/game/Entities/GameObject/GameObject.cpp index 249a2e82e..e3b9216bc 100644 --- a/src/server/game/Entities/GameObject/GameObject.cpp +++ b/src/server/game/Entities/GameObject/GameObject.cpp @@ -1061,6 +1061,7 @@ void GameObject::SaveToDB(uint32 mapid, uint8 spawnMask, uint32 phaseMask, bool } WorldDatabase.CommitTransaction(trans); + sScriptMgr->OnGameObjectSaveToDB(this); } bool GameObject::LoadGameObjectFromDB(ObjectGuid::LowType spawnId, Map* map, bool addToMap) diff --git a/src/server/game/Scripting/ScriptDefines/AllCreatureScript.cpp b/src/server/game/Scripting/ScriptDefines/AllCreatureScript.cpp index 8fa40dd2b..896191242 100644 --- a/src/server/game/Scripting/ScriptDefines/AllCreatureScript.cpp +++ b/src/server/game/Scripting/ScriptDefines/AllCreatureScript.cpp @@ -38,6 +38,16 @@ void ScriptMgr::OnCreatureRemoveWorld(Creature* creature) }); } +void ScriptMgr::OnCreatureSaveToDB(Creature* creature) +{ + ASSERT(creature); + + ExecuteScript([&](AllCreatureScript* script) + { + script->OnCreatureSaveToDB(creature); + }); +} + void ScriptMgr::Creature_SelectLevel(const CreatureTemplate* cinfo, Creature* creature) { ExecuteScript([&](AllCreatureScript* script) diff --git a/src/server/game/Scripting/ScriptDefines/AllGameObjectScript.cpp b/src/server/game/Scripting/ScriptDefines/AllGameObjectScript.cpp index 39d4d62b2..933ef025f 100644 --- a/src/server/game/Scripting/ScriptDefines/AllGameObjectScript.cpp +++ b/src/server/game/Scripting/ScriptDefines/AllGameObjectScript.cpp @@ -37,3 +37,13 @@ void ScriptMgr::OnGameObjectRemoveWorld(GameObject* go) script->OnGameObjectRemoveWorld(go); }); } + +void ScriptMgr::OnGameObjectSaveToDB(GameObject* go) +{ + ASSERT(go); + + ExecuteScript([&](AllGameObjectScript* script) + { + script->OnGameObjectSaveToDB(go); + }); +} diff --git a/src/server/game/Scripting/ScriptMgr.h b/src/server/game/Scripting/ScriptMgr.h index bf874c096..d5e480509 100644 --- a/src/server/game/Scripting/ScriptMgr.h +++ b/src/server/game/Scripting/ScriptMgr.h @@ -561,6 +561,13 @@ public: */ virtual void OnCreatureRemoveWorld(Creature* /*creature*/) { } + /** + * @brief This hook runs after creature has been saved to DB + * + * @param creature Contains information about the Creature + */ + virtual void OnCreatureSaveToDB(Creature* /*creature*/) { } + /** * @brief This hook called when a player opens a gossip dialog with the creature. * @@ -643,7 +650,12 @@ public: * @param go Contains information about the GameObject */ virtual void OnGameObjectAddWorld(GameObject* /*go*/) { } - + /** + * @brief This hook runs after the game object iis saved to the database + * + * @param go Contains information about the GameObject + */ + virtual void OnGameObjectSaveToDB(GameObject* /*go*/) { } /** * @brief This hook runs after remove game object in world * @@ -2392,6 +2404,10 @@ public: /* AllCreatureScript */ //listener function (OnAllCreatureUpdate) is called by OnCreatureUpdate //void OnAllCreatureUpdate(Creature* creature, uint32 diff); void Creature_SelectLevel(const CreatureTemplate* cinfo, Creature* creature); + void OnCreatureSaveToDB(Creature* creature); + +public: /* AllGameobjectScript */ + void OnGameObjectSaveToDB(GameObject* go); public: /* AllMapScript */ void OnBeforeCreateInstanceScript(InstanceMap* instanceMap, InstanceScript* instanceData, bool load, std::string data, uint32 completedEncounterMask);