• 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 [CPP][Conv] Dedicated World CHat Channel

slp13at420

Mad Scientist
[CPP][Conv] Dedicated World Chat Channel

Exactly as the title says.
this is a conversion of one of my World Chat scripts.

This script will allow you to select a chat channel I.e. `/1` and dedicate it to World Chat with color, intractable names, GM badge/title, class and team colors.
comes with worldserver.conf edits for easy changes.

just add to your source, compile, and set what channel, if its team or world, and duration check in the conf.

then players just change to the selected channel i.e. `/2` and just chat away . Again no prefix or chat command required.

Worldserver.conf additions:
Code:
[COLOR="#808080"]
###################################################################################################
# Dedicated World Chat Channel
# By slp13at420 of EmuDevs.com
#
#
# This setting allows you to select what channel to dedicate for World Chat. 
# 
# 	WORLDCHANNELCHAT.CHANNEL
#		Description: channel id.
#		Default: 1

WORLDCHANNELCHAT.CHANNEL = 3

#
# This setting will adjust the spam check duration between a players messages. 
# 
# 	WORLDCHANNELCHAT.DELAY
#		Description: forces players to wait x seconds between each message they send.
#		             1 = 1 second.
#		Default: 5 // 5 second wait.

WORLDCHANNELCHAT.DELAY = 5

#
# This setting will set if wether a players message is seen by only there team or world. 
# 
# 	WORLDCHANNELCHAT.TEAM
#		Description: 0 = world // 1 = team only.
#		Default: 1 // 1 team only.

WORLDCHANNELCHAT.TYPE = 1

#
#####################################################################################################################
[/COLOR]

World_Channel_Chat.cpp:
Code:
[COLOR="#808080"]
/*
a simple chat system.
with a selectable channel conf edit.
with adjustable color layout and adjustable channel name.
made by slp13at420 of EmuDevs.com
*/

#include "Channel.h"
// #include "ChannelMgr.h"
#include "Chat.h"
#include "Config.h"
#include "Player.h"
#include "ScriptMgr.h"
#include "World.h"

std::string wcc_channel_name = "World";
uint32 wcc_channel_id;
uint64 wcc_delay;
uint8 wcc_type;

struct WorldChannelChatElements
{
	uint64 time;
	std::string last_msg;
};

std::unordered_map<uint32, WorldChannelChatElements>WorldChannelChat;

std::string wcc_TeamIcon[2] =
{
	"|TInterface\\icons\\Inv_Misc_Tournaments_banner_Human.png:13|t",
	"|TInterface\\icons\\Inv_Misc_Tournaments_banner_Orc.png:13|t"
};

std::string wcc_GM_ICON = "|TINTERFACE/CHATFRAME/UI-CHATICON-BLIZZ:13:13:0:-1|t";

std::string wcc_GM_RANK[6] =
{
	"Player",
	"GM1",
	"GM2",
	"GM3",
	"Lead GM",
	"Admin",
}; // if you have less/more ranks then -/+ as necessary. edit rank names as necessary.

std::string wcc_ClassIcon[11] =
{
	"|TInterface\\icons\\INV_Sword_27.png:13|t",
	"|TInterface\\icons\\INV_Hammer_01.png:13|t",
	"|TInterface\\icons\\INV_Weapon_Bow_07.png:13|t",
	"|TInterface\\icons\\INV_ThrowingKnife_04.png:13|t",
	"|TInterface\\icons\\INV_Staff_30.png:13|t",
	"|TInterface\\icons\\Spell_Deathknight_ClassIcon.png:13|t",
	"|TInterface\\icons\\inv_jewelry_talisman_04.png:13|t",
	"|TInterface\\icons\\INV_Staff_30.png:13|t",
	"|TInterface\\icons\\INV_Staff_30.png:13|t",
	"",
	"|TInterface\\icons\\Ability_Druid_Maul.png:13|t",
};

std::string wcc_allyblue = "|cff3399FF";
std::string wcc_hordered = "|cffCC0000";
std::string wcc_white = "|cffFFFFFF";
std::string wcc_green = "|cff00cc00";
std::string wcc_red = "|cffFF0000";
std::string wcc_blue = "|cff6666FF";
std::string wcc_black = "|cff000000";
std::string wcc_grey = "|cff808080";

std::string wcc_TeamColor[2] = { wcc_allyblue, wcc_hordered };

class WORLD_CHANNEL_CHAT_Load_Conf : public WorldScript
{
public:
	WORLD_CHANNEL_CHAT_Load_Conf() : WorldScript("WORLD_CHANNEL_CHAT_Load_Conf"){ };

	virtual void OnConfigLoad(bool /*reload*/)
	{
		wcc_channel_id = sConfigMgr->GetIntDefault("WORLDCHANNELCHAT.CHANNEL", 1);
		wcc_delay = sConfigMgr->GetIntDefault("WORLDCHANNELCHAT.DELAY", 5);
		wcc_type = sConfigMgr->GetIntDefault("WORLDCHANNELCHAT.TYPE", 1);
	}
};

void SendWorldChatChannelMessage(std::string msg, uint8 team_id)
{
	SessionMap sessions = sWorld->GetAllSessions();

	for (SessionMap::iterator itr = sessions.begin(); itr != sessions.end(); ++itr)
	{
		if (!itr->second)
			continue;

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

		if (wcc_type == 0 || ((wcc_type == 1) && (player->GetTeamId() == team_id))) 
		{ 
			ChatHandler(player->GetSession()).PSendSysMessage(msg.c_str()); 
		}
	}
}

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

	void OnLogin(Player* player, bool /*firstLogin*/) override
	{
		ChatHandler(player->GetSession()).PSendSysMessage("type `/%u` to access the World Chat channel.", wcc_channel_id);
	}

	virtual void OnChat(Player* player, uint32 /*type*/, uint32 lang, std::string& msg, Channel* channel)
	{
		if (lang != LANG_ADDON)
		{
			uint32 raw_id = channel->GetChannelId();
			uint32 id;

			// channel id's seem to differ than what you see in game so we will convert them here.
			if (raw_id == 1){ id = 1; }
			if (raw_id == 2){ id = 2; }
			if (raw_id == 22){ id = 3; }

			// TC_LOG_INFO("server.loading", "RAW CHANNEL ID:%u", channel->GetChannelId()); // use to identify any channels not allready listed above.

			if (id == wcc_channel_id)
			{
				if ((msg != "") && (msg != "Away") && (player->CanSpeak() == true))
				{
					uint64 current_time = sWorld->GetGameTime();
					uint32 guid = player->GetGUID();

					if (!WorldChannelChat[guid].time)
					{
						WorldChannelChat[guid].time = (current_time - wcc_delay);
						WorldChannelChat[guid].last_msg = "";
					}

					if (player->IsGameMaster()) // here we will set the gm's stored values so they clear the checks.
					{
						WorldChannelChat[guid].time = current_time - wcc_delay;
						WorldChannelChat[guid].last_msg = "";
					}

					if ((current_time - WorldChannelChat[guid].time) < wcc_delay)
					{
						ChatHandler(player->GetSession()).PSendSysMessage("%sSpam timer triggered.", wcc_red);
					}
					else
					{
						if (WorldChannelChat[guid].last_msg == msg)
						{
							ChatHandler(player->GetSession()).PSendSysMessage("%sSpam message detected.", wcc_red);
						}
						else
						{
							// here you can apply different colors
							std::string wcc_channelcolor = wcc_grey;
							std::string wcc_gm_rankcolor = wcc_blue;
							std::string wcc_msgcolor = wcc_green;

							auto gm_rank = player->GetSession()->GetSecurity();
							std::string pName = player->GetName();
							uint8 team_id = player->GetTeamId();

							std::string name = "|Hplayer:" + pName + "|h" + pName;

							std::string WCCMSG = "";

							WCCMSG += "[" + wcc_channelcolor + wcc_channel_name + "|r]";
							WCCMSG += "[" + wcc_TeamIcon[player->GetTeamId()] + "]";

								if (player->IsGameMaster())
								{

									WCCMSG += "[" + wcc_GM_ICON + "]";
									WCCMSG += "[" + wcc_gm_rankcolor + wcc_GM_RANK[gm_rank] + "|r]";
								}

							WCCMSG += "[" + wcc_ClassIcon[player->getClass() - 1] + "]";
							WCCMSG += "[" + wcc_TeamColor[player->GetTeamId()] + name + "|r]";
							WCCMSG += ":" + wcc_msgcolor + msg;

							WorldChannelChat[guid].time = current_time;
							WorldChannelChat[guid].last_msg = msg;

							SendWorldChatChannelMessage(WCCMSG, team_id);
						}
					}
				}
				msg = -1;
			}
		}
	}
};

void AddSC_WorldChannelChat()
{
	new WORLD_CHANNEL_CHAT_Load_Conf;
	new WORLD_CHANNEL_CHAT;
}
[/COLOR]


>> Repo <<

enjoy ;)
 
Last edited:

slp13at420

Mad Scientist
should probably run an ignore list check so people can be ignored in the world chat and not have to worry about being bullied.

Not hard do.


never thought to do something like that ... interesting...


what if I just make it so it only posts to those who are using the channel ?

Or I could make it by default ignore=off at login but then have a command they can then use to ignore the world chat ?
 

yvoms

Exalted Member
nice script i like it ;)

However Line 110 : uint32 raw_id = channel->GetChannelId();

Code:
Error (active)		pointer to incomplete class type is not allowed	scripts	c:\3.3.5\source\src\server\scripts\Custom\world_chat.cpp	110	
Error	C2027	use of undefined type 'Channel'	scripts	C:\3.3.5\source\src\server\scripts\Custom\world_chat.cpp	110	
Error	C2227	left of '->GetChannelId' must point to class/struct/union/generic type	scripts	C:\3.3.5\source\src\server\scripts\Custom\world_chat.cpp	110
 
Top