[Archive] [3.3.5] Gossip NPC Tutorial
[Archive] [3.3.5] Gossip NPC Tutorial
Quote: #include "ScriptMgr.h"We must not forget the ScriptedGossip.h library, available in the sources, src \ server \ game \ AI \ ScriptedAI \.
#include "ScriptedGossip.h"
Click to expand...
Quote: class GossipTutroial : public CreatureScriptWe then create our first function, the one we will see when talking to the PNJ.
{
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...
Quote: AddGossipItemFor(Player* player, uint32 icon, std: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.tring 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...
Quote: static bool OnGossipSelect(Player* player, Creature* creature , uint32 Action)If we choose action 2, the gossip closes.
{
switch (Action)
{
case 1:
creature->TextEmote("Bienvenue sur Open-WOW", player);
CloseGossipMenuFor(player);
break;
case 2:
CloseGossipMenuFor(player);
break;
}
return true;
}
Click to expand...
Quote: void AddSC_GossipTutroial()We are missing more than the NPC to create:
{
new GossipTutroial();
}
Click to expand...
Quote: SETIf all goes well the final script looks like this:
@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...
Quote: #include "ScriptMgr.h"ENjoy!! =)
#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...
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"We must not forget the ScriptedGossip.h library, available in the sources, src \ server \ game \ AI \ ScriptedAI \.
#include "ScriptedGossip.h"
Click to expand...
Quote: class GossipTutroial : public CreatureScriptWe then create our first function, the one we will see when talking to the PNJ.
{
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...
Quote: AddGossipItemFor(Player* player, uint32 icon, std: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.tring 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...
Quote: static bool OnGossipSelect(Player* player, Creature* creature , uint32 Action)If we choose action 2, the gossip closes.
{
switch (Action)
{
case 1:
creature->TextEmote("Bienvenue sur Open-WOW", player);
CloseGossipMenuFor(player);
break;
case 2:
CloseGossipMenuFor(player);
break;
}
return true;
}
Click to expand...
Quote: void AddSC_GossipTutroial()We are missing more than the NPC to create:
{
new GossipTutroial();
}
Click to expand...
Quote: SETIf all goes well the final script looks like this:
@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...
Quote: #include "ScriptMgr.h"ENjoy!! =)
#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...