ii=findmulti(Coord_cl(x+k,y+l,z)); if (ii!=-1 && !(norealmulti))
P_ITEM pi_multi = findmulti(Coord_cl(x+k,y+l,z)); if (pi_multi != NULL && !(norealmulti))
void buildhouse(int s, int i){	int ii,x,y,key,loopexit=0;//where they click, and the house/key items	signed char z;	int sx=0,sy=0;                                  //space around the house needed	int k,l,tmp;                                            //Temps	int hitem[100],icount=0;//extra "house items" (up to 100)	char sect[512];                         //file reading	unsigned char id1,id2;                                   //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)	int boat=0;//Boats	int hdeed=0;//deed id #			int norealmulti=0,nokey=0,othername=0;	char name[512];		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!		hitem[0]=0;//avoid problems if there are no HOUSE_ITEMs by initializing the first one as 0	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")))				{					tmp=hstr2num(script2);					id1 = (unsigned char)(tmp>>8);					id2 = (unsigned char)(tmp%256);				}				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")))				{					hitem[icount]=str2num(script2);					icount++;				}				else if (!(strcmp((char*)script1, "HOUSE_DEED")))				{					hdeed=str2num(script2);				}											else if (!(strcmp((char*)script1, "BOAT"))) boat=1;//Boats								else if (!(strcmp((char*)script1, "NOREALMULTI"))) norealmulti=1; // LB bugfix for pentas crashing client				else if (!(strcmp((char*)script1, "NOKEY"))) nokey=1;				else if (!(strcmp((char*)script1, "NAME"))) 				{ 					strcpy((char*)name,(char*)script2);					othername=1;				}			}		}		while ( (strcmp((char*)script1,"}")) && (++loopexit < MAXLOOPS) );		closescript();				if (!id1)		{			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				mtarget(s, 0, 1, 0, 0, id1-0x40, id2, "Select location for building.");					}		else		{			mtarget(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(!chars[currchar[s]].isGM() && SrvParms->houseintown==0)		{		    if (chars[currchar[s]].inGuardedArea() && ishouse(id1, id2) ) // 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(id1, id2)) // strict checking only for houses ! LB		{			if(!(CheckBuildSite(x,y,z,sx,sy)))			{				sysmessage(s,"Can not build a house at that location (CBS)!");				return;			}		}*/				for (k=-sx;k<sx;k++)//check the SPACEX and SPACEY to make sure they are valid locations....		{			for (l=-sy;l<sy;l++)			{				if ((!validNPCMove(x+k,y+l,z,currchar[s]))&&					((chars[currchar[s]].pos.x!=x+k)&&(chars[currchar[s]].pos.y!=y+l)))					/*This will take the char making the house out of the space check, be careful 					you don't build a house on top of your self..... this had to be done So you 					could extra space around houses, (12+) and they would still be buildable.*/				{					sysmessage(s, "You cannot build your stucture there.");					return;					//clConsole.send("Invalid %i,%i [%i,%i]\n",k,l,x+k,y+l);				} //else clConsole.send("DEBUG: Valid at %i,%i [%i,%i]\n",k,l,x+k,y+l);								ii=findmulti(Coord_cl(x+k,y+l,z));				if (ii!=-1 && !(norealmulti))				{					sysmessage(s,"You cant build structures inside structures");					return;				}			}		}				//Boats ->		if(id2>=18) sprintf((char*)temp,"%s's house",chars[currchar[s]].name);//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 pHouse=Items->SpawnItem(currchar[s], 1,(char*)temp,0,(id1<<8)+id2,0,0);		if (!pHouse) return;								chars[currchar[s]].making=0;				pHouse->MoveTo(x,y,z);		pHouse->priv=0;		pHouse->more4 = itemsdecay; // set to 1 to make items in houses decay		pHouse->morex=hdeed; // crackerjack 8/9/99 - for converting back *into* deeds		pHouse->SetOwnSerial(chars[currchar[s]].serial);		if (!hitem[0] && !boat)		{			teleport(currchar[s]);			all_items(s);			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,DEREF_P_ITEM(pHouse), id2))			{				Items->DeleItem(pHouse);				return;			} 		}				if (i)//Boats->.. Moved from up there ^			Items->DeleItem(chars[currchar[s]].fx1); // this will del the deed no matter where it is				chars[currchar[s]].fx1=-1; //reset fx1 so it does not interfere		// bugfix LB ... was too early reseted 				//Key...				if (id2>=112&&id2<=115) key=Items->SpawnItem(s, currchar[s], 1, "a tent key", 0, 0x10, 0x10,0, 0,1,1);//iron key for tents		else if(id2<=0x18) key=Items->SpawnItem(s,currchar[s],1,"a ship key",0,0x10,0x13,0,0,1,1);//Boats -Rusty Iron Key		else key=Items->SpawnItem(s, currchar[s], 1, "a house key", 0, 0x10, 0x0F, 0, 0,1,1);//gold key for everything else;				items[key].more1=pHouse->ser1;//use the house's serial for the more on the key to keep it unique		items[key].more2=pHouse->ser2;		items[key].more3=pHouse->ser3;		items[key].more4=pHouse->ser4;		items[key].type=7;		items[key].priv=2; // Newbify key..Ripper        		ITEM key2=Items->SpawnItem(s, currchar[s], 1, "a house key", 0, 0x10, 0x0F, 0, 0,1,1);		P_ITEM bankbox = chars[currchar[s]].GetBankBox();		P_ITEM p_key=MAKE_ITEMREF_LR(key2);		p_key->more1=pHouse->ser1;		p_key->more2=pHouse->ser2;		p_key->more3=pHouse->ser3;		p_key->more4=pHouse->ser4;		p_key->type=7;		p_key->priv=2;		bankbox->AddItem(p_key);				if(nokey) 		{			Items->DeleItem(key); // No key for .. nokey items			Items->DeleItem(key2);		}				for (k=0;k<icount;k++)//Loop through the HOUSE_ITEMs		{			openscript("house.scp");			sprintf(sect,"HOUSE ITEM %i",hitem[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();							l=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");							items[l].magic=2;//Non-Movebale by default							items[l].priv=0;//since even things in houses decay, no-decay by default							items[l].pos.x=x;							items[l].pos.y=y;							items[l].pos.z=z;							items[l].SetOwnSerial(chars[currchar[s]].serial);						}						if (!(strcmp((char*)script1,"DECAY")))						{							items[l].priv |= 0x01;						}						if (!(strcmp((char*)script1,"NODECAY")))						{							items[l].priv=0;						}						if (!(strcmp((char*)script1,"PACK")))//put the item in the Builder's Backpack						{							items[l].SetContSerial(items[packitem(currchar[s])].serial);							items[l].pos.x=rand()%90+31;							items[l].pos.y=rand()%90+31;							items[l].pos.z=9;						}						if (!(strcmp((char*)script1,"MOVEABLE")))						{							items[l].magic=1;						}						if (!(strcmp((char*)script1,"LOCK")))//lock it with the house key						{							items[l].more1=pHouse->ser1;							items[l].more2=pHouse->ser2;							items[l].more3=pHouse->ser3;							items[l].more4=pHouse->ser4;						}						if (!(strcmp((char*)script1,"X")))//offset + or - from the center of the house:						{							items[l].pos.x=x+str2num(script2);						}						if (!(strcmp((char*)script1,"Y")))						{ 							items[l].pos.y=y+str2num(script2);						}						if (!(strcmp((char*)script1,"Z")))						{							items[l].pos.z=z+str2num(script2);						}					}				}				while ( (strcmp((char*)script1,"}")) && (++loopexit < MAXLOOPS) );								if (items[l].isInWorld()) 					mapRegions->Add(&items[l]);  //add to mapRegions				closescript();			}		}		all_items(s);//make sure they have all the items Sent....		if (!(norealmulti))		{			chars[currchar[s]].pos.x=x+cx; //move char inside house			chars[currchar[s]].pos.y=y+cy;			chars[currchar[s]].dispz=chars[currchar[s]].pos.z=z+cz;			//clConsole.send("Z: %i Offset: %i Char: %i Total: %i\n",z,cz,chars[currchar[s]].pos.z,z+cz);			teleport(currchar[s]);		}	}}