Welcome to the MMOtop - Arcemu, Mangos, Trinity.
+ Reply to Thread
Results 1 to 4 of 4
  1. #1
    Jerry's Avatar
    Status : Jerry is offline
    Join Date : Mar 2009
    Location : Serbia
    Posts : 2,321
    Thanks: 223
    Thanked 501 Times in 286 Posts
    Rep Power : 10
    Reputation:2077Jerry has a reputation beyond repute Jerry has a reputation beyond repute Jerry has a reputation beyond repute Jerry has a reputation beyond repute Jerry has a reputation beyond repute Jerry has a reputation beyond repute Jerry has a reputation beyond repute Jerry has a reputation beyond repute Jerry has a reputation beyond repute Jerry has a reputation beyond repute Jerry has a reputation beyond repute

    Default [C++ Tutorial] How to Make a Gossip NPC

    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...

    #include "StdAfx.h"
    #include "Setup.h"

    #ifdef WIN32
    #pragma warning(disable:4305)
    #endif
    These mean to include the files StdAfx.h and Setup.h and to disable warning 4305 when the script is compiled using WIN32.
    Don't bother remembering that information.


    Next, we'll add this to our .cpp script:

    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;
    }
    };
    This is pretty much saying that the voids included are:

    - GossipNPC::GossipHello
    - GossipNPC::GossipSelectOption
    - GossipNPC::GossipEnd

    class SCRIPT_DECL GossipNPC : public GossipScript
    You can change GossipNPC to whatever you want. But, remember, it will be used later on in the script!
    I recommend keeping it the same as it is.



    The script should look something like this so far:

    #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;
    }
    };
    The next part of the script - the actual gossip menu. It looks like 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);
    if(AutoSend)
    Menu->SendTo(Plr);
    }
    Make sure that GossipNPC is whatever you had after

    SCRIPT_DECL
    at the start of the script!


    Menu->AddItem(0, "Teleport me to Tanaris", 1) is our first menu option.

    A menu option is set out like this:

    Menu->AddItem(0, "Text of menu option", 1)
    - Menu->AddItem means that the menu will add the item following the "->".

    - The 0 is what appears to the left of the menu on the menu screen in-game. Here are all the IDs:

    //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
    - "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!

    - 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!

    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);
    }
    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!



    The script should look something like this so far:

    #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);
    }
    The options in the script so far won't do anything. The next part to add to your script is the option selecting part:

    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;
    }
    };
    GossipNPC yet again, must be what you had after "SCRIPT_DECL" further above!

    case 1:
    Plr->Gossip_Complete();
    Plr->Teleport(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.


    - 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:

    Plr->EventTeleport(mapID, xcoord, ycoord, zcoord);
    Notice that each coordinate is separated by a comma. Super easy to understand.


    The script should look something like this so far:

    #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;
    }
    };
    This is the final part, and really easy. The setup part at the end of your script:

    void SetupGossipNPC(ScriptMgr * mgr)
    {
    GossipScript * gs = (GossipScript*) new GossipNPC();
    mgr->register_gossip_script(NPCID, gs);
    }
    - The 2 "GossipNPC"'s need to be what came after "SCRIPT_DECL" near the top of your script. Business as usual.

    - And change "NPCID" to your NPC's entry ID!



    The end script should look something 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;
    }
    };


    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);
    }
    And that's it! I hope you enjoyed my tutorial, and I hope it helped people out!

    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

  2. The Following User Says Thank You to Jerry For This Useful Post:

    smokyramone (10-04-2010)

  3. #2
    Status : justinthedemond is offline
    Join Date : Sep 2010
    Posts : 4
    Thanks: 0
    Thanked 0 Times in 0 Posts
    Rep Power : 0
    Reputation:10justinthedemond is on a distinguished road

    Default

    nice

  4. #3
    Status : Nemorfa is offline
    Join Date : Feb 2011
    Posts : 1
    Thanks: 0
    Thanked 0 Times in 0 Posts
    Rep Power : 0
    Reputation:10Nemorfa is on a distinguished road

    Default

    Hello
    I have no problems with this script, I understand to everithing.
    Bud I have problem with this: How do I get the mob or NPC in the game and how do I give him this scrit that I wrote.
    I know how to script in C++ bud I never figured out how do I add this script to my onw NPC´s or mob´s. How can I add a unique mob into the game and assign him that script, so that mob or npc will do what is written in the script.
    (sorry for my english, its not my mother tongue)

  5. #4
    Killerasis's Avatar
    Status : Killerasis is offline
    Join Date : Sep 2010
    Location : I Live @ MMOTop.Org
    Posts : 459
    Thanks: 3
    Thanked 9 Times in 5 Posts
    Rep Power : 2
    Reputation:11Killerasis is on a distinguished road

    Default

    Looks's Nice


 

Similar Threads

  1. [Tutorial] How to setup an Account Creation page for your server
    By Jerry in forum Emulator Server Guides
    Replies: 6
    Last Post: 03-17-2012, 09:52 AM
  2. Replies: 39
    Last Post: 03-07-2012, 09:18 PM
  3. Replies: 6
    Last Post: 06-20-2010, 11:37 PM
  4. Anyone want to make an private server and make it public together?
    By zakakid1 in forum Recruitment & Gamemasters
    Replies: 4
    Last Post: 05-31-2010, 02:08 AM
  5. Make ArcEmu public + Make 2 realm in ArcEmu
    By Jerry in forum ArcEmu Guides
    Replies: 15
    Last Post: 05-23-2010, 04:32 AM

Visitors found this page by searching for:

wow gossip npc

gossip teleporter

wow trinity gossip

npc gossip trinity

gossip trinity

c gossip trinity

wow npc gossip

Mangos C tutorial

npc say c

how to create gossip

trinity gossip tutorial

WoW gossip teleporter

lua c tutorial

mangos scripting tutorial

gossip script trinity

trinitycore c gossip npc

how to create gosip

trinity c gossip script

mangos gossip tutorial

trinity npc gossip

add gossip trinity

trinity c gossip

Trinity c tutorial

arcemu npc gossip

trinity gossip script

SEO Blog

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts