Example C++ Gossip script!
This is small C++ gossip script example/guide, it will teach you where 2 place most of functions, what 2 u place where and lot more small things that can help starter a lot.
Script:
Code:
/*
C++ Gossip Script Example by Azolex
*/
#include "StdAfx.h"
#include "Setup.h"
/*
Configuration:
*/
#define NPC_ID
// Teleport stuff
#define MapID
#define xCoord
#define yCoord
#define zCoord
#define Orientation
// Morph Stuff
#define ModelID
// Buff Stuff
#define BuffID
// Learn Spell stuff
#define Spell1ID
#define Spell2ID
class GossipExample : public GossipScript
{
public:
void Destroy()
{
delete this;
};
void GossipHello(ObjectPointer pObject, PlayerPointer Plr, bool AutoSend)
{
GossipMenu *Menu;
objmgr.CreateGossipMenuForPlayer(&Menu, pObject->GetGUID(), 933, Plr);
Menu->AddItem(0, "Teleport", 0);
Menu->AddItem(0, "Morph", 1);
Menu->AddItem(0, "Buff", 2);
Menu->AddItem(0, "Learn", 3);
if(AutoSend)
Menu->SendTo(Plr);
};
void GossipSelectOption(ObjectPointer pObject, PlayerPointer Plr, uint32 Id, uint32 IntId, const char * Code)
{
GossipMenu * Menu;
switch(IntId)
{
case 0: // IntId = 0, "Teleport"
Plr->SafeTeleport(MapID, InstanceID/*Can be left NULL but i suggest using Plr->GetInstanceID()*/, xCoord, yCoord, zCoord, Orientation);
break;
case 1: // IntId = 1, "Morph"
Plr->SetUInt32Value(UNIT_FIELD_DISPLAYID, ModelID);
break;
case 2: // IntId = 2, "Buff"
Plr->CastSpell( Plr, dbcSpell.LookupEntryForced(BuffID), true);
break;
case 3: // IntId = 3, "Learn"
objmgr.CreateGossipMenuForPlayer(&Menu, pObject->GetGUID(), 0, Plr);
Menu->AddItem(0, "Spell1", 4);
Menu->AddItem(0, "Spell2", 5);
Menu->SendTo(Plr);
break;
case 4: // IntId = 4, "Spell1"
Plr->addSpell(Spell1ID);
break;
case 5: // IntId = 5, "Spell2"
Plr->addSpell(Spell2ID);
break;
};
};
};
void SetupGuardGossip(ScriptMgr * mgr)
{
GossipScript * Example = (GossipScript*) new GossipExample();
mgr->register_gossip_script(NPC_ID, Example);
}
IntId - Sets position and unique option id, it helps you 2 fully control selection.
Menu - Menu pointer, it allows you to control menu.
IconId - Menu item IconId, for example inkeeper, Bank, auction... i don't know Id's except that this(1) is normal Cloud.
Now, using this template u can use some advanced functions, 2 modify something more than display id or 2 teach player spells, you can find them here:
C++ Function Libery - Credits to Gastricpenguin.
Now, before using this script you should populate configuration stuff, NPC_ID, ModelID and stuff. I hope this script helped you, if you have question ask it
!