if(!CheckBuildSite(Coord_cl(x,y,z,pc_currchar->pos.map),sx,sy))
if(!CheckBuildSite(Coord_cl(x,y,z,pc_currchar->pos.map),sx,sy, pc_currchar))
void BuildHouse(UOXSOCKET s, int i){	int x,y,loopexit=0;//where they click, and the house/key items	P_ITEM pKey = NULL;	signed char z;	int sx=0,sy=0;                                  //space around the house needed		//int hitem[100],icount=0;//extra "house items" (up to 100)	vector<int> houseItems;	char sect[512];                         //file reading	unsigned short id;                                   //house ID	char itemsdecay = 0;            // set to 1 to make stuff decay in houses	static int looptimes=0;         //for targeting	long int pos;                                   //for files...	int cx=0,cy=0,cz=8;             //where the char is moved to when they place the house (Inside, on the steps.. etc...)(Offset)	bool boat = false;//Boats	int hdeed=0;//deed id #			bool norealmulti = false, nokey = false, othername = false;	int lockamount=0, secureamount=0;	char name[512];	P_CHAR pc_currchar = currchar[s];	if(buffer[s][11]==0xFF && buffer[s][12]==0xFF && buffer[s][13]==0xFF && buffer[s][14]==0xFF) return; // do nothing if user cancels, avoids CRASH!		if (i)	{		openscript("house.scp");		sprintf(sect, "HOUSE %d", i);//and BTW, .find() adds SECTION on there for you....		if (!(i_scripts[house_script]->find(sect)))		{			closescript();			return;		}		do		{			read2();			if (script1[0]!='}')			{				if (!(strcmp((char*)script1,"ID")))				{					id = static_cast<unsigned short>(hex2num(script2));				}				else if (!(strcmp((char*)script1,"SPACEX")))				{					sx=str2num(script2)+1;				}				else if (!(strcmp((char*)script1,"SPACEY")))				{					sy=str2num(script2)+1;				}				else if (!(strcmp((char*)script1,"CHARX")))				{					cx=str2num(script2);				}				else if (!(strcmp((char*)script1,"CHARY")))				{					cy=str2num(script2);				}				else if (!(strcmp((char*)script1,"CHARZ")))				{					cz=str2num(script2);				}				else if( !(strcmp((char*)script1, "ITEMSDECAY" )))				{					itemsdecay = str2num( script2 );				}				else if (!(strcmp((char*)script1,"HOUSE_ITEM")))				{					houseItems.push_back(str2num(script2));				}				else if (!(strcmp((char*)script1, "HOUSE_DEED")))				{					hdeed=str2num(script2);				}											else if (!(strcmp((char*)script1, "BOAT"))) boat = true;//Boats				// khpae : boat deed num				else if (!(strcmp ((char *)script1, "BOAT_DEED"))) {					hdeed = str2num (script2);				}				else if (!(strcmp((char*)script1, "NOREALMULTI"))) norealmulti = true;				else if (!(strcmp((char*)script1, "NOKEY"))) nokey = true;				else if (!(strcmp((char*)script1, "NAME"))) 				{ 					strcpy((char*)name,(char*)script2);					othername = true;				}				else if(!(strcmp((char*)script1, "LOCKDOWNAMOUNT")))				{					lockamount=str2num(script2);				}				else if(!(strcmp((char*)script1, "SECUREAMOUNT")))				{					secureamount=str2num(script2);				}			}		}		while ( (strcmp((char*)script1,"}")) && (++loopexit < MAXLOOPS) );		closescript();				if (!id)		{			clConsole.send("ERROR: Bad house script # %i!\n",i);			return;		}	}		if(!looptimes)	{		if (i)		{						addid1[s]=0x40;addid2[s]=100;//Used in addtarget			if (norealmulti) 				target(s, 0, 1, 0, 245, "Select a place for your structure: "); 			else				HomeTarget(s, 0, 1, 0, 0, (id>>8)-0x40, static_cast<unsigned char>(id&0x00FF), "Select location for building.");					}		else		{			HomeTarget(s, 0, 1, 0, 0, addid1[s]-0x40, addid2[s], "Select location for building.");		}		looptimes++;//for when we come back after they target something		return;	}	if(looptimes)	{		looptimes=0;		if(!pc_currchar->isGM() && SrvParams->houseInTown()==0)		{		    if (pc_currchar->inGuardedArea() && ishouse(id) ) // popy			{			    sysmessage(s," You cannot build houses in town!");			    return;			}		}				x=(buffer[s][11]<<8)+buffer[s][12];//where they targeted		y=(buffer[s][13]<<8)+buffer[s][14];		z=buffer[s][16]+Map->TileHeight((buffer[s][17]<<8)+buffer[s][18]);						if ( (( x<200 && y <200 ) || ( x>6200 || y >4200 ))  )					{			sysmessage(s, "You cannot build your structure there!");			return;		}				if (ishouse(id)) // strict checking only for houses ! LB		{			if(!CheckBuildSite(Coord_cl(x,y,z,pc_currchar->pos.map),sx,sy))			{				sysmessage(s,"Can not build a house at that location (CBS)!");				return;			}		}				//Boats ->		if(!boat) 			sprintf((char*)temp,"%s's house", pc_currchar->name.c_str());//This will make the little deed item you see when you have showhs on say the person's name, thought it might be helpful for GMs.		else 			strcpy((char*)temp, "a mast");		if(norealmulti) 			strcpy((char*)temp, name);		//--^				if (othername) 			strcpy((char*)temp, name);				P_ITEM pMulti = NULL;		if (!boat)		{			pMulti = dynamic_cast<P_ITEM>( new cHouse );			pMulti->Init();			pMulti->setId(id);			pMulti->name = pc_currchar->name + "'s house";			Items->GetScriptItemSetting(pMulti);			//pMulti->setId(id);			RefreshItem( pMulti );		}		else			pMulti = Items->SpawnItem(pc_currchar, 1,(char*)temp,0,id,0,0);					if (!pMulti) return;				pMulti->MoveTo(x,y,z);		pMulti->priv = 0;		pMulti->more4 = itemsdecay; // set to 1 to make items in houses decay		pMulti->morex = hdeed; // crackerjack 8/9/99 - for converting back *into* deeds		pMulti->SetOwnSerial(pc_currchar->serial);				if (houseItems.empty() && !boat)		{			teleport(pc_currchar);			cRegion::RegionIterator4Items rii(pMulti->pos);			for(rii.Begin(); !rii.atEnd(); rii++)			{				P_ITEM sii = rii.GetData();				senditem(s, sii);			}			return;//If there's no extra items, we don't really need a key, or anything else do we? ;-)		}				if(boat) //Boats		{			if(!Boats->Build(s, pMulti, static_cast<char>(id&0x00FF)))			{				Items->DeleItem(pMulti);				return;			}			// store deed item number			pMulti->madewith = hdeed;		}				if (i)//Boats->.. Moved from up there ^		{			P_ITEM pDeed = FindItemBySerial(pc_currchar->fx1);			Items->DeleItem(pDeed); // this will del the deed no matter where it is		}		pc_currchar->fx1=INVALID_SERIAL; //reset fx1 so it does not interfere		// bugfix LB ... was too early reseted 				//Key...		/*		House[houseSize]->OwnerSerial=pc_currchar->serial;		House[houseSize]->OwnerAccount=pc_currchar->account;		House[houseSize]->LockAmount=lockamount;		House[houseSize]->SecureAmount=secureamount;*/			unsigned char id2 = static_cast<unsigned char>(id&0x00FF);		if (id2>=112&&id2<=115) pKey = Items->SpawnItem(s, pc_currchar, 1, "a tent key", 0, 0x10, 0x10,0, 1,1);//iron key for tents		else if(id2<=0x18) pKey = Items->SpawnItem(s, pc_currchar, 1, "a ship key",0,0x10,0x13,0,1,1);//Boats -Rusty Iron Key		else pKey = Items->SpawnItem(s, pc_currchar, 1, "a house key", 0, 0x10, 0x0F, 0, 1,1);//gold key for everything else;				pKey->more1 = static_cast<unsigned char>((pMulti->serial&0xFF000000)>>24);		pKey->more2 = static_cast<unsigned char>((pMulti->serial&0x00FF0000)>>16);		pKey->more3 = static_cast<unsigned char>((pMulti->serial&0x0000FF00)>>8);		pKey->more4 = static_cast<unsigned char>((pMulti->serial&0x000000FF));		pKey->type=7;		pKey->priv=2; // Newbify key..Ripper		// khpae - added tent key & ship key		P_ITEM pKey2;		if (id2>=112&&id2<=115) pKey2 = Items->SpawnItem(s, pc_currchar, 1, "a tent key", 0, 0x10, 0x10,0, 1,1);		else if(id2<=0x18) pKey2 = Items->SpawnItem(s, pc_currchar, 1, "a ship key",0,0x10,0x13,0,1,1);		else 	pKey2 = Items->SpawnItem(s, pc_currchar, 1, "a house key", 0, 0x10, 0x0F, 0,1,1);		P_ITEM bankbox = pc_currchar->GetBankBox();		pKey2->more1 = static_cast<unsigned char>((pMulti->serial&0xFF000000)>>24);		pKey2->more2 = static_cast<unsigned char>((pMulti->serial&0x00FF0000)>>16);		pKey2->more3 = static_cast<unsigned char>((pMulti->serial&0x0000FF00)>>8);		pKey2->more4 = static_cast<unsigned char>((pMulti->serial&0x000000FF));		pKey2->type=7;		pKey2->priv=2;		bankbox->AddItem(pKey2);				if(nokey) 		{			Items->DeleItem(pKey); // No key for .. nokey items			Items->DeleItem(pKey2);		}				P_ITEM pHouseItem = NULL;		unsigned int k;		for (k=0; k < houseItems.size(); ++k)//Loop through the HOUSE_ITEMs		{			openscript("house.scp");			sprintf(sect,"HOUSE ITEM %i", houseItems[k]);			if (!i_scripts[house_script]->find(sect))			{				closescript();			}			else			{				loopexit=0;				do 				{					read2();					if (script1[0]!='}')					{						if (!(strcmp((char*)script1,"ITEM")))						{							pos=ftell(scpfile);// To prevent accidental exit of loop.							closescript();							pHouseItem = Items->CreateScriptItem(s,str2num(script2),0);//This opens the item script... so we gotta keep track of where we are with the other script.							openscript("house.scp");							fseek(scpfile, pos, SEEK_SET);							strcpy((char*)script1, "ITEM");							pHouseItem->setGMMovable();//Non-Movebale by default							pHouseItem->priv=0;//since even things in houses decay, no-decay by default							pHouseItem->pos.x=x;							pHouseItem->pos.y=y;							pHouseItem->pos.z=z;							pHouseItem->SetOwnSerial(pc_currchar->serial);						}						else if (!(strcmp((char*)script1,"DECAY")))						{							pHouseItem->priv |= 0x01;						}						else if (!(strcmp((char*)script1,"NODECAY")))						{							pHouseItem->priv = 0;						}						else if (!(strcmp((char*)script1,"PACK")))//put the item in the Builder's Backpack						{							P_ITEM pBackpack = Packitem(pc_currchar);							pBackpack->AddItem(pHouseItem);						}						else if (!(strcmp((char*)script1,"MOVEABLE")))						{							pHouseItem->setAllMovable();						}						else if (!(strcmp((char*)script1,"LOCK")))//lock it with the house key						{							pHouseItem->more1 = static_cast<unsigned char>((pMulti->serial&0xFF000000)>>24);							pHouseItem->more2 = static_cast<unsigned char>((pMulti->serial&0x00FF0000)>>16);							pHouseItem->more3 = static_cast<unsigned char>((pMulti->serial&0x0000FF00)>>8);							pHouseItem->more4 = static_cast<unsigned char>((pMulti->serial&0x000000FF));						}						else if (!(strcmp((char*)script1,"X")))//offset + or - from the center of the house:						{							pHouseItem->pos.x=x+str2num(script2);						}						else if (!(strcmp((char*)script1,"Y")))						{ 							pHouseItem->pos.y=y+str2num(script2);						}						else if (!(strcmp((char*)script1,"Z")))						{							pHouseItem->pos.z=z+str2num(script2);						}					}				}				while ( (strcmp((char*)script1,"}")) && (++loopexit < MAXLOOPS) );								if (pHouseItem->isInWorld()) 					mapRegions->Add(pHouseItem);  //add to mapRegions				closescript();			}		}		cRegion::RegionIterator4Items ri(pMulti->pos);		for(ri.Begin(); !ri.atEnd(); ri++)		{			P_ITEM si = ri.GetData();			sendinrange(si);		}				if (!norealmulti)		{			pc_currchar->pos.x=x+cx; //move char inside house			pc_currchar->pos.y=y+cy;			pc_currchar->dispz = pc_currchar->pos.z = z+cz;			// khpae : water height = -5, char height = -2			if (boat) {				pc_currchar->pos.z = z + 3;			}			teleport((pc_currchar));		}	}}