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

[Trinity C++] How to add on World Chat for each class an icon?

Status
Not open for further replies.

Synth

Exalted Member
Greetings Emudevs,That is my first post here and i need a simple help as title say.
So i'm trying to add on world chat script an icon for classes,i'm using this Script,and i want to icon for each class on cases,like here:
case CLASS_WARRIOR:
color = "|cffC79C6E";
break;
And what should be here?
return "|Hplayer:"+name+"|h|cffFFFFFF["+color+name+"|cffFFFFFF]|h|r";
I didn't know how to add the icon on cases but i get it for i add icons on races like if player is an alliance show the icon,and same for horde.
If someone can give me a simple example how i can add it?so i can slove the others i just want it to show like this:
Thank you :)
Best Regards,
Synth !

Sorry for my bad English :S​
 
Last edited:

Darthye

Enthusiast
Code:
#include "ScriptPCH.h"
#include "Channel.h"
#include "Player.h"
#include <sstream>

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

    void OnChat(Player* player, uint32 /*type*/, uint32 lang, std::string& msg, Channel* channel )
    {
        if (!player || !channel)
            return;

        std::stringstream ssMsg;
        ssMsg << ((player->GetBGTeam() == HORDE) ? "|TInterface\\PVPFrame\\PVP-Currency-Horde:18:18:0:-1|t" : "|TInterface\\PVPFrame\\PVP-Currency-Alliance:18:18:0:-1|t") << msg;
        msg = ssMsg.str();
    }
};

void AddSC_channel_factions()
{
    new channel_factions();
}

Alliance or horde icon in chat channels (/1, /2, /3, etc...)

Hope you figure out what you want to do.
 

Synth

Exalted Member
Code:
#include "ScriptPCH.h"
#include "Channel.h"
#include "Player.h"
#include <sstream>

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

    void OnChat(Player* player, uint32 /*type*/, uint32 lang, std::string& msg, Channel* channel )
    {
        if (!player || !channel)
            return;

        std::stringstream ssMsg;
        ssMsg << ((player->GetBGTeam() == HORDE) ? "|TInterface\\PVPFrame\\PVP-Currency-Horde:18:18:0:-1|t" : "|TInterface\\PVPFrame\\PVP-Currency-Alliance:18:18:0:-1|t") << msg;
        msg = ssMsg.str();
    }
};

void AddSC_channel_factions()
{
    new channel_factions();
}

Alliance or horde icon in chat channels (/1, /2, /3, etc...)

Hope you figure out what you want to do.
That is for races and as i said bro i get it how to add it for races.I need to add icons for classes,on the script of world chat i linked in the post,anw thank you for you trying to helping me :)
 
Last edited:

Tommy

Founder
That is for races and as i said bro i get it how to add it for races.I need to add icons for classes,on the script of world chat i linked in the post,anw thank you for you trying to helping me :)

Those are actually the factions, not races. I looked through these interface files and cannot find any icons related to classes. If I skipped something, I surely better notice now because I've been through all of these files. The only icons I found were the race icons, that's it. :/
 

Synth

Exalted Member
Those are actually the factions, not races. I looked through these interface files and cannot find any icons related to classes. If I skipped something, I surely better notice now because I've been through all of these files. The only icons I found were the race icons, that's it. :/
Well i just updated with classes icons check it out World Chat with icons for classes ! but i still have problem i didn't get this result,Image,i think the problem here:
return "|Hplayer:"+name+"|h|cffFFFFFF["+color+name+"|cffFFFFFF]|h|r";
May someone tell me how i can fix it for i get the result on the image bellow,race icon then class icon?
Thank you.
 

Tommy

Founder
Sorry,that is the result i Get.I want the race icon show near the class icon.

Replace the ALLIANCE/HORDE icon with the player race icon. :/

I saw the race icons earlier today, but now I cannot find THEM so I can give you the names... >.>
 

Synth

Exalted Member
Replace the ALLIANCE/HORDE icon with the player race icon. :/

I saw the race icons earlier today, but now I cannot find THEM so I can give you the names... >.>
Well i didn't understand actually what i should do,but look this about race icons:
if (player->GetTeam() == ALLIANCE)
{
msg += "|cff00ff00[World]";
msg += " |cff0000ff|TInterface\\icons\\Achievement_PVP_A_A:15|t|r";
msg += GetNameLink(player);
msg += ":|cfffaeb00";
}

else
{
msg += "|cff00ff00[World] ";
msg += " |cffff0000|TInterface\\icons\\Achievement_PVP_A_H:15|t|r";
msg += GetNameLink(player);
msg += ":|cfffaeb00";
}
break;
The race icons are working perfectly but the problem class icon,the class icon are working but there is a bug in check last line about image.
Example Human Female Priest:
Code:
case CLASS_PRIEST:
color = "|cffFFFFFF";
CLASS_ICON = "|TInterface\\icons\\INV_Staff_30:15|t|r";
break;
On world chat when i try to talk i tell you what i get Result.I edit here this:
return "|Hplayer:"+name+"|h"+CLASS_ICON+"|cffFFFFFF["+color+name+"|cffFFFFFF]|h|r";
When i go in-game and i wrtie .world <message> i get the result i need but the problem now when you click on name you can't whisper or something you have to click on the icon for you can whisper a player,invite,ignore,cancel can you tell me how i can fix it for name?
Result of this bug:
Result
Thank you :)
 

Tommy

Founder
It should work considering the name link is correct and it is similar to the "playerLink" function in Chat.h, minus the icons of course..
ZFmbXqy.png
 

Synth

Exalted Member
It should work considering the name link is correct and it is similar to the "playerLink" function in Chat.h, minus the icons of course..
ZFmbXqy.png
Well it was working when i didn't edit something without icon ofc,but when i edit the colored one it work the icon but "Playerlink" fucked.
return "|Hplayer:"+name+"|h"+CLASS_ICON+"|cffFFFFFF["+color+name+"|cffFFFFFF]|h|r";
So the problem i think there,anw you can check the whole script Here.
If you find the problem updated for me on new link please,thank you.
 

Tommy

Founder
Also, you don't need to have 4 commands for 4 different types of wording. It does that automatically..

I updated your code:

Code:
#include "Chat.h"
const char* CLASS_ICON;

#define FACTION_SPECIFIC 0

std::string GetNameLink(Player* player)
{
    std::string name = player->GetName();
    std::string color;
    switch(player->getClass()) 
    {
    case CLASS_DEATH_KNIGHT:
        color = "|cffC41F3B";
        CLASS_ICON = "|TInterface\\icons\\Spell_Deathknight_ClassIcon:15|t|r";
        break;
    case CLASS_DRUID:
        color = "|cffFF7D0A";
        CLASS_ICON = "|TInterface\\icons\\Ability_Druid_Maul:15|t|r";
        break;
    case CLASS_HUNTER:
        color = "|cffABD473";
        CLASS_ICON = "|TInterface\\icons\\INV_Weapon_Bow_07:15|t|r";
        break;
    case CLASS_MAGE:
        color = "|cff69CCF0";
        CLASS_ICON = "|TInterface\\icons\\INV_Staff_13:15|t|r";
        break;
    case CLASS_PALADIN:
        color = "|cffF58CBA";
        CLASS_ICON = "|TInterface\\icons\\INV_Hammer_01:15|t|r";
        break;
    case CLASS_PRIEST:
        color = "|cffFFFFFF";
        CLASS_ICON = "|TInterface\\icons\\INV_Staff_30:15|t|r";
        break;
    case CLASS_ROGUE:
        color = "|cffFFF569";
        CLASS_ICON = "|TInterface\\icons\\INV_ThrowingKnife_04:15|t|r";
        break;
    case CLASS_SHAMAN:
        color = "|cff0070DE";
        CLASS_ICON = "|TInterface\\icons\\Spell_Nature_BloodLust:15|t|r";
        break;
    case CLASS_WARLOCK:
        color = "|cff9482C9";
        CLASS_ICON = "|TInterface\\icons\\Spell_Nature_FaerieFire:15|t|r";
        break;
    case CLASS_WARRIOR:
        color = "|cffC79C6E";
        CLASS_ICON = "|TInterface\\icons\\INV_Weapon_Bow_07:15|t|r";
        break;
    }
    return "|Hplayer:"+name+"|h"+CLASS_ICON+"|cffFFFFFF["+color+name+"|cffFFFFFF]|h|r";
}

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

    ChatCommand * GetCommands() const
    {
        static ChatCommand WorldChatCommandTable[] = 
        {
            {"chat",    SEC_PLAYER,        true,        &HandleWorldChatCommand,    "", NULL},
            {NULL,        0,                false,        NULL,                        "", NULL}
        };

        return WorldChatCommandTable;
    }

    static bool HandleWorldChatCommand(ChatHandler * handler, const char * args)
    {
        if (!handler->GetSession()->GetPlayer()->CanSpeak())
            return false;
        std::string temp = args;

        if (!args || temp.find_first_not_of(' ') == std::string::npos)
            return false;

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

        switch(player->GetSession()->GetSecurity())
        {
            // Player
        case SEC_PLAYER:
                if (player->GetTeam() == ALLIANCE)
                {
                    msg += "|cff00ff00[World]";
                    msg += " |cff0000ff|TInterface\\icons\\Achievement_PVP_A_A:15|t|r";
                    msg += GetNameLink(player);
                    msg += ":|cfffaeb00";
                }

                else
                {
                    msg += "|cff00ff00[World] ";
                    msg += " |cffff0000|TInterface\\icons\\Achievement_PVP_A_H:15|t|r";
                    msg += GetNameLink(player);
                    msg += ":|cfffaeb00";
                }
                break;
            // Moderator/trial 
            case SEC_MODERATOR:
                msg += "|cffff8a00[Mod] ";
                msg += GetNameLink(player);
                msg += " |cfffaeb00";
                break;
            // GM
            case SEC_GAMEMASTER:
                msg += "|cff00ffff[GM] ";
                msg += GetNameLink(player);
                msg += " |cfffaeb00";
                break;
            // Admin
            case SEC_ADMINISTRATOR:
                msg += "|cfffa9900[Admin] ";
                msg += GetNameLink(player);
                msg += " |cfffaeb00";
                break;

        }
            
        msg += args;
        if (FACTION_SPECIFIC)
        {
            SessionMap sessions = sWorld->GetAllSessions();
            for (SessionMap::iterator itr = sessions.begin(); itr != sessions.end(); ++itr)
                if (Player* plr = itr->second->GetPlayer())
                    if (plr->GetTeam() == player->GetTeam())
                        sWorld->SendServerMessage(SERVER_MSG_STRING, msg.c_str(), plr);
        }
        else
            sWorld->SendServerMessage(SERVER_MSG_STRING, msg.c_str(), 0);    

        return true;
    }
};

void AddSC_cs_world_chat()
{
    new cs_world_chat();
}

Perhaps the CLASS icon needs to be moved in front of the name link considering it is interfering with the name itself, that's why you can check the class icon to show whisper, etc..
 

Synth

Exalted Member
Also, you don't need to have 4 commands for 4 different types of wording. It does that automatically..

I updated your code:

Code:
#include "Chat.h"
const char* CLASS_ICON;

#define FACTION_SPECIFIC 0

std::string GetNameLink(Player* player)
{
    std::string name = player->GetName();
    std::string color;
    switch(player->getClass()) 
    {
    case CLASS_DEATH_KNIGHT:
        color = "|cffC41F3B";
        CLASS_ICON = "|TInterface\\icons\\Spell_Deathknight_ClassIcon:15|t|r";
        break;
    case CLASS_DRUID:
        color = "|cffFF7D0A";
        CLASS_ICON = "|TInterface\\icons\\Ability_Druid_Maul:15|t|r";
        break;
    case CLASS_HUNTER:
        color = "|cffABD473";
        CLASS_ICON = "|TInterface\\icons\\INV_Weapon_Bow_07:15|t|r";
        break;
    case CLASS_MAGE:
        color = "|cff69CCF0";
        CLASS_ICON = "|TInterface\\icons\\INV_Staff_13:15|t|r";
        break;
    case CLASS_PALADIN:
        color = "|cffF58CBA";
        CLASS_ICON = "|TInterface\\icons\\INV_Hammer_01:15|t|r";
        break;
    case CLASS_PRIEST:
        color = "|cffFFFFFF";
        CLASS_ICON = "|TInterface\\icons\\INV_Staff_30:15|t|r";
        break;
    case CLASS_ROGUE:
        color = "|cffFFF569";
        CLASS_ICON = "|TInterface\\icons\\INV_ThrowingKnife_04:15|t|r";
        break;
    case CLASS_SHAMAN:
        color = "|cff0070DE";
        CLASS_ICON = "|TInterface\\icons\\Spell_Nature_BloodLust:15|t|r";
        break;
    case CLASS_WARLOCK:
        color = "|cff9482C9";
        CLASS_ICON = "|TInterface\\icons\\Spell_Nature_FaerieFire:15|t|r";
        break;
    case CLASS_WARRIOR:
        color = "|cffC79C6E";
        CLASS_ICON = "|TInterface\\icons\\INV_Weapon_Bow_07:15|t|r";
        break;
    }
    return "|Hplayer:"+name+"|h"+CLASS_ICON+"|cffFFFFFF["+color+name+"|cffFFFFFF]|h|r";
}

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

    ChatCommand * GetCommands() const
    {
        static ChatCommand WorldChatCommandTable[] = 
        {
            {"chat",    SEC_PLAYER,        true,        &HandleWorldChatCommand,    "", NULL},
            {NULL,        0,                false,        NULL,                        "", NULL}
        };

        return WorldChatCommandTable;
    }

    static bool HandleWorldChatCommand(ChatHandler * handler, const char * args)
    {
        if (!handler->GetSession()->GetPlayer()->CanSpeak())
            return false;
        std::string temp = args;

        if (!args || temp.find_first_not_of(' ') == std::string::npos)
            return false;

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

        switch(player->GetSession()->GetSecurity())
        {
            // Player
        case SEC_PLAYER:
                if (player->GetTeam() == ALLIANCE)
                {
                    msg += "|cff00ff00[World]";
                    msg += " |cff0000ff|TInterface\\icons\\Achievement_PVP_A_A:15|t|r";
                    msg += GetNameLink(player);
                    msg += ":|cfffaeb00";
                }

                else
                {
                    msg += "|cff00ff00[World] ";
                    msg += " |cffff0000|TInterface\\icons\\Achievement_PVP_A_H:15|t|r";
                    msg += GetNameLink(player);
                    msg += ":|cfffaeb00";
                }
                break;
            // Moderator/trial 
            case SEC_MODERATOR:
                msg += "|cffff8a00[Mod] ";
                msg += GetNameLink(player);
                msg += " |cfffaeb00";
                break;
            // GM
            case SEC_GAMEMASTER:
                msg += "|cff00ffff[GM] ";
                msg += GetNameLink(player);
                msg += " |cfffaeb00";
                break;
            // Admin
            case SEC_ADMINISTRATOR:
                msg += "|cfffa9900[Admin] ";
                msg += GetNameLink(player);
                msg += " |cfffaeb00";
                break;

        }
            
        msg += args;
        if (FACTION_SPECIFIC)
        {
            SessionMap sessions = sWorld->GetAllSessions();
            for (SessionMap::iterator itr = sessions.begin(); itr != sessions.end(); ++itr)
                if (Player* plr = itr->second->GetPlayer())
                    if (plr->GetTeam() == player->GetTeam())
                        sWorld->SendServerMessage(SERVER_MSG_STRING, msg.c_str(), plr);
        }
        else
            sWorld->SendServerMessage(SERVER_MSG_STRING, msg.c_str(), 0);    

        return true;
    }
};

void AddSC_cs_world_chat()
{
    new cs_world_chat();
}

Perhaps the CLASS icon needs to be moved in front of the name link considering it is interfering with the name itself, that's why you can check the class icon to show whisper, etc..
Thank you dude its working now :)
 
Status
Not open for further replies.
Top