From 34c27cecd436bb1565ed815258b5051534daa3a5 Mon Sep 17 00:00:00 2001 From: Foereaper Date: Fri, 13 Oct 2023 22:09:17 +0200 Subject: [PATCH] Added Trade Init and Accept hooks --- Hooks.h | 4 ++-- LuaEngine.h | 2 ++ PlayerHooks.cpp | 16 ++++++++++++++++ TrinityCore/GlobalMethods.h | 4 ++-- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/Hooks.h b/Hooks.h index e2b070ab4c..17fa08693f 100644 --- a/Hooks.h +++ b/Hooks.h @@ -202,14 +202,14 @@ namespace Hooks PLAYER_EVENT_ON_QUEST_ABANDON = 38, // (event, player, questId) PLAYER_EVENT_ON_LEARN_TALENTS = 39, // (event, player, talentId, talentRank, spellid) PLAYER_EVENT_ON_ENVIRONMENTAL_DEATH = 40, // (event, player, environmentalDamageType) - // UNUSED = 41, // (event, player) + PLAYER_EVENT_ON_TRADE_ACCEPT = 41, // (event, player, target) - Can return false to interrupt trade 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) + PLAYER_EVENT_ON_TRADE_INIT = 48, // (event, player, target) - Can return false to interrupt trade // UNUSED = 49, // (event, player) // UNUSED = 50, // (event, player) // UNUSED = 51, // (event, player) diff --git a/LuaEngine.h b/LuaEngine.h index 59c9c723c5..74f92ea60b 100644 --- a/LuaEngine.h +++ b/LuaEngine.h @@ -385,6 +385,8 @@ class ELUNA_GAME_API Eluna void OnLuaStateClose(); void OnLuaStateOpen(); bool OnAddonMessage(Player* sender, uint32 type, std::string& msg, Player* receiver, Guild* guild, Group* group, Channel* channel); + bool OnTradeInit(Player* trader, Player* tradee); + bool OnTradeAccept(Player* trader, Player* tradee); /* Item */ void OnDummyEffect(WorldObject* pCaster, uint32 spellId, SpellEffIndex effIndex, Item* pTarget); diff --git a/PlayerHooks.cpp b/PlayerHooks.cpp index 8b53ebc8af..f7863ec07c 100644 --- a/PlayerHooks.cpp +++ b/PlayerHooks.cpp @@ -460,6 +460,22 @@ void Eluna::OnAchievementComplete(Player* player, uint32 achievementId) CallAllFunctions(PlayerEventBindings, key); } +bool Eluna::OnTradeInit(Player* trader, Player* tradee) +{ + START_HOOK_WITH_RETVAL(PLAYER_EVENT_ON_TRADE_INIT, true); + Push(trader); + Push(tradee); + return CallAllFunctionsBool(PlayerEventBindings, key, true); +} + +bool Eluna::OnTradeAccept(Player* trader, Player* tradee) +{ + START_HOOK_WITH_RETVAL(PLAYER_EVENT_ON_TRADE_ACCEPT, true); + Push(trader); + Push(tradee); + return CallAllFunctionsBool(PlayerEventBindings, key, true); +} + bool Eluna::OnChat(Player* pPlayer, uint32 type, uint32 lang, std::string& msg) { if (lang == LANG_ADDON) diff --git a/TrinityCore/GlobalMethods.h b/TrinityCore/GlobalMethods.h index 417b88cccd..a3e5b46c89 100644 --- a/TrinityCore/GlobalMethods.h +++ b/TrinityCore/GlobalMethods.h @@ -650,14 +650,14 @@ namespace LuaGlobalFunctions * PLAYER_EVENT_ON_QUEST_ABANDON = 38, // (event, player, questId) * PLAYER_EVENT_ON_LEARN_TALENTS = 39, // (event, player, talentId, talentRank, spellid) * PLAYER_EVENT_ON_ENVIRONMENTAL_DEATH = 40, // (event, player, environmentalDamageType) - * // UNUSED = 41, // (event, player) + * PLAYER_EVENT_ON_TRADE_ACCEPT = 41, // (event, player, target) - Can return false to interrupt trade * 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) + * PLAYER_EVENT_ON_TRADE_INIT = 48, // (event, player, target) - Can return false to interrupt trade * // UNUSED = 49, // (event, player) * // UNUSED = 50, // (event, player) * // UNUSED = 51, // (event, player)