Gossip Script

I’m trying to get a gossip script to work and not quite sure on all the ways I need to accomplish this on TrinityCore (Mangos Transferer)

Right now the script I have is:

#include “ScriptPCH.h”

//BE SURE TO CHANGE THE GOSSIP OPTIONS FURTHER DOWN
enum defines
{
TOKEN_ID = 1,
RACE_CHANGE_TOKENS_REQUIRED = 7,
FACTION_CHANGE_TOKENS_REQUIRED = 10,
NAME_CHANGE_TOKENS_REQUIRED = 7,

};

class Gossip_Changer : public CreatureScript
{
public:
Gossip_Changer() : CreatureScript(“Gossip_Changer”){}

	bool OnGossipHello(Player * pPlayer, Creature * pCreature)
	{
		pPlayer->ADD_GOSSIP_ITEM(4, "[7 Tokens] Change my race", GOSSIP_SENDER_MAIN, 0);
		pPlayer->ADD_GOSSIP_ITEM(4, "[10 Tokens] Change my faction", GOSSIP_SENDER_MAIN, 1);
		pPlayer->ADD_GOSSIP_ITEM(4, "[7 Tokens] Change my name", GOSSIP_SENDER_MAIN, 2);
		pPlayer->PlayerTalkClass->SendGossipMenu(9425, pCreature->GetGUID());
		return true;
	}

	bool OnGossipSelect(Player * Player, Creature * Creature, uint32 /*uiSender*/, uint32 uiAction)
	{
		if(!Player)
			return true;

		WorldSession * m_session = Player->GetSession();

		switch(uiAction)
		{
			case 0:
				if(Player->HasItemCount(TOKEN_ID, RACE_CHANGE_TOKENS_REQUIRED))
				{
					Player->DestroyItemCount(TOKEN_ID, RACE_CHANGE_TOKENS_REQUIRED, true, false);
					Player->SetAtLoginFlag(AT_LOGIN_CHANGE_RACE);
					CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '128' WHERE guid = %u", (Player->GetGUID()));
					m_session->SendNotification("Relog. You will be prompted on your next login.");
					Player->PlayerTalkClass->SendCloseGossip();

				}
				else
				{
					m_session->SendNotification("You don't have enough vote tokens");
					Player->PlayerTalkClass->SendCloseGossip();
				}
				break;
			case 1:
				if(Player->HasItemCount(TOKEN_ID, FACTION_CHANGE_TOKENS_REQUIRED))
				{
					Player->DestroyItemCount(TOKEN_ID, FACTION_CHANGE_TOKENS_REQUIRED, true, false);
					Player->SetAtLoginFlag(AT_LOGIN_CHANGE_FACTION);
					CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '64' WHERE guid = %u", (Player->GetGUID()));
					m_session->SendNotification("Relog. You will be prompted on your next login.");
					Player->PlayerTalkClass->SendCloseGossip();

				}
				else
				{
					m_session->SendNotification("You don't have enough vote tokens");
					Player->PlayerTalkClass->SendCloseGossip();
				}
				break;
			case 2:
				if(Player->HasItemCount(TOKEN_ID, NAME_CHANGE_TOKENS_REQUIRED))
				{
					Player->DestroyItemCount(TOKEN_ID, NAME_CHANGE_TOKENS_REQUIRED, true, false);
					Player->SetAtLoginFlag(AT_LOGIN_RENAME);
					CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '1' WHERE guid = %u", (Player->GetGUID()));
					m_session->SendNotification("Relog. You will be prompted on your next login.");
					Player->PlayerTalkClass->SendCloseGossip();

				}
				else
				{
					m_session->SendNotification("You don't have enough vote tokens");
					Player->PlayerTalkClass->SendCloseGossip();
				}
				break;
				

		}
		return true;
	}

};

void AddSC_NPC_Gossip_Changer()
{
new Gossip_Changer();
}

When I put Gossip_Changer under ScriptName in the database on the creature and set the NPC to a Gossip Vendor (129) The gossip is not displayed, so I was wondering if there was something more I had to do with the DB or if something is wrong in the script. Thanks for any help.

add player->PrepareGossipMenu(creature); at first in OnGossipHello

and don’t forget to add this script to scriptloader (to check this: remove scriptname from db, if you get startup error related to this script, script is loaded correctly ^^)

Awesome. So I’m pretty sure that my issue is in script Loading. Was hoping I could perhaps ask for a little more help. In ScriptLoader.cpp I’ve added

#ifdef SCRIPTS
/* This is where custom scripts’ loading functions should be declared. */

#endif

void AddCustomScripts()
{
#ifdef SCRIPTS
/* This is where custom scripts should be added. */
AddSC_Gossip_Changer();

#endif
}

During the Compile I get:

AddSC_Gossip_Changer was not declared in this scope

I have the Gossip_Changer declared in the CMakeLists and I’m not sure what more it wants.

You got this function in your script :

void AddSC_NPC_Gossip_Changer()
{

though you are using :

AddSC_Gossip_Changer();

it should be like this ( added the needed script’s loading function aswell ) :

[CODE]
#ifdef SCRIPTS
/* This is where custom scripts’ loading functions should be declared. */
void AddSC_NPC_Gossip_Changer();
#endif

void AddCustomScripts()
{
#ifdef SCRIPTS
/* This is where custom scripts should be added. */
AddSC_NPC_Gossip_Changer();

#endif
}[/CODE]

With both of your guys’ help the script is now loading and functioning. Now just to add more content to it and it’ll be good to go. Thanks guys. Feel free to Can the message as solved. If anyone else doesn’t understand feel free to PM me and I’ll explain further, but these two here cleared it up well.

Vote tokens… come on guys, illegal public servers aren’t supposed to be getting help here…

Im curious where vote tokens is at in the script.

Nevermind, I see it now, modified script by the way. The tokens are intended as an additional loot item for honor kills.

+KingPin needs to do something about code boxes, those horrid colors make it very hard to read.

wait what… what horrid colors? I assume one of the custom themes?

IPB sucks donkey balls

They tried to be clever, and make every other line a slightly different shade of white, and, in the custom skins, it makes it almost impossible to read.

Please do something, I hate reading forums with white backgrounds.

Code box colors are fine imho

Switch to blood or gamer skin and tell me if they still are fine.

ah yeah that sucks, didnt know you meant a different skin.