From 54899419e09dc1ef1ec026f84f589540a64de4c4 Mon Sep 17 00:00:00 2001 From: Foereaper Date: Sun, 6 Apr 2014 00:54:41 +0200 Subject: [PATCH] Eluna SendAddonMessage method Added: SendAddonMessage method. TODO: Debug, does not work. @Easelm --- LuaFunctions.cpp | 1 + PlayerMethods.h | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/LuaFunctions.cpp b/LuaFunctions.cpp index 5408465..8a133e4 100644 --- a/LuaFunctions.cpp +++ b/LuaFunctions.cpp @@ -592,6 +592,7 @@ ElunaRegister PlayerMethods[] = { "SendAreaTriggerMessage", &LuaPlayer::SendAreaTriggerMessage }, // :SendAreaTriggerMessage(message) - Sends a yellow message in the middle of your screen { "SendNotification", &LuaPlayer::SendNotification }, // :SendNotification(message) - Sends a red message in the middle of your screen { "SendPacket", &LuaPlayer::SendPacket }, // :SendPacket(packet, selfOnly) - Sends a packet to player or everyone around also if selfOnly is false + { "SendAddonMessage", &LuaPlayer::SendAddonMessage }, // :SendAddonMessage(prefix, message, channel, receiver) - Sends an addon message to the player. { "SendVendorWindow", &LuaPlayer::SendVendorWindow }, // :SendVendorWindow(unit) - Sends the unit's vendor window to the player { "ModifyMoney", &LuaPlayer::ModifyMoney }, // :ModifyMoney(amount[, sendError]) - Modifies (does not set) money (copper count) of the player. Amount can be negative to remove copper { "LearnSpell", &LuaPlayer::LearnSpell }, // :LearnSpell(id) - learns the given spell diff --git a/PlayerMethods.h b/PlayerMethods.h index fd4287f..9468614 100644 --- a/PlayerMethods.h +++ b/PlayerMethods.h @@ -2229,6 +2229,37 @@ namespace LuaPlayer return 0; } + int SendAddonMessage(lua_State* L, Player* player) + { + std::string prefix = sEluna->CHECKVAL(L, 1); + std::string message = sEluna->CHECKVAL(L, 2); + uint8 channel = sEluna->CHECKVAL(L, 3); + uint64 receiver = sEluna->CHECKVAL(L, 4); + + std::string fullmsg = prefix + '\t' + message; + + // Needs a custom built packet since TC doesnt send guid + WorldPacket* data = new WorldPacket(); + uint32 messageLength = (uint32)strlen(fullmsg.c_str()) + 1; + data->Initialize(SMSG_MESSAGECHAT, 100); + *data << channel; + *data << LANG_ADDON; + *data << player->GetGUID(); + *data << uint32(0); + + if (channel == CHAT_MSG_WHISPER) + *data << receiver; + else + *data << uint64(0); + + *data << messageLength; + *data << fullmsg; + *data << uint8(0); + player->GetSession()->SendPacket(data); + + return 0; + } + /*int BindToInstance(lua_State* L, Player* player) { player->BindToInstance();