PDA

View Full Version : [C++] Guild Housing System v2.0



Lbniese
22-09-09, 08:07 AM
WARNING!
Script was compiled for Latest Aspire Hearthstone 3_1_0 Branch with shared ptrs
As is, this is not 'Completely' compatible with ArcEmu, some errors may still occur, if they do please post the errors you recieve on this thread ONLY.

##EDIT##
GUILD HOUSING V.2.0
UPDATE


I Spent the better part of the last 3 weeks trying to dig out some old school guild house scripts and hopefully convert those to work for Aspire's shared ptr's on their 3.1.X Branch. After weeks of converting, nothing would work. My NPC's would always crash the realm on talk or option choices. And no matter what I did, after modding the code to safely compile my options were very limited. So I decided to code myself a new Guild House script to work on as a base for my future Guild System which will include a FFA Guild battle system. I've already gone thru some kinks in the script and am very confident this will be a good starting point for any other average coder like myself. I release this to you AC Webians with the hope of inspiring a bit of hope that anybody can code if given a moment to breathe.


What it does:
Guild Houses
Will query the Guild ID of player and cross check with entries in the character database (house table posted below)
checks if players guild owns an area
checks if player has enough gold
if no gold no port to house
enters in coords based on players gps location (i have some future plans for this - change to actual coords instead of gps function if you want to limit locations)
Ports to guild house cost 100 gold (1000 * 1000 = 100 gold)


Q_RESULTS_1 and Q_RESULTS_2 now check to see if Guilds own a Zone
Q_RESULTS_G_LEADER now checks guild_data table in character DB for guildid, guid, and guildrank
if all 3 are proper, Only Guild Masters can purchase
Guilds can now purchase multiple zones
If a zone is already owned - you cannot purchase
Now checks correctly in various ways if you are -
level 10
in a guild
Guild Master
what Zone
Guild ID
Player GUID
In Combat


Now teleports you to nearest Housing Area if in a Zone that
Your Guild Controls - If not in a Guild Controlled Zone you cannot port there
-- Next Stop
On Owned Zone Entry - If players own a Zone there will be
an announcement to players if they own / if its available
and what options are allowed


Everybody say yay for ownable zones http://www.ac-web.org/forum/venise/smilies/smile.gif


G_House.CPP


/*
* Written by Tekkeryole / AKA / WHOS / Galv
* Copyright (C)2009 <http://wowtek.servegame.org/> WoWTek Realms
* Feel free to modify as you wish - Give Credits if you
* Repost this anywhere else and/or modify and re-release.
* I will not tolerate Leechers and / or code stealers
* So for the sake of Open Source, give Credits please.
* Cheers :)
*/


#include "StdAfx.h"
#include "Setup.h"

#ifdef WIN32
#pragma warning(disable:4305)
#pragma warning(disable:4101)

#endif


#define HOUSE_MANAGER 40014//< Duh, NPC ID >
#define REQ_COIN 1000 * 1000//< 1000 * 1000 = 100 Gold
#define GUILD_MASTER_RANK 0

class SCRIPT_DECL H_MANAGER : public GossipScript
{
public:
void GossipHello(ObjectPointer Ob, PlayerPointer Plr, bool AutoSend);
void GossipSelectOption(ObjectPointer Ob, PlayerPointer Plr, uint32 Id, uint32 IntId, const char * Code);
void GossipEnd(ObjectPointer Ob, PlayerPointer Plr);
void Destroy()
{
delete this;
}
};

void H_MANAGER::GossipHello(ObjectPointer Ob, PlayerPointer Plr, bool AutoSend)
{
GossipMenu * Menu;
objmgr.CreateGossipMenuForPlayer(&Menu, Ob->GetGUID(), 1, Plr);

if(
Plr->CombatStatus.IsInCombat())
{
Plr->BroadcastMessage("You are in Combat!");
return;
}
if(
Plr->GetGuildId() == NULL)
{
Plr->BroadcastMessage("You are not in a Guild!");
return;
}
if(
Plr->getLevel() < 10)
{
Plr->BroadcastMessage("You must be level 10.");
}else{
Menu->AddItem(1, "Buy this Area.", 1);
Menu->AddItem(2, "Port me to the nearest Guild Area.", 2);
Menu->AddItem(3, "Area Options", 3);
}
if(AutoSend)
Menu->SendTo(Plr);
}
void H_MANAGER::GossipSelectOption(ObjectPointer Ob, PlayerPointer Plr, uint32 Id, uint32 IntId, const char * Code)
{
CreaturePointer pCreature = (Ob->GetTypeId()==TYPEID_UNIT) ?TO_CREATURE(Ob):NULLCREATURE;

uint32 PLR_COIN = Plr->GetUInt32Value(PLAYER_FIELD_COINAGE);

if(pCreature==NULLCREATURE)
return;
GossipMenu * Menu;
switch(IntId)
{
case 0:
GossipHello(Ob, Plr, true);
break;


//CASE ONE - BUYING THE HOUSE - DO YOU HAVE THE PRE-REQUISITES FILLED OUT?
case 1:
{
// SQL HACK CHECK TO SEE IF YOU ARE A GUILD MASTER UNTIL I FIGURE OUT HOW
// TO CALL FUNCTION GETGUILDLEADER PROPERLY
QueryResult * Q_RESULTS_G_LEADER = CharacterDatabase.Query("SELECT * FROM guild_data WHERE guildid = %u AND playerid = %u AND guildRank = %u", Plr->GetGuildId(), Plr->GetGUID(), GUILD_MASTER_RANK);
if(Q_RESULTS_G_LEADER == GUILD_MASTER_RANK)
{
Plr->BroadcastMessage("You are not the Guild Master.");
Plr->Gossip_Complete();
return;
}
QueryResult * Q_RESULTS_1 = CharacterDatabase.Query("SELECT * FROM House_system WHERE guild_id = %u AND zoneid = %u", Plr->GetGuildId(), Plr->GetZoneId());
if(Q_RESULTS_1 != NULL)
{ //ARE YOU SERIOUSLY TRYING TO BUY PROPERTY TWICE?
Plr->BroadcastMessage("This area has already been purchased.");
Plr->Gossip_Complete();
return;
}
if(PLR_COIN < (REQ_COIN))
//REMINDER FOR LATER - ADD IN OPTION TO TELE TO OTHER GUILDS
//OWNED HOUSE IF ON ZONE - EXTRA CHARGE APPLIES FOR NON OWNERS

{ //YOU NEED TO HAVE A SUBSTANTIAL BREAD FLOW OR THIS HAPPENS
Plr->BroadcastMessage("You don't have enough gold to Teleport to nearby Guilds Land.");
Plr->Gossip_Complete();
return;
}
if(Q_RESULTS_1 == NULL)
{ //MMMM, DATA INSERTION
//NOW GIVE ME MY MONEY!
CharacterDatabase.Execute("INSERT INTO House_system VALUES('%u', '%f', '%f', '%f', '%u', '%u')", Plr->GetGuildId(), Plr->GetPositionX(), Plr->GetPositionY(), Plr->GetPositionZ(), Plr->GetMapId(), Plr->GetZoneId());
Plr->SetUInt32Value(PLAYER_FIELD_COINAGE, (PLR_COIN - (REQ_COIN)));//GOLD REMOVAL
Plr->BroadcastMessage("Gratz! Your Guild now Owns this area."); //PLAYER SEES THIS IN CHAT
Plr->Gossip_Complete();
}
}break;

//CASE TWO - READ ALL THE FINE PRINT AND GET ACCESS
case 2:
{
QueryResult * Q_RESULTS_2 = CharacterDatabase.Query("SELECT * FROM House_system WHERE guild_id = %u AND zoneid = %u", Plr->GetGuildId(), Plr->GetZoneId());
if(Q_RESULTS_2 == NULL)
{ //EITHER YOU ARE TRYING TO OUTBUY SOMEONE ELSES HOUSE
//OR YOUR GUILD ALREADY OWNS A HOUSE
Plr->BroadcastMessage("Your Guild does not own any Land Nearby.");
Plr->Gossip_Complete();
return;
}
if(Q_RESULTS_2->GetRowCount() > 1)
{ //OH BEJESUS, ANOTHER MYSQL ERROR
//BTW - ERROR 421 = BETTER THEN SOBER
//AND YOU THOUGHT 4:20 WAS SO COOL
//BY THE TIME 4:21 ROLLS AROUND IM BETTER THEN SOBER
Plr->BroadcastMessage("Error 421 - Please Report this on the Forums - ");
Plr->Gossip_Complete();
return;
}
if(PLR_COIN < (REQ_COIN))
{ //ZOMG NO GOLD?
Plr->BroadcastMessage("You don't have enough gold to teleport to your house.");
Plr->Gossip_Complete();
return;
}
float x, y, z;
uint32 MapID;
Field * F_RESULT = Q_RESULTS_2->Fetch();
x = F_RESULT[1].GetFloat();
y = F_RESULT[2].GetFloat();
z = F_RESULT[3].GetFloat();
MapID = F_RESULT[4].GetUInt32();
Plr->EventTeleport(MapID, x, y, z);
Plr->Gossip_Complete();
}break;

//CASE THREE - AVAILABLE HOUSE OPTIONS
case 3:
{
objmgr.CreateGossipMenuForPlayer(&Menu, Ob->GetGUID(), 1, Plr);
Menu->AddItem(0, "This menu is under construction");
//WILL FINISH CREATURE SPAWNS AND OBJECT SPAWNS
//ONCE HOUSE LOCATIONS IN EACH ZONE ARE SET UP
//UNLESS I CAN FIGURE OUT A BETTER WAY
Menu->AddItem(1, "Purchase Repair Bot", 4);
Menu->AddItem(2, "Purchase Furniture", 5);
Menu->AddItem(3, "Purchase Armor Vendor", 6);
Menu->AddItem(4, "Purchase Weapon Vendor", 7);
Menu->AddItem(5, "Teleport List", 8);
Menu->SendTo(Plr);
}break;
//BEGINNING OF CASES
//case OPEN:
// {
// Plr->FUNCTION(PARAMETERS);
// }break;

}
};

void H_MANAGER::GossipEnd(ObjectPointer Ob, PlayerPointer Plr)
{
GossipScript::GossipEnd(Ob, Plr);
}

void SetupH_MANAGER(ScriptMgr * mgr)
{
GossipScript * H_M = (GossipScript*) new H_MANAGER();
mgr->register_gossip_script(HOUSE_MANAGER, H_M);
}
SETUP.CPP

#include "StdAfx.h"
#include "Setup.h"
#define SKIP_ALLOCATOR_SHARING 1
#include <ScriptSetup.h>

extern "C" SCRIPT_DECL uint32 _exp_get_script_type()
{
return SCRIPT_TYPE_MISC;
}

extern "C" SCRIPT_DECL void _exp_script_register(ScriptMgr* mgr)
{
SetupH_MANAGER(mgr);
}

#ifdef WIN32

BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved )
{
return TRUE;
}

#endif
SETUP.H

#ifndef INSTANCE_SCRIPTS_SETUP_H
#define INSTANCE_SCRIPTS_SETUP_H

void SetupH_MANAGER(ScriptMgr * mgr);

#endif
SQL Table to be loaded into Character Database

DROP TABLE IF EXISTS "house_system";

CREATE TABLE "house_system" (
"guild_id" int(6) unsigned NOT NULL DEFAULT '0',
"posX" float NOT NULL DEFAULT '0',
"posY" float NOT NULL DEFAULT '0',
"posZ" float NOT NULL DEFAULT '0',
"mapId" int(10) unsigned NOT NULL DEFAULT '0',
"zoneid" int(10) unsigned NOT NULL COMMENT 'zone id',
PRIMARY KEY ("zoneid")
);

GUILD HOUSE MANAGER


INSERT INTO `creature_names` (`entry`, `name`, `subname`, `info_str`, `Flags1`, `type`, `family`, `rank`, `unk4`, `spelldataid`, `male_displayid`, `female_displayid`, `male_displayid2`, `female_displayid2`, `unknown_float1`, `unknown_float2`, `civilian`, `leader`) VALUES ('40014', 'Housing Manager', 'Guild House Manager', '', '1', '7', '0', '4', '0', '0', '22220', '0', '0', '0', '1.0', '1.0', '0', '1');INSERT INTO `creature_proto` (`entry`, `minlevel`, `maxlevel`, `faction`, `minhealth`, `maxhealth`, `mana`, `scale`, `npcflags`, `attacktime`, `attacktype`, `mindamage`, `maxdamage`, `rangedattacktime`, `rangedmindamage`, `rangedmaxdamage`, `item1`, `item2`, `item3`, `RespawnTime`, `resistance1`, `resistance2`, `resistance3`, `resistance4`, `resistance5`, `resistance6`, `resistance7`, `combat_reach`, `bounding_radius`, `auras`, `boss`, `money`, `invisibility_type`, `death_state`, `walk_speed`, `run_speed`, `fly_speed`, `extra_a9_flags`, `auraimmune_flag`, `vehicle_entry`, `CanMove`) VALUES ('40014', '80', '80', '35', '50000', '50000', '0', '1.0', '3', '3000', '0', '20000.0', '20000.0', '0', '0.0', '0.0', '0', '0', '0', '30000', '1', '1', '1', '1', '1', '1', '0', '0.0', '0.0', '0', '1', '0', '0', '0', '2.5', '8.0', '14.0', '0', '0', '-1', '7');




Credits by Tekkeryole

Avidgamer
22-09-09, 09:50 AM
Put credits in. I know for a fact you didn't create this. I've seen this a while back...

Dimman
22-09-09, 10:35 AM
Wrong section
No credits written

Lbniese
22-09-09, 01:02 PM
ohh ye, it needs to be in the scripting > C++ section...
and credits its some1 from ac-web and i will add it :D ;)

Dimman
22-09-09, 01:44 PM
good . you deserv a ";)"

enegue
23-09-09, 06:07 AM
Agreed. Add credits before cookies are given!

Lbniese
23-09-09, 08:33 AM
i found them, there was credits just in the c++ script :(
i will add it in the thread ;)

enegue
24-09-09, 07:12 AM
Saw this exact script on another emulation forum

Avidgamer
24-09-09, 07:35 AM
I dont think he should be given any rep to be honest. All he does is take other peoples posts, copy and paste them for rep.

enegue
25-09-09, 04:03 AM
It's ok to do so but once in a while...

Avidgamer
25-09-09, 09:54 AM
All the posts I've seen him make have been 'reposts' or 'copy/pasted' - mabey one or two he actually made.. but I doubt it.

Lbniese
07-10-09, 11:59 PM
Hmmm i made many of them

enegue
08-10-09, 03:08 AM
Nah, I doubt it. I find most of your stuff on other Emulation sites.