This is a read only copy without any forum functionality of the old Modcraft forum.
If there is anything that you would like to have removed, message me on Discord via Kaev#5208.
Big thanks to Alastor for making this copy!

Menu

Author Topic: [QUESTION] Custom interface scripting  (Read 2044 times)

ferreon

  • Contributors
  • Loreweaver
  • *****
  • Posts: 104
    • View Profile
[QUESTION] Custom interface scripting
« 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

Code: [Select]
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.
« Last Edit: January 01, 1970, 01:00:00 am by Admin »

schlumpf

  • Administrator
  • Creator of Worlds
  • *****
  • Posts: 2967
    • View Profile
Re: [QUESTION] Custom interface scripting
« Reply #1 on: September 11, 2014, 02:01:53 pm »
Listen to the matching event from http://www.wowwiki.com/Events/Communication.
« Last Edit: January 01, 1970, 01:00:00 am by Admin »

stoneharry

  • Contributors
  • Creator of Worlds
  • *****
  • Posts: 617
    • View Profile
Re: [QUESTION] Custom interface scripting
« Reply #2 on: September 11, 2014, 06:39:49 pm »
Addon messages are an easy way to do it:

E.g, taken from one of my scripts, I listen for messages this way:

Code: [Select]
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:

Code: [Select]
SendAddonMessage("CREATEGAME", messageToSend, "WHISPER", UnitName("player"))

I send messages from the server to client this way:

Code: [Select]
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());
}
}
« Last Edit: January 01, 1970, 01:00:00 am by Admin »

ferreon

  • Contributors
  • Loreweaver
  • *****
  • Posts: 104
    • View Profile
Re: [QUESTION] Custom interface scripting
« Reply #3 on: September 11, 2014, 10:05:49 pm »
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

other possibility (Without Worldsession::)

http://gyazo.com/37b43a33bc091a781186bc1cdde5a7e1

Then I have to call the function on an "if" and I don't know how to do it:
http://gyazo.com/daa737807c31c972c85e62f089a5556f

(Not the complete function, only the part in which I have to call it)

Thanks. Ferreon.
« Last Edit: January 01, 1970, 01:00:00 am by Admin »

schlumpf

  • Administrator
  • Creator of Worlds
  • *****
  • Posts: 2967
    • View Profile
« Last Edit: January 01, 1970, 01:00:00 am by Admin »

ferreon

  • Contributors
  • Loreweaver
  • *****
  • Posts: 104
    • View Profile
Re: [QUESTION] Custom interface scripting
« Reply #5 on: September 11, 2014, 10:38:45 pm »
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

Thanks for the answers, Ferreon.
« Last Edit: January 01, 1970, 01:00:00 am by Admin »

stoneharry

  • Contributors
  • Creator of Worlds
  • *****
  • Posts: 617
    • View Profile
Re: [QUESTION] Custom interface scripting
« Reply #6 on: September 11, 2014, 10:42:01 pm »
Quote from: "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

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.
« Last Edit: January 01, 1970, 01:00:00 am by Admin »