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

[SOLVED] BossAnnouncer

Status
Not open for further replies.

Blaze

Enthusiast
Hello there, I have downloaded a script that announces when a boss inside the world gets killed. My question is : how do I add the guild leader's name and the difficulty of the instance and make it look like this?

[Boss Announcer] The guild lead by "Guild leader's name" and his group killed world boss "Name of the boss" in 10 man Heroic difficulty!

This is the script : http://pastebin.com/e4SEx4ge

Thanks in advance :)
 

Tommy

Founder
I'm not sure if there's a more simple way in doing this, but you can do it like this:

(Note: I took out that nasty snprintf and put in ostringstream instead)

Code:
#include "InstanceScript.h"
#include "Guild.h"

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

    void OnCreatureKill(Player* player, Creature* boss)
    {
        if (boss->isWorldBoss())
        {
            std::string guildLeaderName = "";
            if (player->GetGuild())
            {
                Player* guildLeader = sObjectAccessor->FindPlayer(player->GetGuild()->GetLeaderGUID());
                if (!guildLeader)
                    guildLeaderName = "Unknown";

                guildLeaderName = guildLeader->GetName();
         }

            std::ostringstream ss;
            if (guildLeaderName != "Unknown")
            {
                ss << "|CFF7BBEF7[Boss Announcer]|r:|cffff0000 The guild lead by"
                    << guildLeaderName
                    << "|r and his group killed world boss |CFF18BE00["
                    << boss->GetName()
                    << "]|r.";
            }
            else
            {
                ss << "|CFF7BBEF7[Boss Announcer]|r:|cffff0000"
                    << player->GetName()
                    << "|r and his group killed world boss |CFF18BE00["
                    << boss->GetName()
                    << "]|r.";
            }
            sWorld->SendServerMessage(SERVER_MSG_STRING, ss.str().c_str());
        }
    }
};


void AddSC_boss_announcer()
{
	new Boss_Announcer();
}
 

Jameyboor

Retired Staff
I'm not sure if there's a more simple way in doing this, but you can do it like this:

(Note: I took out that nasty snprintf and put in ostringstream instead)

Code:
#include "InstanceScript.h"
#include "Guild.h"

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

    void OnCreatureKill(Player* player, Creature* boss)
    {
        if (boss->isWorldBoss())
        {
            std::string guildLeaderName = "";
            if (player->GetGuild())
            {
                Player* guildLeader = sObjectAccessor->FindPlayer(player->GetGuild()->GetLeaderGUID());
                if (!guildLeader)
                    guildLeaderName = "Unknown";

                guildLeaderName = guildLeader->GetName();
         }

            std::ostringstream ss;
            if (guildLeaderName != "Unknown")
            {
                ss << "|CFF7BBEF7[Boss Announcer]|r:|cffff0000 The guild lead by"
                    << guildLeaderName
                    << "|r and his group killed world boss |CFF18BE00["
                    << boss->GetName()
                    << "]|r.";
            }
            else
            {
                ss << "|CFF7BBEF7[Boss Announcer]|r:|cffff0000"
                    << player->GetName()
                    << "|r and his group killed world boss |CFF18BE00["
                    << boss->GetName()
                    << "]|r.";
            }
            sWorld->SendServerMessage(SERVER_MSG_STRING, ss.str().c_str());
        }
    }
};


void AddSC_boss_announcer()
{
	new Boss_Announcer();
}

Using queries to get the name of the leader would be better I suppose since FindPlayer only returns something if the player is online, and I don't think the leader is always online :3
 

Tommy

Founder
Using queries to get the name of the leader would be better I suppose since FindPlayer only returns something if the player is online, and I don't think the leader is always online :3

That's why I wrote the other part if the leader isn't online. :p
 

Blaze

Enthusiast
I'm not sure if there's a more simple way in doing this, but you can do it like this:

(Note: I took out that nasty snprintf and put in ostringstream instead)

Code:
#include "InstanceScript.h"
#include "Guild.h"

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

    void OnCreatureKill(Player* player, Creature* boss)
    {
        if (boss->isWorldBoss())
        {
            std::string guildLeaderName = "";
            if (player->GetGuild())
            {
                Player* guildLeader = sObjectAccessor->FindPlayer(player->GetGuild()->GetLeaderGUID());
                if (!guildLeader)
                    guildLeaderName = "Unknown";

                guildLeaderName = guildLeader->GetName();
         }

            std::ostringstream ss;
            if (guildLeaderName != "Unknown")
            {
                ss << "|CFF7BBEF7[Boss Announcer]|r:|cffff0000 The guild lead by"
                    << guildLeaderName
                    << "|r and his group killed world boss |CFF18BE00["
                    << boss->GetName()
                    << "]|r.";
            }
            else
            {
                ss << "|CFF7BBEF7[Boss Announcer]|r:|cffff0000"
                    << player->GetName()
                    << "|r and his group killed world boss |CFF18BE00["
                    << boss->GetName()
                    << "]|r.";
            }
            sWorld->SendServerMessage(SERVER_MSG_STRING, ss.str().c_str());
        }
    }
};


void AddSC_boss_announcer()
{
	new Boss_Announcer();
}

Amazing as always, Tommy! Thank you very much. There's only a little problem with it: even if I' not in a Guild, it displays the same message. It says this : The guild lead by and his group killed world boss "Boss name" when , in your script, it should say : "Playername" and his group killed worldboss "Boss name". I don't get what's wrong with the check you made tho, it seems to be fine
 

Tommy

Founder
It's probably because I forgot to set the guildLeaderName to Unknown if you aren't in a guild.

This should fix it:

Code:
#include "InstanceScript.h"
#include "Guild.h"

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

    void OnCreatureKill(Player* player, Creature* boss)
    {
        if (boss->isWorldBoss())
        {
            std::string guildLeaderName = "";
            if (player->GetGuild())
            {
                Player* guildLeader = sObjectAccessor->FindPlayer(player->GetGuild()->GetLeaderGUID());
                if (!guildLeader)
                    guildLeaderName = "Unknown";

                guildLeaderName = guildLeader->GetName();
            }
            else
                guildLeaderName = "Unknown";

            std::ostringstream ss;
            if (guildLeaderName != "Unknown")
            {
                ss << "|CFF7BBEF7[Boss Announcer]|r:|cffff0000 The guild lead by"
                    << guildLeaderName
                    << "|r and his group killed world boss |CFF18BE00["
                    << boss->GetName()
                    << "]|r.";
            }
            else
            {
                ss << "|CFF7BBEF7[Boss Announcer]|r:|cffff0000"
                    << player->GetName()
                    << "|r and his group killed world boss |CFF18BE00["
                    << boss->GetName()
                    << "]|r.";
            }
            sWorld->SendServerMessage(SERVER_MSG_STRING, ss.str().c_str());
        }
    }
};


void AddSC_boss_announcer()
{
	new Boss_Announcer();
}
 

Blaze

Enthusiast
It's probably because I forgot to set the guildLeaderName to Unknown if you aren't in a guild.

This should fix it:

Code:
#include "InstanceScript.h"
#include "Guild.h"

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

    void OnCreatureKill(Player* player, Creature* boss)
    {
        if (boss->isWorldBoss())
        {
            std::string guildLeaderName = "";
            if (player->GetGuild())
            {
                Player* guildLeader = sObjectAccessor->FindPlayer(player->GetGuild()->GetLeaderGUID());
                if (!guildLeader)
                    guildLeaderName = "Unknown";

                guildLeaderName = guildLeader->GetName();
            }
            else
                guildLeaderName = "Unknown";

            std::ostringstream ss;
            if (guildLeaderName != "Unknown")
            {
                ss << "|CFF7BBEF7[Boss Announcer]|r:|cffff0000 The guild lead by"
                    << guildLeaderName
                    << "|r and his group killed world boss |CFF18BE00["
                    << boss->GetName()
                    << "]|r.";
            }
            else
            {
                ss << "|CFF7BBEF7[Boss Announcer]|r:|cffff0000"
                    << player->GetName()
                    << "|r and his group killed world boss |CFF18BE00["
                    << boss->GetName()
                    << "]|r.";
            }
            sWorld->SendServerMessage(SERVER_MSG_STRING, ss.str().c_str());
        }
    }
};


void AddSC_boss_announcer()
{
	new Boss_Announcer();
}
It's working, thank you so much, Tommy! :) What about the difficulty mode? Any ideas?
 
Last edited:

Blaze

Enthusiast
What do you mean?

I'd like to make it announce this : "[Boss Announcer] The guild lead by "Guild leader's name" and his group killed world boss "Name of the boss" in 10 man Heroic difficulty!" with the Difficulty mode of the raid. Is it possible?
 

Jameyboor

Retired Staff
you can use :
Code:
player->GetDifficulty(player->GetGroup()->isRaidGroup());

return values are :
8mI3E.png
 

Blaze

Enthusiast
you can use :
Code:
player->GetDifficulty(player->GetGroup()->isRaidGroup());

return values are :
8mI3E.png

Thank you, that's what I was looking for. I thought it could have been done by GetDifficulty().

This thread can be marked as solved :)
 
Last edited:
Status
Not open for further replies.
Top