PDA

View Full Version : TrinityCore 3.3.5 Add tag before player name (chat)



zhier
07-19-2016, 01:40 AM
Hey what's up.

I wanna put a tag before the player name when (s)he send any message (say, yell, guild, etc).

At this moment, the basic msg:

[Zhier]: Hi bro.

I wanna do something like:

[TAG][Zhier]: Hi bro.

(I wanna do it with GetSecurity or checking which commands the player have).

I hope u can help me.

Thanks

slp13at420
07-19-2016, 02:04 AM
here is a link to all my different world chat scripts for Eluna and CPP --> https://github.com/BlackWolfsDen/World_Chat

you can see how i handle local chat trigger and channel chat trigger. also if you examine Guild Warz (http://emudevs.com/showthread.php/2260-Eluna-Grumbo-z-Guild-Warz-Tides-of-Desolation) you will see how i handle Guild channel chat trigger.

from there with Eluna you could just make 1 function to add the tag and then just register it to all those unique chat events(/say , /channel , /guild).

with CPP you could just make a sub function then call it from a player script chat event and it will just add the tag plus player name and return the updated msg. then send the new msg to all players in world while nil'ing the original msg i.e. (msg = -1). you will see how i do that in my CPP world chat scripts :)

zhier
07-19-2016, 02:13 AM
Hmm I can't understand all the code... I need to say I'm newbie in this but I do all what I can.

Can u tell me better which files I need to edit or something else...

I don't want World Chat, I want to set badges or tags to the traditional chat.

Thanks and sorry.

slp13at420
07-19-2016, 02:21 AM
the world chat scripts have badges n prefixes/tags in them , clickable names blah blah blah i was linking them for those examples.

- - - Updated - - -

basic World Chat cpp (http://emudevs.com/showthread.php/5564-Simple-World-Chat-script)
World Chat Script cpp (http://emudevs.com/showthread.php/5339-World-Chat-script)

you will see in the pix.

slp13at420
07-19-2016, 02:44 AM
im currently rewiping my pc or i would have whipped up a base script you could expand on.

zhier
07-19-2016, 02:48 AM
Thanks bro, no prob.

I will try to do that in base with all the links you gave me.

slp13at420
07-19-2016, 03:05 AM
if you run into a snag just post what you got so far n we can help you :)

slp13at420
07-23-2016, 03:58 AM
actually game/Chat/chat.cpp looks most promising:



std::string ChatHandler::GetNameLink(Player* chr) const
{
return playerLink(chr->GetName());
}






std::string ChatHandler::GetNameLink(Player* chr) const
{
return playerLink("<TAG>" + chr->GetName());
}



but somehow I lost my wotlk client folder so I gotta wait till it finishes downloading till I can do any testing but that should affect any chat and add the tag to the players name anytime GetNameLink() is called.
and you should be able to parse for condition requirements based on player.

zhier
07-23-2016, 05:07 PM
Wow, this is what I need to do.

I'm gonna try and reply this later.

zhier
07-23-2016, 07:02 PM
It didn't work :(

slp13at420
07-24-2016, 03:22 PM
i am getting some reaction by editing `senderName` in chat.cpp:
size_t ChatHandler::BuildChatPacket(WorldPacket& data, ChatMsg chatType, Language language, WorldObject const* sender, WorldObject const* receiver, std::string const& message,
uint32 achievementId /*= 0*/, std::string const& channelName /*= ""*/, LocaleConstant locale /*= DEFAULT_LOCALE*/)

its not exactly what I want it to do as you want since the tag is inside the brackets `[]` .. we need to find where those 2 brackets `[]` are added for the player name then we could try and insert the badge there .

zhier
07-24-2016, 05:42 PM
I could modify that but I supossed the namelinks will broke up..

slp13at420
07-24-2016, 06:19 PM
yea it breaks the name links since its actually editing the name.

slp13at420
07-24-2016, 06:25 PM
I think if we find where its all finally packed in the brackets we can insert the tag there.
most of it I can fake with script but the right way would require only 1-2 lines of code.

zhier
07-24-2016, 10:13 PM
I spent hours looking all files about "chat" and can not find anything like that ... maybe because I'm a little awkward in this or something haha

slp13at420
07-25-2016, 01:03 AM
lol me too . its got my interest peaked though lol .
right now trying it with just a script dunno if I can cover every chat though.

slp13at420
07-25-2016, 04:00 AM
here is what I have been tinkering with so far ...





#include "Chat.h"
#include "Language.h"
#include "Player.h"
#include "ScriptMgr.h"
#include <unordered_map>
#include "World.h"
#include "WorldSession.h"

bool USE_GM_BADGE = true;

std::string CBAC[8][3] = { { "0", "2a", "2b" }, { "1", "says", "|cffFFFFFF"}, { "2", "2a", "2b" }, { "3", "3a", "3b" }, { "4", "[Guild]", "|cff008000" }, { "5", "5a", "5b" }, { "6", "yells", "|cffFF0000" }, { "7", "whispers", "|cffDA70D6" } };

void SendMessage(uint8 type, std::string message, Player* player, Player* chat_target)
{
float SAY_DISTANCE = sWorld->getFloatConfig(CONFIG_LISTEN_RANGE_SAY);
float YELL_DISTANCE = sWorld->getFloatConfig(CONFIG_LISTEN_RANGE_YELL);
Position pos = player->GetPosition();
auto SENDER_TEAM_ID = player->GetTeamId();
uint32 GUILD_ID = player->GetGuildId();

SessionMap sessions = sWorld->GetAllSessions();

for (SessionMap::iterator itr = sessions.begin(); itr != sessions.end(); ++itr)
{

if (!itr->second)
continue;

Player *target = itr->second->GetPlayer();

if (type == 1) // say
{
if (target->GetDistance(pos) <= SAY_DISTANCE)
ChatHandler(target->GetSession()).PSendSysMessage(message.c_str());
}

if ((type == 4)&&(target->GetGuildId() > 0)&&(target->GetGuildId() == GUILD_ID)) // guild
{
ChatHandler(target->GetSession()).PSendSysMessage(message.c_str());
}

if (type == 6) // yell
{
if (target->GetDistance(pos) <= YELL_DISTANCE)
ChatHandler(target->GetSession()).PSendSysMessage(message.c_str());
}

if (type == 7) // whisper
{
if (target->GetName() == chat_target->GetName())
ChatHandler(target->GetSession()).PSendSysMessage(message.c_str());

}
}
}

std::string EditMessage(uint8 type, std::string name, std::string message, bool gm)
{
TC_LOG_INFO("server.loading", "TYPE:%u", type);

if (CBAC[type])
{
TC_LOG_INFO("server.loading", "NAME:%s", CBAC[type][1]);
TC_LOG_INFO("server.loading", "COLOR:%s", CBAC[type][2]);

// tags
std::string TAG = "<Tag>|r";
std::string GM_ICON = "|TINTERFACE/CHATFRAME/UI-CHATICON-BLIZZ:13:13:0:-1|t";
std::string NAME = "[|Hplayer:" + name + "|h" + name + "]";

// 1 say :: 6 yell :: 7 whisper ::
message = CBAC[type][2] + ":" + message + "|r";

if (type != 4) { message = CBAC[type][2] + CBAC[type][1] + "|r" + message; };

message = CBAC[type][2] + NAME + "|r" + message;
message = CBAC[type][2] + TAG + "|r" + message;

if (type == 4)
{
message = CBAC[type][2] + CBAC[type][1] + "|r" + message;
}

if ((gm)&&(USE_GM_BADGE))
{
message = GM_ICON + message;
}

}
return message;
}

class Player_Chat_For_Tagger : public PlayerScript
{
public: Player_Chat_For_Tagger() : PlayerScript("Player_Chat_For_Tagger") { }

virtual void OnChat(Player* player, uint32 type, uint32 lang, std::string& msg) // say
{
if ((lang != LANG_ADDON) && (msg != "" || "Away") && (player->CanSpeak() == true))
{
std::string message = EditMessage(type, player->GetName(), msg, player->IsGameMaster());
SendMessage(type, message, player, NULL);

msg = -1;
}
}

virtual void OnChat(Player* player, uint32 type, uint32 lang, std::string& msg, Player* receiver) // whisper
{
if ((lang != LANG_ADDON) && (msg != "" || "Away") && (player->CanSpeak() == true))
{
std::string message = EditMessage(type, player->GetName(), msg, player->IsGameMaster());
SendMessage(type, message, player, receiver);

msg = -1;
}
}


virtual void OnChat(Player* player, uint32 type, uint32 lang, std::string& msg, Group* group) // group
{
if ((lang != LANG_ADDON) && (msg != "" || "Away") && (player->CanSpeak() == true))
{
std::string message = EditMessage(type, player->GetName(), msg, player->IsGameMaster());
SendMessage(type, message, player, NULL);

// msg = -1;
}
}

virtual void OnChat(Player* player, uint32 type, uint32 lang, std::string& msg, Guild* guild)
{
if ((lang != LANG_ADDON) && (msg != "" || "Away") && (player->CanSpeak() == true))
{
std::string message = EditMessage(type, player->GetName(), msg, player->IsGameMaster());

SendMessage(type, message, player, NULL);

msg = -1;
}
}

virtual void OnChat(Player* player, uint32 type, uint32 lang, std::string& msg, Channel* channel) // channel
{
if ((lang != LANG_ADDON) && (msg != "" || "Away") && (player->CanSpeak() == true))
{
// std::string message = EditMessage(type, player->GetName(), msg, player->IsGameMaster());

// SendMessage(type, message, player, NULL);

// msg = -1;
}
}

};

void AddSC_ChatBadgeAdder()
{
new Player_Chat_For_Tagger;
}

slp13at420
07-27-2016, 05:35 PM
came across an error when dealing with a chat type that isn't in the table yet ..took some time to get itt to check for nil data but now it does:




#include "Channel.h"
// #include "ChannelMgr.h"
#include "Chat.h"
#include "Language.h"
// #include "ObjectMgr.h"
#include "Player.h"
// #include "RBAC.h"
#include "ScriptMgr.h"
#include <unordered_map>
#include "World.h"
#include "WorldSession.h"

bool USE_GM_BADGE = true;
std::string CBAC[8][3] = { { "0", "0a", "0b" }, { "1", "says", "|cffFFFFFF"}, { "2", "2a", "2b" }, { "3", "3a", "3b" }, { "4", "[Guild]", "|cff008000" }, { "5", "5a", "5b" }, { "6", "yells", "|cffFF0000" }, { "7", "whispers", "|cffDA70D6" } };

void SendMessage(uint8 type, std::string message, Player* player, Player* chat_target)
{
float SAY_DISTANCE = sWorld->getFloatConfig(CONFIG_LISTEN_RANGE_SAY);
float YELL_DISTANCE = sWorld->getFloatConfig(CONFIG_LISTEN_RANGE_YELL);

Position pos = player->GetPosition();
auto SENDER_TEAM_ID = player->GetTeamId();
uint32 GUILD_ID = player->GetGuildId();

SessionMap sessions = sWorld->GetAllSessions();

for (SessionMap::iterator itr = sessions.begin(); itr != sessions.end(); ++itr)
{

if (!itr->second)
continue;

Player *target = itr->second->GetPlayer();

if ((type == 1)&&(target->GetDistance(pos) <= SAY_DISTANCE))// say
{
ChatHandler(target->GetSession()).PSendSysMessage(message.c_str());
}

if ((type == 4)&&(target->GetGuildId() > 0)&&(target->GetGuildId() == GUILD_ID))// guild
{
ChatHandler(target->GetSession()).PSendSysMessage(message.c_str());
}

if ((type == 6)&&(target->GetDistance(pos) <= YELL_DISTANCE)) // yell
{
ChatHandler(target->GetSession()).PSendSysMessage(message.c_str());
}

if ((type == 7)&&(target->GetName() == chat_target->GetName())) // whisper
{
ChatHandler(target->GetSession()).PSendSysMessage(message.c_str());
}
}
}

std::string EditMessage(uint8 type, std::string name, std::string message, bool gm)
{
// TC_LOG_INFO("server.loading", "TYPE:%u", type);

if ((CBAC[type]) && (CBAC[type][2].size() > 0))
{
// TC_LOG_INFO("server.loading", "PASSED.");
// TC_LOG_INFO("server.loading", "NAME:%s", CBAC[type][1]);
// TC_LOG_INFO("server.loading", "COLOR:%s", CBAC[type][2]);

// tags
std::string TAG = "<Tag>|r";
std::string GM_ICON = "|TINTERFACE/CHATFRAME/UI-CHATICON-BLIZZ:13:13:0:-1|t";
std::string NAME = "[|Hplayer:" + name + "|h" + name + "]";

// 1 say :: 4 guild :: 6 yell :: 7 whisper ::
message = CBAC[type][2] + ":" + message + "|r";

if (type != 4) { message = CBAC[type][2] + CBAC[type][1] + "|r" + message; };

message = CBAC[type][2] + NAME + "|r" + message;
message = CBAC[type][2] + TAG + "|r" + message;

if (type == 4)
{
message = CBAC[type][2] + CBAC[type][1] + "|r" + message;
}

if ((gm)&&(USE_GM_BADGE))
{
message = GM_ICON + message;
}

}
return message;
}

class Player_Chat_For_Tagger : public PlayerScript
{
public: Player_Chat_For_Tagger() : PlayerScript("Player_Chat_For_Tagger") { }

virtual void OnChat(Player* player, uint32 type, uint32 lang, std::string& msg) // say
{
if ((lang != LANG_ADDON) && (msg != "" || "Away") && (player->CanSpeak() == true))
{
std::string message = EditMessage(type, player->GetName(), msg, player->IsGameMaster());
SendMessage(type, message, player, NULL);

msg = -1;
}
}

virtual void OnChat(Player* player, uint32 type, uint32 lang, std::string& msg, Player* receiver) // whisper
{
if ((lang != LANG_ADDON) && (msg != "" || "Away") && (player->CanSpeak() == true))
{
std::string message = EditMessage(type, player->GetName(), msg, player->IsGameMaster());
SendMessage(type, message, player, receiver);

msg = -1;
}
}


virtual void OnChat(Player* player, uint32 type, uint32 lang, std::string& msg, Group* group) // group
{
if ((lang != LANG_ADDON) && (msg != "" || "Away") && (player->CanSpeak() == true))
{
std::string message = EditMessage(type, player->GetName(), msg, player->IsGameMaster());
SendMessage(type, message, player, NULL);

// msg = -1;
}
}

virtual void OnChat(Player* player, uint32 type, uint32 lang, std::string& msg, Guild* guild)
{
if ((lang != LANG_ADDON) && (msg != "" || "Away") && (player->CanSpeak() == true))
{
std::string message = EditMessage(type, player->GetName(), msg, player->IsGameMaster());

SendMessage(type, message, player, NULL);

msg = -1;
}
}

virtual void OnChat(Player* player, uint32 type, uint32 lang, std::string& msg, Channel* channel) // channel
{
if ((lang != LANG_ADDON) && (msg != "" || "Away") && (player->CanSpeak() == true))
{
// std::string message = EditMessage(type, player->GetName(), msg, player->IsGameMaster());

// SendMessage(type, message, player, NULL);

// msg = -1;
}
}

};

void AddSC_ChatBadgeAdder()
{
new Player_Chat_For_Tagger;
}



the green for Guild chat needs to be brighter lol

this does NOT edit the existing chat channels but rather intercepts the message and bypasses the chat system completely then it edits the message with tags then it sends the message to the world to be received by selected players based on the chat type making it appear like it was sent by the chat system.
so far this does say, yell, guild and whisper.

593

zhier
07-31-2016, 12:37 AM
It looks very good, I'm gonna test it.

Sorry for reply too late, I was doing some extra things.

In some hours I'm gonna reply again to tell u my report.

Thanks a lot.

slp13at420
07-31-2016, 02:45 AM
the whisper needs a line for whisper to who . I just been trying to update some other projects for latest rev ... lol