Forums WoW Modding Tutorials Miscellaneous [Archive] [3.3.5] Gossip NPC Tutorial

[Archive] [3.3.5] Gossip NPC Tutorial

[Archive] [3.3.5] Gossip NPC Tutorial

rektbyfaith
Administrator
0
11-04-2025, 05:04 PM
#1
Archived author: dokuro • Posted: 2025-11-04T18:04:38.594558
Original source

In this tutorial we will see how to simply create a GOSSIP NPC in C ++.

The library
Quote: #include "ScriptMgr.h"

#include "ScriptedGossip.h"

Click to expand...
We must not forget the ScriptedGossip.h library, available in the sources, src \ server \ game \ AI \ ScriptedAI \.

There are various useful functions:

AddGossipItemFor

SendGossipMenuFor

CloseGossipMenuFor

Creation

We start by creating the structure of our script (class, type, name, etc.).
Quote: class GossipTutroial : public CreatureScript

{

public:

GossipTutroial() : CreatureScript("GossipTutroial") { }

struct MyAI : public ScriptedAI

{

MyAI(Creature* m_creature) : ScriptedAI(m_creature) { }

bool GossipHello(Player* player) override

{

return OnGossipHello(player, me);

}

bool GossipSelect(Player* player, uint32 menuId, uint32 gossipListId) override

{

uint32 action = player->PlayerTalkClass->GetGossipOptionAction(gossipListId);

return OnGossipSelect(player, me, action);

}

};

CreatureAI* GetAI(Creature* creature) const override

{

return new MyAI(creature);

}

};

Click to expand...
We then create our first function, the one we will see when talking to the PNJ.

We are going to use the following two functions, which we can find in the ScriptedGossip.h file:
Quote: AddGossipItemFor(Player* player, uint32 icon, std:Confusedtring const& text, uint32 sender, uint32 action)

SendGossipMenuFor(Player* player, uint32 npcTextID, ObjectGuid const& guid)

static bool OnGossipHello(Player * player, Creature * creature)

{

AddGossipItemFor(player,GOSSIP_ICON_CHAT, "Hello World", GOSSIP_SENDER_MAIN, 1);

AddGossipItemFor(player,GOSSIP_ICON_BATTLE, "Good Bye", GOSSIP_SENDER_MAIN, 2);

SendGossipMenuFor(player, player->GetGossipTextId(creature), creature->GetGUID());

return true;

}

Click to expand...
Calling the AddGossipItemFor function will allow us to display a text that will execute an action when we click on it. Remember to change the action number each time, so that the execution is different here 1 and 2.

Do not forget to use the SendGossipMenuFor function, otherwise the PNJ will not display anything.

In short, here is the result on the PNJ:
Quote: static bool OnGossipSelect(Player* player, Creature* creature , uint32 Action)

{

switch (Action)

{

case 1:

creature->TextEmote("Bienvenue sur Open-WOW", player);

CloseGossipMenuFor(player);

break;

case 2:

CloseGossipMenuFor(player);

break;

}

return true;

}

Click to expand...
If we choose action 2, the gossip closes.

Calling the CloseGossipMenuFor function closes the gossip.

We are just missing the last line to call the script.
Quote: void AddSC_GossipTutroial()

{

new GossipTutroial();

}

Click to expand...
We are missing more than the NPC to create:
Quote: SET

@Entry = 50000,

@Name = "GossipTutroial",

@ScriptName = "GossipTutroial";

INSERT INTO `creature_template` (`entry`, `modelid1`, `modelid2`, `name`, `subname`, `IconName`, `gossip_menu_id`, `minlevel`, `maxlevel`, `exp`, `faction`, `npcflag`, `scale`, `rank`, `dmgschool`, `baseattacktime`, `rangeattacktime`, `unit_class`, `unit_flags`, `type`, `type_flags`, `lootid`, `pickpocketloot`, `skinloot`, `AIName`, `MovementType`, `HoverHeight`, `RacialLeader`, `movementId`, `RegenHealth`, `mechanic_immune_mask`, `flags_extra`, `ScriptName`) VALUES

(@Entry, 21665, 0, @Name, '', NULL, 0, 80, 80, 2, 35, 1, 1, 0, 0, 2000, 0, 1, 0, 7, 138936390, 0, 0, 0, '', 0, 1, 0, 0, 1, 0, 0, @ScriptName);

Click to expand...
If all goes well the final script looks like this:
Quote: #include "ScriptMgr.h"

#include "ScriptedGossip.h"

class GossipTutroial : public CreatureScript

{

public:

GossipTutroial() : CreatureScript("GossipTutroial") { }

static bool OnGossipHello(Player * player, Creature * creature)

{

AddGossipItemFor(player,GOSSIP_ICON_CHAT, "Hello World", GOSSIP_SENDER_MAIN, 1);

AddGossipItemFor(player,GOSSIP_ICON_BATTLE, "Good Bye", GOSSIP_SENDER_MAIN, 2);

SendGossipMenuFor(player, player->GetGossipTextId(creature), creature->GetGUID());

return true;

}

static bool OnGossipSelect(Player* player, Creature* creature , uint32 Action)

{

switch (Action)

{

case 1:

creature->TextEmote("Bienvenue sur Open-WOW", player);

CloseGossipMenuFor(player);

break;

case 2:

CloseGossipMenuFor(player);

break;

}

return true;

}

struct MyAI : public ScriptedAI

{

MyAI(Creature* m_creature) : ScriptedAI(m_creature) { }

bool GossipHello(Player* player) override

{

return OnGossipHello(player, me);

}

bool GossipSelect(Player* player, uint32 menuId, uint32 gossipListId) override

{

uint32 action = player->PlayerTalkClass->GetGossipOptionAction(gossipListId);

return OnGossipSelect(player, me, action);

}

};

CreatureAI* GetAI(Creature* creature) const override

{

return new MyAI(creature);

}

};

void AddSC_GossipTutroial()

{

new GossipTutroial();

}

Click to expand...
ENjoy!! =)

Credit to : Killit5 from Open-Wow
rektbyfaith
11-04-2025, 05:04 PM #1

Archived author: dokuro • Posted: 2025-11-04T18:04:38.594558
Original source

In this tutorial we will see how to simply create a GOSSIP NPC in C ++.

The library

Quote: #include "ScriptMgr.h"

#include "ScriptedGossip.h"

Click to expand...
We must not forget the ScriptedGossip.h library, available in the sources, src \ server \ game \ AI \ ScriptedAI \.

There are various useful functions:

AddGossipItemFor

SendGossipMenuFor

CloseGossipMenuFor

Creation

We start by creating the structure of our script (class, type, name, etc.).
Quote: class GossipTutroial : public CreatureScript

{

public:

GossipTutroial() : CreatureScript("GossipTutroial") { }

struct MyAI : public ScriptedAI

{

MyAI(Creature* m_creature) : ScriptedAI(m_creature) { }

bool GossipHello(Player* player) override

{

return OnGossipHello(player, me);

}

bool GossipSelect(Player* player, uint32 menuId, uint32 gossipListId) override

{

uint32 action = player->PlayerTalkClass->GetGossipOptionAction(gossipListId);

return OnGossipSelect(player, me, action);

}

};

CreatureAI* GetAI(Creature* creature) const override

{

return new MyAI(creature);

}

};

Click to expand...
We then create our first function, the one we will see when talking to the PNJ.

We are going to use the following two functions, which we can find in the ScriptedGossip.h file:
Quote: AddGossipItemFor(Player* player, uint32 icon, std:Confusedtring const& text, uint32 sender, uint32 action)

SendGossipMenuFor(Player* player, uint32 npcTextID, ObjectGuid const& guid)

static bool OnGossipHello(Player * player, Creature * creature)

{

AddGossipItemFor(player,GOSSIP_ICON_CHAT, "Hello World", GOSSIP_SENDER_MAIN, 1);

AddGossipItemFor(player,GOSSIP_ICON_BATTLE, "Good Bye", GOSSIP_SENDER_MAIN, 2);

SendGossipMenuFor(player, player->GetGossipTextId(creature), creature->GetGUID());

return true;

}

Click to expand...
Calling the AddGossipItemFor function will allow us to display a text that will execute an action when we click on it. Remember to change the action number each time, so that the execution is different here 1 and 2.

Do not forget to use the SendGossipMenuFor function, otherwise the PNJ will not display anything.

In short, here is the result on the PNJ:
Quote: static bool OnGossipSelect(Player* player, Creature* creature , uint32 Action)

{

switch (Action)

{

case 1:

creature->TextEmote("Bienvenue sur Open-WOW", player);

CloseGossipMenuFor(player);

break;

case 2:

CloseGossipMenuFor(player);

break;

}

return true;

}

Click to expand...
If we choose action 2, the gossip closes.

Calling the CloseGossipMenuFor function closes the gossip.

We are just missing the last line to call the script.
Quote: void AddSC_GossipTutroial()

{

new GossipTutroial();

}

Click to expand...
We are missing more than the NPC to create:
Quote: SET

@Entry = 50000,

@Name = "GossipTutroial",

@ScriptName = "GossipTutroial";

INSERT INTO `creature_template` (`entry`, `modelid1`, `modelid2`, `name`, `subname`, `IconName`, `gossip_menu_id`, `minlevel`, `maxlevel`, `exp`, `faction`, `npcflag`, `scale`, `rank`, `dmgschool`, `baseattacktime`, `rangeattacktime`, `unit_class`, `unit_flags`, `type`, `type_flags`, `lootid`, `pickpocketloot`, `skinloot`, `AIName`, `MovementType`, `HoverHeight`, `RacialLeader`, `movementId`, `RegenHealth`, `mechanic_immune_mask`, `flags_extra`, `ScriptName`) VALUES

(@Entry, 21665, 0, @Name, '', NULL, 0, 80, 80, 2, 35, 1, 1, 0, 0, 2000, 0, 1, 0, 7, 138936390, 0, 0, 0, '', 0, 1, 0, 0, 1, 0, 0, @ScriptName);

Click to expand...
If all goes well the final script looks like this:
Quote: #include "ScriptMgr.h"

#include "ScriptedGossip.h"

class GossipTutroial : public CreatureScript

{

public:

GossipTutroial() : CreatureScript("GossipTutroial") { }

static bool OnGossipHello(Player * player, Creature * creature)

{

AddGossipItemFor(player,GOSSIP_ICON_CHAT, "Hello World", GOSSIP_SENDER_MAIN, 1);

AddGossipItemFor(player,GOSSIP_ICON_BATTLE, "Good Bye", GOSSIP_SENDER_MAIN, 2);

SendGossipMenuFor(player, player->GetGossipTextId(creature), creature->GetGUID());

return true;

}

static bool OnGossipSelect(Player* player, Creature* creature , uint32 Action)

{

switch (Action)

{

case 1:

creature->TextEmote("Bienvenue sur Open-WOW", player);

CloseGossipMenuFor(player);

break;

case 2:

CloseGossipMenuFor(player);

break;

}

return true;

}

struct MyAI : public ScriptedAI

{

MyAI(Creature* m_creature) : ScriptedAI(m_creature) { }

bool GossipHello(Player* player) override

{

return OnGossipHello(player, me);

}

bool GossipSelect(Player* player, uint32 menuId, uint32 gossipListId) override

{

uint32 action = player->PlayerTalkClass->GetGossipOptionAction(gossipListId);

return OnGossipSelect(player, me, action);

}

};

CreatureAI* GetAI(Creature* creature) const override

{

return new MyAI(creature);

}

};

void AddSC_GossipTutroial()

{

new GossipTutroial();

}

Click to expand...
ENjoy!! =)

Credit to : Killit5 from Open-Wow

Recently Browsing
 1 Guest(s)
Recently Browsing
 1 Guest(s)