• 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++] Trying to add gossip to title npc!

Status
Not open for further replies.

Synth

Exalted Member
Hello Emudevs,as title say i'm trying to add gossip to a title npc you can found the thread here:Title npc - Emudevs.

What i try to do?
NEW=COLOR
#include "ScriptPCH.h"

struct Rochet2
{
uint32 menu_id, next_menu_id;
uint8 icon;
std::string name;
uint32 HK, titleID;
};

// {icon, "title name", honored_kills, titleID}
Rochet2 Titles [] =
{
{1, 6, 0, "Honorable Kills Titles", 0, 0 },
{6, 0, 9, "Private", 1, 1 },
{6, 0, 9, "Corporal", 100, 2 },
{6, 0, 9, "Sergeant", 250, 3 },
{6, 0, 9, "Master Sergeant", 500, 4 },
{6, 0, 9, "Sergeant Major", 750, 5 },
{6, 0, 9, "Knight", 1000, 6 },
{6, 0, 9, "Knight-Lieutenant", 1500, 7 },
{6, 0, 9, "Knight-Captain", 2000, 8 },
{6, 0, 9, "Knight-Champion", 2500, 9 },
{6, 0, 9, "Lieutenant Commander", 3000, 10 },
{6, 0, 9, "Commander", 3500, 11 },
{6, 0, 9, "Marshal", 4000, 12 },
{6, 0, 9, "Field Marshal", 4500, 13 },
{6, 0, 9, "Grand Marshal", 5000, 14 },

{1, 7, 0, "Honorable Kills Titles", 0, 0 },
{7, 0, 9, "Scout", 1, 15 },
{7, 0, 9, "Grunt", 100, 16 },
{7, 0, 9, "Sergeant", 250, 17 },
{7, 0, 9, "Senior Sergeant", 500, 18 },
{7, 0, 9, "First Sergeant", 750, 19 },
{7, 0, 9, "Stone Guard", 1000, 20 },
{7, 0, 9, "Blood Guard", 1500, 21 },
{7, 0, 9, "Legionnaire", 2000, 22 },
{7, 0, 9, "Centurion", 2500, 23 },
{7, 0, 9, "Champion", 3000, 24 },
{7, 0, 9, "Lieutenant General", 3500, 25 },
{7, 0, 9, "General", 4000, 26 },
{7, 0, 9, "Warlord", 4500, 27 },
{7, 0, 9, "High Warlord", 5000, 28 },
};
So that what i try to do when i go in-game i can't open the gossip + i get a message if i want to learn the gossip name how i can fix thit problem?

Thank you!
Best regards,
Synth !
 

Tommy

Founder
Well the code could be shown without it being centered. :p

Anyway, I coded this for you:

Screenshots:

ALLIANCE:

84cg.png


HORDE:

zw28.png


Code:
/*
    AYE
    <http://emudevs.com>
    By Tommy
*/

struct HonorGossip
{
    uint32 menu_id;
    uint8 icon;
    std::string name;
    uint32 HK, titleID;
};

// {icon, "title name", honored_kills, titleID}
HonorGossip Titles [] =
{
    {1, 9, "Private", 1, 1 },
    {2, 9, "Corporal", 100, 2 },
    {3, 9, "Sergeant", 250, 3 },
    {4, 9, "Master Sergeant", 500, 4 },
    {5, 9, "Sergeant Major", 750, 5 },
    {6, 9, "Knight", 1000, 6 },
    {7, 9, "Knight-Lieutenant", 1500, 7 },
    {8, 9, "Knight-Captain", 2000, 8 },
    {9, 9, "Knight-Champion", 2500, 9 },
    {10, 9, "Lieutenant Commander", 3000, 10 },
    {11, 9, "Commander", 3500, 11 },
    {12, 9, "Marshal", 4000, 12 },
    {13, 9, "Field Marshal", 4500, 13 },
    {14, 9, "Grand Marshal", 5000, 14 },

    {15, 9, "Scout", 1, 15 },
    {16, 9, "Grunt", 100, 16 },
    {17, 9, "Sergeant", 250, 17 },
    {18, 9, "Senior Sergeant", 500, 18 },
    {19, 9, "First Sergeant", 750, 19 },
    {20, 9, "Stone Guard", 1000, 20 },
    {21, 9, "Blood Guard", 1500, 21 },
    {22, 9, "Legionnaire", 2000, 22 },
    {23, 9, "Centurion", 2500, 23 },
    {24, 9, "Champion", 3000, 24 },
    {25, 9, "Lieutenant General", 3500, 25 },
    {26, 9, "General", 4000, 26 },
    {27, 9, "Warlord", 4500, 27 },
    {28, 9, "High Warlord", 5000, 28 },
};

class npc_honor_gossip : public CreatureScript
{
public:
    npc_honor_gossip() : CreatureScript("npc_honor_gossip") { }

    bool OnGossipHello(Player* player, Creature* creature)
    {
        if (player->GetTeam() == ALLIANCE)
            for (int i = 0; i < 14; i++)
                player->ADD_GOSSIP_ITEM(Titles[i].icon, Titles[i].name.c_str(), GOSSIP_SENDER_MAIN, Titles[i].menu_id);
        else
            for (int i = 14; i < 28; i++)
                player->ADD_GOSSIP_ITEM(Titles[i].icon, Titles[i].name.c_str(), GOSSIP_SENDER_MAIN, Titles[i].menu_id);
        player->SEND_GOSSIP_MENU(1, creature->GetGUID());
        return true;
    }

    bool OnGossipSelect(Player* player, Creature* creature, uint32 /* sender */, uint32 actions)
    {
        player->PlayerTalkClass->ClearMenus();
        for (int i = 0; i < sizeof(Titles) / sizeof(uint32); i++)
            if (actions == Titles[i].menu_id)
                if (!player->HasTitle(Titles[i].titleID) && player->GetUInt32Value(PLAYER_FIELD_LIFETIME_HONORABLE_KILLS) >= Titles[i].HK)
                    if (CharTitlesEntry const* titleEntry = sCharTitlesStore.LookupEntry(Titles[i].titleID))
                        player->SetTitle(titleEntry);
        player->CLOSE_GOSSIP_MENU();
        return true;
    }
};

void AddSC_honor_gossip()
{
    new npc_honor_gossip;
}



Enjoy.
 

Synth

Exalted Member
Well the code could be shown without it being centered. :p
Anyway, I coded this for you:
Enjoy.
Well bro first thanks for the script you maded for me,but the problem i want to create the follow gossips:
●How does this npc work? - It will message you a message about this npc info.
●Titles - It will show whole titles on this gossip,and sure when the player get his team if he is alliance or horde.
●Nevermind - It will close menu.
That what i'm trying to do but it won't work i don't know how i can do it with this struct if you can help me to give me the code for i can fix this problem?
Thank you.
 

Tommy

Founder
Not hard to do at all, but I'd rather do it instead of having you to go through the process. :p


Here you go:

Code:
/*
    AYE
    <http://emudevs.com>
    By Tommy
*/

struct HonorGossip
{
    uint32 menu_id;
    uint8 icon;
    std::string name;
    uint32 HK, titleID;
};

// {icon, "title name", honored_kills, titleID}
HonorGossip Titles [] =
{
    {1, 9, "Private", 1, 1 },
    {2, 9, "Corporal", 100, 2 },
    {3, 9, "Sergeant", 250, 3 },
    {4, 9, "Master Sergeant", 500, 4 },
    {5, 9, "Sergeant Major", 750, 5 },
    {6, 9, "Knight", 1000, 6 },
    {7, 9, "Knight-Lieutenant", 1500, 7 },
    {8, 9, "Knight-Captain", 2000, 8 },
    {9, 9, "Knight-Champion", 2500, 9 },
    {10, 9, "Lieutenant Commander", 3000, 10 },
    {11, 9, "Commander", 3500, 11 },
    {12, 9, "Marshal", 4000, 12 },
    {13, 9, "Field Marshal", 4500, 13 },
    {14, 9, "Grand Marshal", 5000, 14 },

    {15, 9, "Scout", 1, 15 },
    {16, 9, "Grunt", 100, 16 },
    {17, 9, "Sergeant", 250, 17 },
    {18, 9, "Senior Sergeant", 500, 18 },
    {19, 9, "First Sergeant", 750, 19 },
    {20, 9, "Stone Guard", 1000, 20 },
    {21, 9, "Blood Guard", 1500, 21 },
    {22, 9, "Legionnaire", 2000, 22 },
    {23, 9, "Centurion", 2500, 23 },
    {24, 9, "Champion", 3000, 24 },
    {25, 9, "Lieutenant General", 3500, 25 },
    {26, 9, "General", 4000, 26 },
    {27, 9, "Warlord", 4500, 27 },
    {28, 9, "High Warlord", 5000, 28 },
};

class npc_honor_gossip : public CreatureScript
{
public:
    npc_honor_gossip() : CreatureScript("npc_honor_gossip") { }

    bool OnGossipHello(Player* player, Creature* creature)
    {
        player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "How does this NPC work?", GOSSIP_SENDER_MAIN, 100);
        player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "Titles", GOSSIP_SENDER_MAIN, 101);
        player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "Nevermind..", GOSSIP_SENDER_MAIN, 102);
        player->SEND_GOSSIP_MENU(1, creature->GetGUID());
        return true;
    }

    bool OnGossipSelect(Player* player, Creature* creature, uint32 /* sender */, uint32 actions)
    {
        player->PlayerTalkClass->ClearMenus();
        if (actions == 100)
            ChatHandler(player->GetSession()).SendSysMessage("This npc gives you titles, herp, derp..");
        else if(actions == 101)
        {
            if (player->GetTeam() == ALLIANCE)
                for (int i = 0; i < 14; i++)
                    player->ADD_GOSSIP_ITEM(Titles[i].icon, Titles[i].name.c_str(), GOSSIP_SENDER_MAIN, Titles[i].menu_id);
            else
                for (int i = 14; i < 28; i++)
                    player->ADD_GOSSIP_ITEM(Titles[i].icon, Titles[i].name.c_str(), GOSSIP_SENDER_MAIN, Titles[i].menu_id);
            player->SEND_GOSSIP_MENU(1, creature->GetGUID());
        }
        else if (actions == 102)
            player->CLOSE_GOSSIP_MENU();

        for (int i = 0; i < sizeof(Titles) / sizeof(uint32); i++)
            if (actions == Titles[i].menu_id)
                if (!player->HasTitle(Titles[i].titleID) && player->GetUInt32Value(PLAYER_FIELD_LIFETIME_HONORABLE_KILLS) >= Titles[i].HK)
                    if (CharTitlesEntry const* titleEntry = sCharTitlesStore.LookupEntry(Titles[i].titleID))
                    {
                        player->SetTitle(titleEntry);
                        player->CLOSE_GOSSIP_MENU();
                    }
        return true;
    }
};

void AddSC_honor_gossip()
{
    new npc_honor_gossip;
}
 

Synth

Exalted Member
Not hard to do at all, but I'd rather do it instead of having you to go through the process. :p


Here you go:
Thank you it works now,i try to do like that from hours but i was having a problem and now gossips fixed.
But where i can add a check if player has the title will get notification "You already have this title".
If the player don't have enough honorable kills get notification "You don't have enough honorable kills".
And how i can add Back section on "Titles" gossip.
Really this struct make me shit.
Can you show me the code please ?
 
Last edited:

Tommy

Founder
Thank you it works now,i try to do like that from hours but i was having a problem and now gossips fixed.
But where i can add a check if player has the title will get notification "You already have this title".
If the player don't have enough honorable kills get notification "You don't have enough honorable kills".
And how i can add Back section on "Titles" gossip.
Really this struct make me shit.
Can you show me the code please ?

It already does those checks, except it doesn't have error messages.

They have the messages now:

Code:
/*
    AYE
    <http://emudevs.com>
    By Tommy
*/

struct HonorGossip
{
    uint32 menu_id;
    uint8 icon;
    std::string name;
    uint32 HK, titleID;
};

// {icon, "title name", honored_kills, titleID}
HonorGossip Titles [] =
{
    {1, 9, "Private", 1, 1 },
    {2, 9, "Corporal", 100, 2 },
    {3, 9, "Sergeant", 250, 3 },
    {4, 9, "Master Sergeant", 500, 4 },
    {5, 9, "Sergeant Major", 750, 5 },
    {6, 9, "Knight", 1000, 6 },
    {7, 9, "Knight-Lieutenant", 1500, 7 },
    {8, 9, "Knight-Captain", 2000, 8 },
    {9, 9, "Knight-Champion", 2500, 9 },
    {10, 9, "Lieutenant Commander", 3000, 10 },
    {11, 9, "Commander", 3500, 11 },
    {12, 9, "Marshal", 4000, 12 },
    {13, 9, "Field Marshal", 4500, 13 },
    {14, 9, "Grand Marshal", 5000, 14 },

    {15, 9, "Scout", 1, 15 },
    {16, 9, "Grunt", 100, 16 },
    {17, 9, "Sergeant", 250, 17 },
    {18, 9, "Senior Sergeant", 500, 18 },
    {19, 9, "First Sergeant", 750, 19 },
    {20, 9, "Stone Guard", 1000, 20 },
    {21, 9, "Blood Guard", 1500, 21 },
    {22, 9, "Legionnaire", 2000, 22 },
    {23, 9, "Centurion", 2500, 23 },
    {24, 9, "Champion", 3000, 24 },
    {25, 9, "Lieutenant General", 3500, 25 },
    {26, 9, "General", 4000, 26 },
    {27, 9, "Warlord", 4500, 27 },
    {28, 9, "High Warlord", 5000, 28 },
};

class npc_honor_gossip : public CreatureScript
{
public:
    npc_honor_gossip() : CreatureScript("npc_honor_gossip") { }

    bool OnGossipHello(Player* player, Creature* creature)
    {
        player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "How does this NPC work?", GOSSIP_SENDER_MAIN, 100);
        player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "Titles", GOSSIP_SENDER_MAIN, 101);
        player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "Nevermind..", GOSSIP_SENDER_MAIN, 102);
        player->SEND_GOSSIP_MENU(1, creature->GetGUID());
        return true;
    }

    bool OnGossipSelect(Player* player, Creature* creature, uint32 /* sender */, uint32 actions)
    {
        player->PlayerTalkClass->ClearMenus();
        if (actions == 100)
            ChatHandler(player->GetSession()).SendSysMessage("This npc gives you titles, herp, derp..");
        else if(actions == 101)
        {
            if (player->GetTeam() == ALLIANCE)
                for (int i = 0; i < 14; i++)
                    player->ADD_GOSSIP_ITEM(Titles[i].icon, Titles[i].name.c_str(), GOSSIP_SENDER_MAIN, Titles[i].menu_id);
            else
                for (int i = 14; i < 28; i++)
                    player->ADD_GOSSIP_ITEM(Titles[i].icon, Titles[i].name.c_str(), GOSSIP_SENDER_MAIN, Titles[i].menu_id);
            player->SEND_GOSSIP_MENU(1, creature->GetGUID());
        }
        else if (actions == 102)
            player->CLOSE_GOSSIP_MENU();

        for (int i = 0; i < sizeof(Titles) / sizeof(uint32); i++)
        {
            if (actions == Titles[i].menu_id)
            {
                if (player->HasTitle(Titles[i].titleID))
                {
                    player->GetSession()->SendNotification("You already have this title!");
                    return false;
                }
                
                if (player->GetUInt32Value(PLAYER_FIELD_LIFETIME_HONORABLE_KILLS) < Titles[i].HK)
                {
                    player->GetSession()->SendNotification("You don't have enough kills!");
                    return false;
                }
                
                if (CharTitlesEntry const* titleEntry = sCharTitlesStore.LookupEntry(Titles[i].titleID))
                {
                    player->SetTitle(titleEntry);
                    player->CLOSE_GOSSIP_MENU();
                }
            }
        }
        return true;
    }
};

void AddSC_honor_gossip()
{
    new npc_honor_gossip;
}
 

Synth

Exalted Member
It already does those checks, except it doesn't have error messages.

They have the messages now:
Thank you,but "back"section you forget it to add it to code,it should be on "Titles" gossip,idkn how to do add it the gossip on this struct.
 

Tommy

Founder
Thank you,but "back"section you forget it to add it to code,it should be on "Titles" gossip,idkn how to do add it the gossip on this struct.

Well, I'm going to let you handle this, I can't be doing everything because you won't learn how to do it. I'll tell you.

To make a "Back" menu, all you have to do is place:

Code:
player->ADD_GOSSIP_ITEM(GOSSIP_ICON_DOT, "<- Back <-", GOSSIP_SENDER_MAIN, 999);

Inside of "else if (actions == 101)", above THE COLORED CODE:

Code:
        else if(actions == 101)
        {
            if (player->GetTeam() == ALLIANCE)
                for (int i = 0; i < 14; i++)
                    player->ADD_GOSSIP_ITEM(Titles[i].icon, Titles[i].name.c_str(), GOSSIP_SENDER_MAIN, Titles[i].menu_id);
            else
                for (int i = 14; i < 28; i++)
                    player->ADD_GOSSIP_ITEM(Titles[i].icon, Titles[i].name.c_str(), GOSSIP_SENDER_MAIN, Titles[i].menu_id);
            [COLOR=#00ff00]player->SEND_GOSSIP_MENU(1, creature->GetGUID());[/COLOR]
        }

After that, make another "else if" under the last one:

Code:
        else if (actions == 102)
            player->CLOSE_GOSSIP_MENU();
        else if (actions == 999)
        {
        }

And all you have to do in "else if (actions == 999)" is copy / paste the contents from "else if(actions == 101)" and paste it in the "999" if statement.


Honestly, you keep saying that you don't know how to do it because of the "struct"; however, you do it the same exact way when adding new menus that doesn't pertain to the struct. If you had to add a new option inside of the struct, then that would be a different story. :/
 
Last edited:

Synth

Exalted Member
Well, I'm going to let you handle this, I can't be doing everything because you won't learn how to do it. I'll tell you.

To make a "Back" menu, all you have to do is place:

Code:
player->ADD_GOSSIP_ITEM(GOSSIP_ICON_DOT, "<- Back <-", GOSSIP_SENDER_MAIN, 999);

Inside of "else if (actions == 101)", above THE COLORED CODE:

Code:
        else if(actions == 101)
        {
            if (player->GetTeam() == ALLIANCE)
                for (int i = 0; i < 14; i++)
                    player->ADD_GOSSIP_ITEM(Titles[i].icon, Titles[i].name.c_str(), GOSSIP_SENDER_MAIN, Titles[i].menu_id);
            else
                for (int i = 14; i < 28; i++)
                    player->ADD_GOSSIP_ITEM(Titles[i].icon, Titles[i].name.c_str(), GOSSIP_SENDER_MAIN, Titles[i].menu_id);
            [COLOR=#00ff00]player->SEND_GOSSIP_MENU(1, creature->GetGUID());[/COLOR]
        }

After that, make another "else if" under the last one:

Code:
        else if (actions == 102)
            player->CLOSE_GOSSIP_MENU();
        else if (actions == 999)
        {
        }

And all you have to do in "else if (actions == 999)" is copy / paste the contents from "else if(actions == 101)" and paste it in the "999" if statement.


Honestly, you keep saying that you don't know how to do it because of the "struct"; however, you do it the same exact way when adding new menus that doesn't pertain to the struct. If you had to add a new option inside of the struct, then that would be a different story. :/
Oh thank you man so much its solved :)
 
Status
Not open for further replies.
Top