Yes, it's possible. When writing a module you use the existing hooks that are available in AzerothCore. If you need a hook that is not existing yet, you can simply create it and send a PR to AzerothCore.
How to add new hooks: a practical example
I needed to create a very simple module that sends the player a warning whenever he/she leaves the BG queue after being invited to join.
This is the code of my module, very basic:
void OnBattlegroundDesertion(Player* player, const BattlegroundDesertionType type) override
{
if (sConfigMgr->GetBoolDefault(DESERTION_ENABLED_CONFIG, false))
{
switch (type)
{
case BG_DESERTION_TYPE_LEAVE_QUEUE:
case BG_DESERTION_TYPE_NO_ENTER_BUTTON:
ChatHandler(player->GetSession()).PSendSysMessage("%s", sConfigMgr->GetStringDefault(WARNING_TEXT_CONFIG, "").c_str());
break;
default:
break;
}
}
}
the full source code of the module is available here: https://github.com/azerothcore/mod-desertion-warnings
Looks very easy right? Especially if you had that OnBattlegroundDesertion
method that gave me what I needed (the Player
and the BattlegroundDesertionType
).
There was only one problem... the hook OnBattlegroundDesertion
didn't exist before!
But it's ok, I just had to implement it in the core, and this is the PR that does the job:
https://github.com/azerothcore/azerothcore-wotlk/pull/4619
As you can see it's just a matter of creating the method in ScriptMgr.h
and ScriptMgr.cpp
(the same way other hook-methods are created) and then call it around the core whenever I needed it.