Skip to content

Commit

Permalink
Add new Player and Item hooks
Browse files Browse the repository at this point in the history
These are somewhat equivalent with the AzerothCore custom hooks, though they do work a little differently. Ensure to read the documentation if something differs.
  • Loading branch information
Foereaper committed Oct 13, 2023
1 parent 7a83897 commit 90bd45d
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 0 deletions.
16 changes: 16 additions & 0 deletions Hooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,18 @@ namespace Hooks
PLAYER_EVENT_ON_ENVIRONMENTAL_DEATH = 40, // (event, player, environmentalDamageType)
// UNUSED = 41, // (event, player)
PLAYER_EVENT_ON_COMMAND = 42, // (event, player, command) - player is nil if command used from console. Can return false
// UNUSED = 43, // (event, player)
PLAYER_EVENT_ON_LEARN_SPELL = 44, // (event, player, spellId)
PLAYER_EVENT_ON_ACHIEVEMENT_COMPLETE = 45, // (event, player, achievementId)
// UNUSED = 46, // (event, player)
PLAYER_EVENT_ON_UPDATE_AREA = 47, // (event, player, oldArea, newArea)
// UNUSED = 48, // (event, player)
// UNUSED = 49, // (event, player)
// UNUSED = 50, // (event, player)
// UNUSED = 51, // (event, player)
// UNUSED = 52, // (event, player)
// UNUSED = 53, // (event, player)
PLAYER_EVENT_ON_QUEST_STATUS_CHANGED = 54, // (event, player, questId, status)

PLAYER_EVENT_COUNT
};
Expand Down Expand Up @@ -319,6 +331,10 @@ namespace Hooks
ITEM_EVENT_ON_QUEST_ACCEPT = 3, // (event, player, item, quest) - Can return true
ITEM_EVENT_ON_EXPIRE = 4, // (event, player, itemid) - Can return true
ITEM_EVENT_ON_REMOVE = 5, // (event, player, item) - Can return true

// Custom
ITEM_EVENT_ON_ADD = 6, // (event, player, item)

ITEM_EVENT_COUNT
};

Expand Down
8 changes: 8 additions & 0 deletions ItemHooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,11 @@ bool Eluna::OnRemove(Player* pPlayer, Item* pItem)
Push(pItem);
return CallAllFunctionsBool(ItemEventBindings, key);
}

void Eluna::OnAdd(Player* pPlayer, Item* pItem)
{
START_HOOK(ITEM_EVENT_ON_ADD, pItem->GetEntry());
Push(pPlayer);
Push(pItem);
CallAllFunctions(ItemEventBindings, key);
}
5 changes: 5 additions & 0 deletions LuaEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,9 @@ class ELUNA_GAME_API Eluna
void OnRepop(Player* pPlayer);
void OnResurrect(Player* pPlayer);
void OnQuestAbandon(Player* pPlayer, uint32 questId);
void OnQuestStatusChanged(Player* pPlayer, uint32 questId, uint8 status);
void OnLearnTalents(Player* pPlayer, uint32 talentId, uint32 talentRank, uint32 spellid);
void OnLearnSpell(Player* pPlayer, uint32 spellid);
InventoryResult OnCanUseItem(const Player* pPlayer, uint32 itemEntry);
void OnLuaStateClose();
void OnLuaStateOpen();
Expand All @@ -392,6 +394,7 @@ class ELUNA_GAME_API Eluna
bool OnItemGossip(Player* pPlayer, Item* pItem, SpellCastTargets const& targets);
bool OnExpire(Player* pPlayer, ItemTemplate const* pProto);
bool OnRemove(Player* pPlayer, Item* item);
void OnAdd(Player* pPlayer, Item* item);
void HandleGossipSelectOption(Player* pPlayer, Item* item, uint32 sender, uint32 action, const std::string& code);

/* Creature */
Expand Down Expand Up @@ -488,8 +491,10 @@ class ELUNA_GAME_API Eluna
void OnSave(Player* pPlayer);
void OnBindToInstance(Player* pPlayer, Difficulty difficulty, uint32 mapid, bool permanent);
void OnUpdateZone(Player* pPlayer, uint32 newZone, uint32 newArea);
void OnUpdateArea(Player* pPlayer, uint32 oldArea, uint32 newArea);
void OnMapChanged(Player* pPlayer);
void HandleGossipSelectOption(Player* pPlayer, uint32 menuId, uint32 sender, uint32 action, const std::string& code);
void OnAchievementComplete(Player* pPlayer, uint32 achievementId);

#ifndef CLASSIC
#ifndef TBC
Expand Down
34 changes: 34 additions & 0 deletions PlayerHooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ void Eluna::OnLearnTalents(Player* pPlayer, uint32 talentId, uint32 talentRank,
CallAllFunctions(PlayerEventBindings, key);
}

void Eluna::OnLearnSpell(Player* pPlayer, uint32 spellId)
{
START_HOOK(PLAYER_EVENT_ON_LEARN_TALENTS);
Push(pPlayer);
Push(spellId);
CallAllFunctions(PlayerEventBindings, key);
}

bool Eluna::OnCommand(Player* player, const char* text)
{
// If from console, player is NULL
Expand Down Expand Up @@ -106,6 +114,15 @@ void Eluna::OnQuestAbandon(Player* pPlayer, uint32 questId)
CallAllFunctions(PlayerEventBindings, key);
}

void Eluna::OnQuestStatusChanged(Player* pPlayer, uint32 questId, uint8 status)
{
START_HOOK(PLAYER_EVENT_ON_QUEST_STATUS_CHANGED);
Push(pPlayer);
Push(questId);
Push(status);
CallAllFunctions(PlayerEventBindings, key);
}

void Eluna::OnEquip(Player* pPlayer, Item* pItem, uint8 bag, uint8 slot)
{
START_HOOK(PLAYER_EVENT_ON_EQUIP);
Expand Down Expand Up @@ -419,13 +436,30 @@ void Eluna::OnUpdateZone(Player* pPlayer, uint32 newZone, uint32 newArea)
CallAllFunctions(PlayerEventBindings, key);
}

void Eluna::OnUpdateArea(Player* pPlayer, uint32 oldArea, uint32 newArea)
{
START_HOOK(PLAYER_EVENT_ON_UPDATE_AREA);
Push(pPlayer);
Push(oldArea);
Push(newArea);
CallAllFunctions(PlayerEventBindings, key);
}

void Eluna::OnMapChanged(Player* player)
{
START_HOOK(PLAYER_EVENT_ON_MAP_CHANGE);
Push(player);
CallAllFunctions(PlayerEventBindings, key);
}

void Eluna::OnAchievementComplete(Player* player, uint32 achievementId)
{
START_HOOK(PLAYER_EVENT_ON_ACHIEVEMENT_COMPLETE);
Push(player);
Push(achievementId);
CallAllFunctions(PlayerEventBindings, key);
}

bool Eluna::OnChat(Player* pPlayer, uint32 type, uint32 lang, std::string& msg)
{
if (lang == LANG_ADDON)
Expand Down
13 changes: 13 additions & 0 deletions TrinityCore/GlobalMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,18 @@ namespace LuaGlobalFunctions
* PLAYER_EVENT_ON_ENVIRONMENTAL_DEATH = 40, // (event, player, environmentalDamageType)
* // UNUSED = 41, // (event, player)
* PLAYER_EVENT_ON_COMMAND = 42, // (event, player, command) - player is nil if command used from console. Can return false
* // UNUSED = 43, // (event, player)
* PLAYER_EVENT_ON_LEARN_SPELL = 44, // (event, player, spellId)
* PLAYER_EVENT_ON_ACHIEVEMENT_COMPLETE = 45, // (event, player, achievementId)
* // UNUSED = 46, // (event, player)
* PLAYER_EVENT_ON_UPDATE_AREA = 47, // (event, player, oldArea, newArea)
* // UNUSED = 48, // (event, player)
* // UNUSED = 49, // (event, player)
* // UNUSED = 50, // (event, player)
* // UNUSED = 51, // (event, player)
* // UNUSED = 52, // (event, player)
* // UNUSED = 53, // (event, player)
* PLAYER_EVENT_ON_QUEST_STATUS_CHANGED = 54, // (event, player, questId, status)
* };
* </pre>
*
Expand Down Expand Up @@ -860,6 +872,7 @@ namespace LuaGlobalFunctions
* ITEM_EVENT_ON_QUEST_ACCEPT = 3, // (event, player, item, quest) - Can return true
* ITEM_EVENT_ON_EXPIRE = 4, // (event, player, itemid) - Can return true
* ITEM_EVENT_ON_REMOVE = 5, // (event, player, item) - Can return true
* ITEM_EVENT_ON_ADD = 6, // (event, player, item)
* ITEM_EVENT_COUNT
* };
* </pre>
Expand Down

0 comments on commit 90bd45d

Please sign in to comment.