• This is a read only backup of the old Emudevs forum. If you want to have anything removed, please message me on Discord: KittyKaev

TrinityCore 3.3.5 Add tag before player name (chat)

zhier

Member
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

Mad Scientist
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 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 :)
 
Last edited:

zhier

Member
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

Mad Scientist
actually game/Chat/chat.cpp looks most promising:
Code:
[COLOR="#808080"]
std::string ChatHandler::GetNameLink(Player* chr) const
{
    return playerLink(chr->GetName());
}
[/COLOR]

Code:
[COLOR="#808080"]
std::string ChatHandler::GetNameLink(Player* chr) const
{
    return playerLink("<TAG>" + chr->GetName());
}
[/COLOR]

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.
 

slp13at420

Mad Scientist
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 .
 

slp13at420

Mad Scientist
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

Member
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

Mad Scientist
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

Mad Scientist
here is what I have been tinkering with so far ...


Code:
[COLOR="#808080"]
#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;
}
[/COLOR]
 
Last edited:

slp13at420

Mad Scientist
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:

Code:
[COLOR="#808080"]
#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;
}
[/COLOR]

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.

tag for names2.jpg
 
Last edited:

zhier

Member
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

Mad Scientist
the whisper needs a line for whisper to who . I just been trying to update some other projects for latest rev ... lol
 
Top