Modcraft - The community dedicated to quality WoW modding!
Wrath of the Lich King Modding => Serverside Modding => Topic started by: ferreon on September 11, 2014, 01:48:09 pm
-
Hi people!
I need to make a custom script that change the interface in a specific event and I know more or less how to do it but I need some help. The interface will receive a message sent from the server
SendMessagebrglasd(aasd, oooa, suwa)
and I'll react. The problem is that I don't know how to capture the message.
Thanks to all, hope you understand what I want to do.
-
Listen to the matching event from http://www.wowwiki.com/Events/Communication (http://www.wowwiki.com/Events/Communication" onclick="window.open(this.href);return false;).
-
Addon messages are an easy way to do it:
E.g, taken from one of my scripts, I listen for messages this way:
function eventHandlerMainFrame(self, event, message, _, Type, Sender)
if (event == "CHAT_MSG_ADDON" and Sender == UnitName("player")) then
local packet, link, linkCount, MSG = message:match("(%d%d%d)(%d%d)(%d%d)(.+)");
if not packet or not link or not linkCount or not MSG then
return
end
packet, link, linkCount = tonumber(packet), tonumber(link), tonumber(linkCount);
links[packet] = links[packet] or {count = 0};
links[packet][link] = MSG;
links[packet].count = links[packet].count + 1;
if (links[packet].count ~= linkCount) then
return
end
local fullMessage = table.concat(links[packet]);
links[packet] = {count = 0};
-- Handle addon messages
-- Handle game list
if string.starts(fullMessage, "GAMES-") then
local tokens = scen_split(fullMessage)
local pos = 1
for i=2, #tokens, 2 do
ONLINE_PLAYERS[pos] = {tokens[i + 1], tokens[i]}
pos = pos + 1
end
-- update view
SB_Main_ScrollBar_Update()
elseif string.starts(fullMessage, "PLAYERS-") then
local tokens = scen_split(fullMessage)
for i=2, #tokens do
ONLINE_PLAYERS[i - 1] = {tokens[i], "1"}
end
-- update view
SB_Main_ScrollBar_Update()
elseif string.starts(fullMessage, "SelectedPerks-") then
local tokens = scen_split(fullMessage)
local perks = tokens[2]
local offsets = {1, 3, 5, 7}
for i=1,4 do
SELECTED_PERKS[i] = tonumber(perks:sub(offsets[i], offsets[i] + 1))
end
end
end
end
I send addon messages this way:
SendAddonMessage("CREATEGAME", messageToSend, "WHISPER", UnitName("player"))
I send messages from the server to client this way:
void WorldSession::SendAddonMessage(Player* player, std::string message, uint32 packet)
{
uint32 splitLength = 240;
uint32 splits = ceil((float)message.length() / (float)splitLength);
uint32 counter = 1;
for (uint32 i = 0; i < message.length(); i += splitLength)
{
std::stringstream send;
send << std::setfill('0') << std::setw(3) << packet;
send << std::setw(2) << counter;
send << std::setw(2) << splits;
send << message.substr(i, std::min(splitLength, (uint32)(message.length() - i)));
counter = counter + 1;
WorldPacket* data = new WorldPacket();
uint32 messageLength = send.str().length() + 1;
data->Initialize(SMSG_MESSAGECHAT, 100);
*data << (uint8)CHAT_MSG_SYSTEM;
*data << LANG_ADDON;
*data << player->GetGUID();
*data << uint32(0);
*data << player->GetGUID();
*data << messageLength;
*data << send.str().c_str();
*data << uint8(0);
player->GetSession()->SendPacket(data);
TC_LOG_INFO("server.debug", "[DEBUG] Sent: %s", send.str().c_str());
}
}
-
Maybe is outdated or I don't know (I included Worldsession.h at the start of script):
SendAddonMessage is not a member of WorldSession
http://gyazo.com/0f5072166d4de33ea38e862695c4f8f4 (http://gyazo.com/0f5072166d4de33ea38e862695c4f8f4" onclick="window.open(this.href);return false;)
other possibility (Without Worldsession::)
http://gyazo.com/37b43a33bc091a781186bc1cdde5a7e1 (http://gyazo.com/37b43a33bc091a781186bc1cdde5a7e1" onclick="window.open(this.href);return false;)
Then I have to call the function on an "if" and I don't know how to do it:
http://gyazo.com/daa737807c31c972c85e62f089a5556f (http://gyazo.com/daa737807c31c972c85e62f089a5556f" onclick="window.open(this.href);return false;)
(Not the complete function, only the part in which I have to call it)
Thanks. Ferreon.
-
http://www.tutorialspoint.com/cplusplus ... ctions.htm (http://www.tutorialspoint.com/cplusplus/cpp_class_member_functions.htm" onclick="window.open(this.href);return false;)
-
Ok thanks for the link. Now I edited the code but the server do not show the message when player update a zone and nothings appears on TC_LOG_INFO neither.
http://gyazo.com/19fe936a9ed601cc4dedb644343db79c (http://gyazo.com/19fe936a9ed601cc4dedb644343db79c" onclick="window.open(this.href);return false;)
Thanks for the answers, Ferreon.
-
Ok thanks for the link. Now I edited the code but the server do not show the message when player update a zone and nothings appears on TC_LOG_INFO neither.
http://gyazo.com/19fe936a9ed601cc4dedb644343db79c (http://gyazo.com/19fe936a9ed601cc4dedb644343db79c" onclick="window.open(this.href);return false;)
Thanks for the answers, Ferreon.
Add a breakpoint and follow through the code if you can. TC_LOG_INFO syntax may have changed since I used it and/or you are not printing that log level. Print out -all- addon messages received client side, even when the event is called. Allows for easier debugging.