Code:
/*
Credits:
Rochet2
Eric
ScriptName: TeLe_gossip_codebox
*/
#include "ScriptPCH.h"
struct Eric
{
uint32 menu_id;
uint32 next_menu_id;
uint8 icon;
std::string name;
int32 cost; // 0 for no requirement
uint8 level; // 0 for no requirement
uint32 faction; // 0 Both, 1 Ally, 2 Horde
uint32 map;
float x, y, z, o;
};
typedef struct Eric Rochet2;
static const Rochet2 TeLe [] =
{
// {menu_id, next_menu_id, icon, name, cost, level, faction, map, x, y, z, o}
{1, 0, 2, "Stormwind", 0, 0, 1, 0, -8842.09f, 626.358f, 94.0867f, 3.61363f},
{1, 0, 2, "Orgrimmar", 0, 0, 2, 1, -1601.08f, 4378.69f, 9.9846f, 2.14362f},
{1, 2, 3, "Submenu", 0, 0, 0, 0, 0, 0, 0, 0},
{2, 0, 2, "Some other teleport", 0, 0, 0, 0, -8842.09f, 626.358f, 94.0867f, 3.61363f},
{2, 1, 7, "Back..", 0, 0, 0, 0, 0, 0, 0, 0},
};
static const uint32 TeLe_size = sizeof(TeLe)/sizeof(*TeLe);
#define ARE_YOU_SURE "Are you sure, that you want to go to "
#define ERROR_COMBAT "You are in combat"
class TeLe_gossip_codebox : public CreatureScript
{
public:
TeLe_gossip_codebox() : CreatureScript("TeLe_gossip_codebox")
{
}
void SendMenu(Player* player, Creature* creature, uint32 Key)
{
uint32 team = player->GetTeam()+1;
for (uint32 i = 0; i < TeLe_size; ++i)
{
if (TeLe[i].menu_id != Key)
continue;
if (player->getLevel() < TeLe[i].level)
continue;
if (TeLe[i].faction && TeLe[i].faction != team)
continue;
if (TeLe[i].next_menu_id)
player->ADD_GOSSIP_ITEM_EXTENDED(TeLe[i].icon, TeLe[i].name, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+i, "", TeLe[i].cost, false);
else
player->ADD_GOSSIP_ITEM_EXTENDED(TeLe[i].icon, TeLe[i].name, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+i, ARE_YOU_SURE+TeLe[i].name, TeLe[i].cost, false);
}
player->SEND_GOSSIP_MENU(DEFAULT_GOSSIP_MESSAGE, creature->GetGUID());
}
bool OnGossipHello(Player* player, Creature* creature)
{
SendMenu(player, creature, 1);
return true;
}
bool OnGossipSelect(Player* player, Creature* creature, uint32 sender, uint32 action)
{
player->PlayerTalkClass->ClearMenus(); // clear the menu
// Stop cheats
if (sender != GOSSIP_SENDER_MAIN || action < GOSSIP_ACTION_INFO_DEF || action >= GOSSIP_ACTION_INFO_DEF+TeLe_size)
{
player->CLOSE_GOSSIP_MENU();
return true;
}
action -= GOSSIP_ACTION_INFO_DEF;
if (player->getLevel() < TeLe[action].level ||
TeLe[action].faction && TeLe[action].faction != player->GetTeam()+1)
{
SendMenu(player, creature, 1);
return true;
}
if (TeLe[action].next_menu_id) // No next menu, teleport
{
if (player->IsInCombat())
{
player->GetSession()->SendNotification(ERROR_COMBAT);
SendMenu(player, creature, TeLe[action].menu_id);
return true;
}
player->ModifyMoney(-TeLe[action].cost);
SendMenu(player, creature, TeLe[action].menu_id);
player->TeleportTo(TeLe[action].map, TeLe[action].x, TeLe[action].y, TeLe[action].z, TeLe[action].o);
return true;
}
player->ModifyMoney(-TeLe[action].cost);
SendMenu(player, creature, TeLe[action].next_menu_id);
return true;
}
};
#undef ARE_YOU_SURE
#undef ERROR_COMBAT
void AddSC_TeLe_gossip_codebox()
{
new TeLe_gossip_codebox();
}
You would need to hook a creature update function instead of a gossip function.