• 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 World Chat script

slp13at420

Mad Scientist
Just a simple operated world chat script. that includes :
faction icons,
class icons,
faction colored names,
interactable player names,
if GM then it adds GM Badge, and GM rank.

This doesn't require you to add anything to your Rbac. It does it automatically.

Just add to your core and compile :D
for instructions on how-to add a script -> http://emudevs.com/showthread.php/13-Adding-a-C-script-to-your-core

Updated 2-21-2016 to the latest rev.

WorldChat.cpp
Code:
[COLOR="#808080"]
/*
a simple chat system with an adjustable prefix. default`.chat`.
with adjustable color layout and adjustable channel name.
made by slp13at420 of EmuDevs.com
*/
#include "Chat.h"
#include "Player.h"
#include "ScriptMgr.h"
#include "World.h"

std::string wc1_world_chat_command = "chat";
std::string wc1_channel_name = "World";

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

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

std::string wc1_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 wc1_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 wc1_allyblue = "|cff3399FF";
std::string wc1_hordered = "|cffCC0000";
std::string wc1_white = "|cffFFFFFF";
std::string wc1_green = "|cff00cc00";
std::string wc1_red = "|cffFF0000";
std::string wc1_blue = "|cff6666FF";
std::string wc1_black = "|cff000000";
std::string wc1_grey = "|cff808080";

std::string wc1_TeamColor[2] = { wc1_allyblue, wc1_hordered };

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

	void OnLogin(Player* player, bool /*firstLogin*/) override
	{
		ChatHandler(player->GetSession()).PSendSysMessage("type `.%s` for World Chat commands.", wc1_world_chat_command.c_str());
	}
};

class WORLD_CHAT : public CommandScript
{
public:
	WORLD_CHAT() : CommandScript("WORLD_CHAT") { }

	std::vector<ChatCommand> GetCommands() const
	{
		static std::vector<ChatCommand> commandTable =
		{
			{ wc1_world_chat_command.c_str(), rbac::RBAC_IN_GRANTED_LIST, true, &HandleWorldChatCommand, "World Chat prefix. `.chat hello world`" },
		};
		return commandTable;
	}

	static bool HandleWorldChatCommand(ChatHandler* handler, const char* msg)
	{
		// here you can apply different colors
		std::string wc1_channelcolor = wc1_grey;
		std::string wc1_gm_rankcolor = wc1_blue;
		std::string wc1_msgcolor = wc1_green;

		WorldSession* session = handler->GetSession();
		Player* player = session->GetPlayer();
		auto gm_rank = session->GetSecurity();
		std::string pName = player->GetName();

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

		std::string WCMSG = "";

		WCMSG = "[" + wc1_channelcolor + wc1_channel_name + "|r]";
		WCMSG = WCMSG + "[" + wc1_TeamIcon[player->GetTeamId()] + "]";

		if (player->IsGameMaster())
		{

			WCMSG = WCMSG + "[" + wc1_GM_ICON + "]";
			WCMSG = WCMSG + "[" + wc1_gm_rankcolor + wc1_GM_RANK[gm_rank] + "|r]";
		}

		WCMSG = WCMSG + "[" + wc1_ClassIcon[player->getClass() - 1] + "]";
		WCMSG = WCMSG + "[" + wc1_TeamColor[player->GetTeamId()] + name + "|r]";
		WCMSG = WCMSG + ":" + wc1_msgcolor + msg;

		sWorld->SendGlobalText(WCMSG.c_str(), NULL);

		return true;
	}
};

void AddSC_WorldChat()
{
	new Player_WorldChat;
	new WORLD_CHAT;
}
[/COLOR]

Horde player:
QPKLzMl.jpg


Alliance active GM:
6ab8f8h.jpg


HuIBUav.jpg


htt4kdt.jpg
 
Last edited:

slp13at420

Mad Scientist
so now you can define the colors to your liking then apply the colors you want to use

- - - Updated - - -

so now you can define the colors to your liking then apply the colors you want to use in `HandleWorldChatCommand` for channel color, rank color and message color.

HuIBUav.jpg


htt4kdt.jpg
 
Last edited:

Noones

Enthusiast
Hello,

i tried to compile this script and got errors involving ScriptPCH.h

In this thread: http://emudevs.com/showthread.php/5425-Trinitycore-Error-when-compiling-Worldchat?p=36688#post36688 Tommy helped me and posted a updated and cleaned up version of your script, which is working with the newest core.

Code:
/*
a simple chat system with an adjustable prefix. default`.chat`.
with adjustable color layout and adjustable channel name.
made by slp13at420 of EmuDevs.com
*/
#include "Chat.h"
#include "Player.h"

std::string wc1_world_chat_command = "chat";
std::string wc1_channel_name = "World";

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

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

std::string wc1_GM_RANK[4] =
{
    "Player",
    "GM1",
    "GM2",
    "GM3",
};

std::string wc1_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 wc1_allyblue = "|cff3399FF";
std::string wc1_hordered = "|cffCC0000";
std::string wc1_white = "|cffFFFFFF";
std::string wc1_green = "|cff00cc00";
std::string wc1_red = "|cffFF0000";
std::string wc1_blue = "|cff6666FF";
std::string wc1_black = "|cff000000";
std::string wc1_grey = "|cff808080";

std::string wc1_TeamColor[2] = { wc1_allyblue, wc1_hordered };

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

    void OnLogin(Player* player, bool /*firstLogin*/) override
    {
        ChatHandler(player->GetSession()).PSendSysMessage("type `.%s` for World Chat commands.", wc1_world_chat_command.c_str());
    }
};

class WORLD_CHAT : public CommandScript

{
public:
    WORLD_CHAT() : CommandScript("WORLD_CHAT") { }

    std::vector<ChatCommand> GetCommands() const override
    {
        static std::vector<ChatCommand> commandTable =
        {
            { wc1_world_chat_command.c_str(), 1, false, &HandleWorldChatCommand, "World Chat prefix." },
        };

	return commandTable;
    }

    static bool HandleWorldChatCommand(ChatHandler* handler, const char* msg)
    {
        // here you can apply different colors
        std::string wc1_channelcolor = wc1_grey;
        std::string wc1_gm_rankcolor = wc1_blue;
        std::string wc1_msgcolor = wc1_green;

        WorldSession* session = handler->GetSession();
        Player* player = session->GetPlayer();
        std::string WCMSG = "";

        WCMSG = "[" + wc1_channelcolor + wc1_channel_name + "|r]";
        WCMSG = WCMSG + "[" + wc1_TeamIcon[player->GetTeamId()] + "]";

        if (player->IsGameMaster())
        {
            WCMSG = WCMSG + "[" + wc1_GM_ICON + "]";
            WCMSG = WCMSG + "[" + wc1_gm_rankcolor + wc1_GM_RANK[session->GetSecurity()] + "|r]";
        }

        WCMSG = WCMSG + "[" + wc1_ClassIcon[player->getClass() - 1] + "]";
        WCMSG = WCMSG + "[" + wc1_TeamColor[player->GetTeamId()] + player->GetName() + "|r]";
        WCMSG = WCMSG + ":" + wc1_msgcolor + msg;

        sWorld->SendGlobalText(WCMSG.c_str(), NULL);

        return true;
    }
};

void AddSC_WorldChat()
{
    new Player_WorldChat;
}
 

slp13at420

Mad Scientist
ok tested and its working:
Code:
[COLOR="#808080"]
/*
a simple chat system with an adjustable prefix. default`.chat`.
with adjustable color layout and adjustable channel name.
made by slp13at420 of EmuDevs.com
*/
#include "Chat.h"
#include "Player.h"
[COLOR="#FFD700"]#include "ScriptMgr.h"[/COLOR]

std::string wc1_world_chat_command = "chat";
std::string wc1_channel_name = "World";

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

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

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

std::string wc1_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 wc1_allyblue = "|cff3399FF";
std::string wc1_hordered = "|cffCC0000";
std::string wc1_white = "|cffFFFFFF";
std::string wc1_green = "|cff00cc00";
std::string wc1_red = "|cffFF0000";
std::string wc1_blue = "|cff6666FF";
std::string wc1_black = "|cff000000";
std::string wc1_grey = "|cff808080";

std::string wc1_TeamColor[2] = { wc1_allyblue, wc1_hordered };

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

	void OnLogin(Player* player, bool /*firstLogin*/) override
	{
		ChatHandler(player->GetSession()).PSendSysMessage("type `.%s` for World Chat commands.", wc1_world_chat_command.c_str());
	}
};

class WORLD_CHAT : public CommandScript
{
public:
	WORLD_CHAT() : CommandScript("WORLD_CHAT") { }

	std::vector<ChatCommand> GetCommands() const
	{
		static std::vector<ChatCommand> commandTable =
		{
			[COLOR="#FFD700"]{ wc1_world_chat_command.c_str(), rbac::RBAC_IN_GRANTED_LIST, true, &HandleWorldChatCommand, "World Chat prefix. `.chat hello world`" },[/COLOR]
		};
		return commandTable;
	}

	static bool HandleWorldChatCommand(ChatHandler* handler, const char* msg)
	{
		// here you can apply different colors
		std::string wc1_channelcolor = wc1_grey;
		std::string wc1_gm_rankcolor = wc1_blue;
		std::string wc1_msgcolor = wc1_green;

		WorldSession* session = handler->GetSession();
		Player* player = session->GetPlayer();
		auto gm_rank = session->GetSecurity();

		std::string WCMSG = "";

		WCMSG = "[" + wc1_channelcolor + wc1_channel_name + "|r]";
		WCMSG = WCMSG + "[" + wc1_TeamIcon[player->GetTeamId()] + "]";

		if (player->IsGameMaster())
		{

			WCMSG = WCMSG + "[" + wc1_GM_ICON + "]";
			WCMSG = WCMSG + "[" + wc1_gm_rankcolor + wc1_GM_RANK[gm_rank] + "|r]";
		}

		WCMSG = WCMSG + "[" + wc1_ClassIcon[player->getClass() - 1] + "]";
		WCMSG = WCMSG + "[" + wc1_TeamColor[player->GetTeamId()] + player->GetName() + "|r]";
		WCMSG = WCMSG + ":" + wc1_msgcolor + msg;

		sWorld->SendGlobalText(WCMSG.c_str(), NULL);

		return true;
	}
};

void AddSC_WorldChat()
{
	new Player_WorldChat;
[COLOR="#FFD700"]	new WORLD_CHAT;[/COLOR]
}
[/COLOR]

highlighted the 2 changes.

just copy this whole script since I did a little tweaking with it.

you don't need to add anything to your sql rbac. this will add the command itself.

I also updated the main post with this :D.
 
Last edited:

slp13at420

Mad Scientist
did a little tweaking to it today and now player names are interactable.
Now names can be clicked to whisper,target,...

updated main post with this :D
 
Top