Code:
#include "StdAfx.h"
#include "Setup.h"
class SCRIPT_DECL HousePortItem : 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 HousePortItem::GossipHello(Object * pObject, Player* Plr, bool AutoSend)
{
GossipMenu * Menu;
uint32 TextID = 820;
objmgr.CreateGossipMenuForPlayer(&Menu, pObject->GetGUID(), TextID, Plr);
Menu->AddItem(5, "Go to your House", 1);
if(AutoSend)
Menu->SendTo(Plr);
}
void HousePortItem::GossipSelectOption(Object * pObject, Player * Plr, uint32 Id, uint32 IntId, const char * Code)
{
Item * pItem = (pObject->GetTypeId()==TYPEID_ITEM)?((Item*)pObject):NULL;
if(pItem==NULL)
return;
switch(IntId)
{
case 0:
{
GossipHello(pItem, Plr, true);
}
break;
case 1:
{
QueryResult * result = WorldDatabase.Query( "SELECT * FROM playerhouse WHERE `guid`=%u",Plr->GetGUID() );
if(result)
{
do
{
if(Plr->CombatStatus.IsInCombat())
{
Plr->BroadcastMessage("You are in combat!");
}
if(!Plr->CombatStatus.IsInCombat())
{
Field * fields = result->Fetch();
uint32 locmap = fields[1].GetUInt32();
float x = fields[2].GetFloat();
float y = fields[3].GetFloat();
float z = fields[4].GetFloat();
Plr->SafeTeleport(locmap, 0, LocationVector(x, y, z), 0);
//Plr->SafeTeleport(locmap, 0, LocationVector(x, y, z));
}
}
while (result->NextRow());
delete result;
}
else
{
sChatHandler.SystemMessage(Plr->GetSession(),"You have no house found in the database");
}
Plr->Gossip_Complete();
}
break;
case 2:
{
Plr->Gossip_Complete();
}
break;
}
}
void HousePortItem::GossipEnd(Object * pObject, Player* Plr)
{
GossipScript::GossipEnd(pObject, Plr);
}
void SetupHousePortItem(ScriptMgr * mgr)
{
GossipScript * gpItem = (GossipScript*) new HousePortItem();
mgr->register_item_gossip_script(60003, gpItem);
}