while (((pi = ContainerSearch(p_petowner->serial, &ci)) != NULL) && (++loopexit < MAXLOOPS) ) {
vector<SERIAL> vecContainer = contsp.getData(p_petowner->serial); for ( ci = 0; ci < vecContainer.size(); ci++) { pi = FindItemBySerial(vecContainer[ci]);
int unmounthorse(int s) // Get off a horse (Remove horse item and spawn new horse) { 	CHARACTER cc = currchar[s]; 	int ci = 0, loopexit = 0; 	P_ITEM pi; 	const P_CHAR p_petowner = MAKE_CHARREF_LRV(cc, -1); 	while (((pi = ContainerSearch(p_petowner->serial, &ci)) != NULL) && (++loopexit < MAXLOOPS) ) 	{ 		if (pi->layer == 0x19 && pi->free == 0) 		{ 			////////////////////////////////////// 			// Lets 'unstable' the mount. 			// Unmount the horse and take him out of 			// stable 0. 			// 			// 						// CHARACTER c; 						bool found = false; 			int stablemaster_serial = p_petowner->serial; 			P_CHAR  p_pet = NULL; 						p_petowner->onhorse = false; 						vector<SERIAL> pets = stablesp.getData(stablemaster_serial);			unsigned int i;			for (i = 0; i < pets.size(); i++) 			{ 				p_pet = FindCharBySerial(pets[i]);				if (p_pet != NULL) 				{ 					// clConsole.send("%d = %d ... %d = %d\n", p_pet->ownserial, p_petowner->serial, p_pet->stablemaster_serial,stablemaster_serial); 					if ( p_petowner->Owns(p_pet) && p_pet->stablemaster_serial == stablemaster_serial) // already stabled and owned by claimer ? 					{ 						found = true; 						break; 					} 				} 			} 						if (found) 			{ 				// clConsole.send("Pet found loop\n"); 				// remove from hash table 				stablesp.remove(stablemaster_serial, p_pet->serial);//				removefromptr(&stablesp[stablemaster_serial%HASHMAX], DEREF_P_CHAR(p_pet)); 								p_pet->stablemaster_serial = 0; // actual unstabling 				p_pet->timeused_last = getNormalizedTime(); 				p_pet->time_unused = 0; 				p_pet->pos.x = p_petowner->pos.x; 				p_pet->pos.y = p_petowner->pos.y; 				p_pet->pos.z = p_petowner->pos.z; 								mapRegions->Remove(p_pet); 				mapRegions->Add(p_pet); 								for (int ch = 0; ch < now; ch++) 				{ 					if (perm[ch])						impowncreate(ch, DEREF_P_CHAR(p_pet), 0); 				} 			} 			// cant find horse in stable 			// make them a new one 			else			{ 				clConsole.send("Makeing a new horse cause the other somehow got out/lost :(\n"); 				CHARACTER c; 				switch (pi->id2) 				{ 					case 0xA0:  						c = Npcs->AddNPCxyz(s, 8, 0, p_petowner->pos.x, p_petowner->pos.y, p_petowner->pos.z);						break; 					case 0xA1:  						c = Npcs->AddNPCxyz(s, 9, 0, p_petowner->pos.x, p_petowner->pos.y, p_petowner->pos.z);						break; 					case 0xA2:  						c = Npcs->AddNPCxyz(s, 10, 0, p_petowner->pos.x, p_petowner->pos.y, p_petowner->pos.z);						break; 					case 0xA3:  						c = Npcs->AddNPCxyz(s, 429, 0, p_petowner->pos.x, p_petowner->pos.y, p_petowner->pos.z);						break; 					case 0xA4: 						c = Npcs->AddNPCxyz(s, 427, 0, p_petowner->pos.x, p_petowner->pos.y, p_petowner->pos.z);						break; 					case 0xA5:  						c = Npcs->AddNPCxyz(s, 428, 0, p_petowner->pos.x, p_petowner->pos.y, p_petowner->pos.z);						break; 					case 0xA6:  						c = Npcs->AddNPCxyz(s, 54, 0, p_petowner->pos.x, p_petowner->pos.y, p_petowner->pos.z);						break; 					case 0x9F: 						if (pi->color1 == 0x04 && pi->color2 == 0x55) 							c = Npcs->AddNPCxyz(s, 430, 0, p_petowner->pos.x, p_petowner->pos.y, p_petowner->pos.z); 						else 							c = Npcs->AddNPCxyz(s, 7, 0, p_petowner->pos.x, p_petowner->pos.y, p_petowner->pos.z); 						break; 					default: 						LogCritical("No horse type in unmounthorse(), avoiding crash"); 						return -1; 						break; 				} 				P_CHAR pc_pet = MAKE_CHARREF_LRV(c, -1);				strcpy(pc_pet->name, pi->name); 				pc_pet->xid1 = pc_pet->id1; 				pc_pet->xid2 = pc_pet->id2; 				pc_pet->skin = pc_pet->xskin = pi->color(); 				pc_pet->dispz = pc_pet->pos.z = p_petowner->pos.z; 				pc_pet->dir = p_petowner->dir; 				pc_pet->SetOwnSerial( p_petowner->serial ); 				pc_pet->npcWander = pi->moreb1; 				// pc_s->hp=pi->hp; 				pc_pet->poisoned = pi->poisoned; 				if (pi->decaytime != 0) 					pc_pet->summontimer = pi->decaytime; 				pc_pet->npcaitype = 0; 				updatechar(c); 			} 						// 			// 			// Aldur 			////////////////////////////////////// 			Items->DeleItem(pi); 			return 0; 		} 	} 	return -1; }