Code:
/*
House System v.2
Made by Link_S of MMOwned, him and only.
Changelog:
Removed the annoying MySQL outgoing connection,
so now you don't have to edit the code to get this working.
Added a prize you can edit via Optional Config.
No warnings now.
*/
#include "StdAfx.h"
uint32 HOUSEPRIZE = 1064, HOUSETELEPORTPRIZE = 20; //Variables to store the prizes, Changeable via Optional Config
class HouseNPC : public GossipScript
{
public:
void GossipHello(Object * pObject, Player* plr, bool AutoSend)
{
GossipMenu *menu;
objmgr.CreateGossipMenuForPlayer(&menu, pObject->GetGUID(), 1, plr);
if(!plr->CombatStatus.IsInCombat())
{
//Merge the House prize with the menu options.
char m_1[512], m_2[512];
snprintf(m_1, 512, "Buy a house. %s g", HOUSEPRIZE);
snprintf(m_2, 512, "Take me to my house %s g", HOUSETELEPORTPRIZE);
//Add the options..
menu->AddItem(1, m_1, 1);
menu->AddItem(2, m_2, 2);
}
else
plr->BroadcastMessage("I don't want to talk to you when you're in combat.");
if(AutoSend)
menu->SendTo(plr);
};
void GossipSelectOption(Object * pObject, Player* plr, uint32 id, uint32 intId, const char * code)
{
switch(intId)
{
case 1: //The player wants a house
{
QueryResult * res = CharacterDatabase.Query("SELECT * FROM houses WHERE ownerguid = %u", plr->GetGUID());
if(res != NULL) //Appearantly the player alredy have a house.
{
plr->BroadcastMessage("You do alredy have a house.");
plr->Gossip_Complete();
return;
}
//Hmm, a House do also have a prize.
uint32 player_money = plr->GetUInt32Value(PLAYER_FIELD_COINAGE);
if(player_money < (HOUSEPRIZE * 10000))
{
plr->BroadcastMessage("You don't afford a house.");
plr->Gossip_Complete();
return;
}
//Remove the money.
plr->SetUInt32Value(PLAYER_FIELD_COINAGE, (player_money - (HOUSEPRIZE * 10000)));
//Give the house.
CharacterDatabase.Execute("INSERT INTO houses VALUES(%u, 242.284, 0.74529, 1.75938, 598)", plr->GetGUID());
plr->BroadcastMessage("Congratulations, you just bought a house.");
plr->Gossip_Complete();
}break;
case 2: //Teleport to your house
{
QueryResult * res = CharacterDatabase.Query("SELECT * FROM houses WHERE ownerguid = %u", plr->GetGUID());
if(res == NULL)
{
plr->BroadcastMessage("Sorry, you don't have a house.");
plr->Gossip_Complete();
return;
}
if(res->GetRowCount() > 1)
{
Log.Error("HouseSystem", "Report this error to Link_S of MMOwned : received to many rows out of query.");
plr->BroadcastMessage("Error occured. Operation aborted.");
return;
}
//Now draw the money, so the player don't get pissed off when he loses money and don't get teleported.
uint32 player_money = plr->GetUInt32Value(PLAYER_FIELD_COINAGE);
if(player_money < (HOUSEPRIZE * 10000))
{
plr->BroadcastMessage("You don't afford to teleport to your house.");
plr->Gossip_Complete();
return;
}
//Just some variables for teleportation, makes better structure.
float x, y, z;
uint32 mapid;
Field * f = res->Fetch();
x = f[1].GetFloat();
y = f[2].GetFloat();
z = f[3].GetFloat();
mapid = f[4].GetUInt32();
//Now teleport the player to their house.
plr->EventTeleport(mapid, x, y, z);
plr->Gossip_Complete();
}break;
}
};
void Destroy()
{
delete this;
};
};
void SetupHouseNPC(ScriptMgr * mgr)
{
HOUSEPRIZE = (uint32)Config.OptionalConfig.GetIntDefault("HouseSystem", "HousePrize", 1064);
HOUSETELEPORTPRIZE = (uint32)Config.OptionalConfig.GetIntDefault("HouseSystem", "HouseTeleportationPrize", 20);
if((HOUSEPRIZE < 0) || (HOUSETELEPORTPRIZE < 0))
{
Log.Error("HouseSystem", "HousePrize and HouseTeleportationPrize in Optional Config can't be under 0.");
return;
}
GossipScript * gs = (GossipScript*) new HouseNPC();
mgr->register_gossip_script(160000, gs);
};
Code:
--HOUSE PART
INSERT INTO creature_spawns
VALUES
(6152980, 7733, 598, 263.153, 0.0362612, 1.23726, 3.10861, 0, 7346, 474, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
INSERT INTO creature_spawns
VALUES
(6152981, 2456, 598, 274.185, -2.88463, 1.91083, 2.83921, 0, 1436, 814, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
INSERT INTO recall
VALUES
(836, 'house', 598, 242.284, 0.74529, 1.75938);
INSERT INTO creature_names
VALUES
(160000, 'Guild House NPC', 'Handles guild houses', '', 0, 0, 0, 4, 0, 0, 24905, 24905, 0, 0, 1, 1, 1, 0);
INSERT INTO creature_proto
VALUES
(160000, 80, 80, 35, 1000, 1000, 1000, 1, 1, 150, 0, 5000, 6000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 360000, 1500, 0, 0, 0, 0, 0, 0, 1, 1, '0', 0, 0, 0, 0, 2.5, 8, 14, 0, 0, 0, 0, 0, 0, 0);