CREDITS: Alvanaar
This tutorial will teach you how to make a gossip NPC for ArcEmu. I know heaps of people want to learn to program in C++ so I decided to make this tutorial.
I will be keeping this tutorial updated. If you have any requests, questions, or need more explaining. Please say so!
Remember, C++ scripting is fun!
Firstly, you need to [Only registered and activated users can see links. ].
Create a .cpp file, or "C++ Source File" and name it whatever you want.
We usually start our gossip script (well, most miscellaneous scripts) with the following code...
These mean to include the files StdAfx.h and Setup.h and to disable warning 4305 when the script is compiled using WIN32.#include "StdAfx.h"
#include "Setup.h"
#ifdef WIN32
#pragma warning(disable:4305)
#endif
Don't bother remembering that information.
Next, we'll add this to our .cpp script:
This is pretty much saying that the voids included are:class SCRIPT_DECL GossipNPC : public GossipScript
{
public:
void GossipHello(Object * pObject, Player* Plr, bool AutoSend);
void GossipSelectOption(Object * pObject, Player* Plr, uint32 Id, uint32 IntId, const char * Code);
void GossipEnd(Object * pObject, Player* Plr);
void Destroy()
{
delete this;
}
};
- GossipNPC::GossipHello
- GossipNPC::GossipSelectOption
- GossipNPC::GossipEnd
You can change GossipNPC to whatever you want. But, remember, it will be used later on in the script!class SCRIPT_DECL GossipNPC : public GossipScript
I recommend keeping it the same as it is.
The script should look something like this so far:
The next part of the script - the actual gossip menu. It looks like this:#include "StdAfx.h"
#include "Setup.h"
#ifdef WIN32
#pragma warning(disable:4305)
#endif
class SCRIPT_DECL GossipNPC : public GossipScript
{
public:
void GossipHello(Object * pObject, Player* Plr, bool AutoSend);
void GossipSelectOption(Object * pObject, Player* Plr, uint32 Id, uint32 IntId, const char * Code);
void GossipEnd(Object * pObject, Player* Plr);
void Destroy()
{
delete this;
}
};
Make sure that GossipNPC is whatever you had aftervoid GossipNPC::GossipHello(Object * pObject, Player* Plr, bool AutoSend)
{
GossipMenu *Menu;
objmgr.CreateGossipMenuForPlayer(&Menu, pObject->GetGUID(), 1, Plr);
Menu->AddItem(0, "Teleport me to Tanaris", 1);
if(AutoSend)
Menu->SendTo(Plr);
}
at the start of the script!SCRIPT_DECL
Menu->AddItem(0, "Teleport me to Tanaris", 1) is our first menu option.
A menu option is set out like this:
- Menu->AddItem means that the menu will add the item following the "->".Menu->AddItem(0, "Text of menu option", 1)
- The 0 is what appears to the left of the menu on the menu screen in-game. Here are all the IDs:
- "Text of menu option" is what the text of the menu option will be. Change it to whatever you want, but make sure you leave the ""s!//0 - Chat
//1 - Vendor
//2 - Flight
//3 - Trainer
//4 - Gear
//5 - Gear
//6 - Bank
//7 - Chat with Point
//8 - Tabard
//9 - Swords
//10 - Gold Dot
- 1 is known as the "intid" in Lua, but in this type of C++ gossip script, it is known as the "case". It must be a unique number to any other case! It will be used in the next section of the script.
How do you add another item to the menu? Easy!
Menu->AddItem(5, "Nevermind", 2); is my new menu item. I simply added it by typing it up underneath. Note that I have a different case ID (which is 2). Also, make sure you remember to include the ; at the end of each command!void GossipNPC::GossipHello(Object * pObject, Player* Plr, bool AutoSend)
{
GossipMenu *Menu;
objmgr.CreateGossipMenuForPlayer(&Menu, pObject->GetGUID(), 1, Plr);
Menu->AddItem(0, "Teleport me to Tanaris", 1);
Menu->AddItem(5, "Nevermind", 2);
if(AutoSend)
Menu->SendTo(Plr);
}
The script should look something like this so far:
The options in the script so far won't do anything. The next part to add to your script is the option selecting part:#include "StdAfx.h"
#include "Setup.h"
#ifdef WIN32
#pragma warning(disable:4305)
#endif
class SCRIPT_DECL GossipNPC : public GossipScript
{
public:
void GossipHello(Object * pObject, Player* Plr, bool AutoSend);
void GossipSelectOption(Object * pObject, Player* Plr, uint32 Id, uint32 IntId, const char * Code);
void GossipEnd(Object * pObject, Player* Plr);
void Destroy()
{
delete this;
}
};
void GossipNPC::GossipHello(Object * pObject, Player* Plr, bool AutoSend)
{
GossipMenu *Menu;
objmgr.CreateGossipMenuForPlayer(&Menu, pObject->GetGUID(), 1, Plr);
Menu->AddItem(0, "Teleport me to Tanaris", 1);
Menu->AddItem(5, "Nevermind", 2);
if(AutoSend)
Menu->SendTo(Plr);
}
GossipNPC yet again, must be what you had after "SCRIPT_DECL" further above!void GossipNPC::GossipSelectOption(Object * pObject, Player* Plr, uint32 Id, uint32 IntId, const char * Code)
{
Creature * pCreature = (pObject->GetTypeId()==TYPEID_UNIT)?((Creature*)pObject):NU LL;
if(pCreature==NULL)
return;
GossipMenu * Menu;
switch(IntId)
{
case 0:
GossipHello(pObject, Plr, true);
break;
case 1:
Plr->Gossip_Complete();
Plr->EventTeleport(1, -6942.47, -4847.1, 0.667853);
break;
case 2:
Plr->Gossip_Complete();
break;
}
};
The above code is the main stuff we'll be focusing on for this section of the script.case 1:
Plr->Gossip_Complete();
Plr->Teleport(1, -6942.47, -4847.1, 0.667853);
break;
case 2:
Plr->Gossip_Complete();
break;
- Plr <-- this means the player.
- -> <-- you could say this means "will do". "Plr->" means that the player will do what comes after it. Really simple.
- Gossip_Complete(); <-- this makes the player's gossip window close.
- EventTeleport(1, -6942.47, -4847.1, 0.667853); <-- Okay, this command is used to teleport a player. It is set out like this:
Notice that each coordinate is separated by a comma. Super easy to understand.Plr->EventTeleport(mapID, xcoord, ycoord, zcoord);
The script should look something like this so far:
This is the final part, and really easy. The setup part at the end of your script:#include "StdAfx.h"
#include "Setup.h"
#ifdef WIN32
#pragma warning(disable:4305)
#endif
class SCRIPT_DECL GossipNPC : public GossipScript
{
public:
void GossipHello(Object * pObject, Player* Plr, bool AutoSend);
void GossipSelectOption(Object * pObject, Player* Plr, uint32 Id, uint32 IntId, const char * Code);
void GossipEnd(Object * pObject, Player* Plr);
void Destroy()
{
delete this;
}
};
void GossipNPC::GossipHello(Object * pObject, Player* Plr, bool AutoSend)
{
GossipMenu *Menu;
objmgr.CreateGossipMenuForPlayer(&Menu, pObject->GetGUID(), 1, Plr);
Menu->AddItem(0, "Teleport me to Tanaris", 1);
Menu->AddItem(5, "Nevermind", 2);
if(AutoSend)
Menu->SendTo(Plr);
}
void GossipNPC::GossipSelectOption(Object * pObject, Player* Plr, uint32 Id, uint32 IntId, const char * Code)
{
Creature * pCreature = (pObject->GetTypeId()==TYPEID_UNIT)?((Creature*)pObject):NU LL;
if(pCreature==NULL)
return;
GossipMenu * Menu;
switch(IntId)
{
case 0:
GossipHello(pObject, Plr, true);
break;
case 1:
Plr->Gossip_Complete();
Plr->EventTeleport(1, -6942.47, -4847.1, 0.667853);
break;
case 2:
Plr->Gossip_Complete();
break;
}
};
- The 2 "GossipNPC"'s need to be what came after "SCRIPT_DECL" near the top of your script. Business as usual.void SetupGossipNPC(ScriptMgr * mgr)
{
GossipScript * gs = (GossipScript*) new GossipNPC();
mgr->register_gossip_script(NPCID, gs);
}
- And change "NPCID" to your NPC's entry ID!
The end script should look something like this:
And that's it! I hope you enjoyed my tutorial, and I hope it helped people out!#include "StdAfx.h"
#include "Setup.h"
#ifdef WIN32
#pragma warning(disable:4305)
#endif
class SCRIPT_DECL GossipNPC : public GossipScript
{
public:
void GossipHello(Object * pObject, Player* Plr, bool AutoSend);
void GossipSelectOption(Object * pObject, Player* Plr, uint32 Id, uint32 IntId, const char * Code);
void GossipEnd(Object * pObject, Player* Plr);
void Destroy()
{
delete this;
}
};
void GossipNPC::GossipHello(Object * pObject, Player* Plr, bool AutoSend)
{
GossipMenu *Menu;
objmgr.CreateGossipMenuForPlayer(&Menu, pObject->GetGUID(), 1, Plr);
Menu->AddItem(0, "Teleport me to Tanaris", 1);
Menu->AddItem(5, "Nevermind", 2);
if(AutoSend)
Menu->SendTo(Plr);
}
void GossipNPC::GossipSelectOption(Object * pObject, Player* Plr, uint32 Id, uint32 IntId, const char * Code)
{
Creature * pCreature = (pObject->GetTypeId()==TYPEID_UNIT)?((Creature*)pObject):NU LL;
if(pCreature==NULL)
return;
GossipMenu * Menu;
switch(IntId)
{
case 0:
GossipHello(pObject, Plr, true);
break;
case 1:
Plr->Gossip_Complete();
Plr->EventTeleport(1, -6942.47, -4847.1, 0.667853);
break;
case 2:
Plr->Gossip_Complete();
break;
}
};
void SetupGossipNPC(ScriptMgr * mgr)
{
GossipScript * gs = (GossipScript*) new GossipNPC();
mgr->register_gossip_script(55555, gs);
}
Please post if you didn't understand it well enough or if you have any problems/requests!
NOTE: If you find a mistake, want something to be explained better, etc then please leave a post!
Cheers,
Alvanaar



LinkBack URL
About LinkBacks




Reply With Quote


Bookmarks