if (pc->spawnregion < 0 || pc->spawnregion >= spawnregion.size())
if ( pc->spawnregion >= spawnregion.size() )
void loadchar(int x) // Load a character from WSC{	unsigned long k,b,c1 ;	int i ;	int j, loops=0;	P_CHAR pc = Npcs->MemCharFree();	if ( pc == NULL )		return;	pc->Init(false);	pc->hungertime = uiCurrentTime + ( SrvParams->hungerRate() * MY_CLOCKS_PER_SEC / 2 );	// avoid loss of one hungerpoint for each restart (Duke, 6.6.2001)	do	{		readw2();		switch(script1[0])		{		case 'A':		case 'a':			if (!strcmp((char*)script1, "ACCOUNT"))				{ pc->account=str2num(script2);  }			else if (!strcmp((char*)script1, "ALLMOVE"))		{ pc->priv2=str2num(script2);}			else if (!strcmp((char*)script1, "ATT"))			{ pc->att=str2num(script2);}			else if (!strcmp((char*)script1, "ADVOBJ"))			{ pc->advobj=str2num(script2);}		break;		case 'B':		case 'b':			if (!(strcmp((char*)script1, "BODY")))			{				i=str2num(script2);				pc->id1=i>>8;				pc->id2=i%256;			}		break;		case 'C':		case 'c':			if (!strcmp((char*)script1, "CREATIONDAY"))			{ pc->creationday = str2num(script2); }			else if (!strcmp((char*)script1, "CARVE"))			{ pc->carve=str2num(script2); }			else if (!strcmp((char*)script1, "CANTRAIN"))		  pc->cantrain = true; 		break;		case 'D':		case 'd':			if (!strcmp((char*)script1, "DISPZ"))				  pc->dispz=str2num(script2);			else if (!strcmp((char*)script1, "DIR"))			  pc->dir=str2num(script2);			else if (!strcmp((char*)script1, "DEXTERITY"))		  pc->setDex(str2num(script2));			else if (!strcmp((char*)script1, "DEXTERITY2"))		  pc->setDecDex(str2num(script2));			else if (!strcmp((char*)script1, "DEATHS"))			  pc->deaths=str2num(script2);			else if (!strcmp((char*)script1, "DEAD"))			  pc->dead = true;   // dead only appears in file if it's true.			else if (!strcmp((char*)script1, "DEF"))			  pc->def=str2num(script2);			else if (!strcmp((char*)script1, "DISABLED"))		  pc->disabled=uiCurrentTime+(str2num(script2)*MY_CLOCKS_PER_SEC);			else if (!strcmp((char*)script1, "DISABLEMSG"))		  pc->disabledmsg = (char*)script2;		break;		case 'E':		case 'e':			if (!strcmp((char*)script1, "EMOTE"))			{				pc->emotecolor = str2num(script2);			}		break;		case 'F':		case 'f':			if (!strcmp((char*)script1, "FAME"))				  pc->fame=str2num(script2);			else if (!strcmp((char*)script1, "FIXEDLIGHT"))		  pc->fixedlight=str2num(script2);			else if (!strcmp((char*)script1, "FONT"))			  pc->fonttype=str2num(script2);			else if (!strcmp((char*)script1, "FLEEAT"))			  pc->fleeat=str2num(script2);			else if (!strcmp((char*)script1, "FX1"))			  pc->fx1=str2num(script2);			else if (!strcmp((char*)script1, "FY1"))			  pc->fy1=str2num(script2);			else if (!strcmp((char*)script1, "FZ1"))			  pc->fz1=str2num(script2);			else if (!strcmp((char*)script1, "FX2"))			  pc->fx2=str2num(script2);			else if (!strcmp((char*)script1, "FY2"))			  pc->fy2=str2num(script2);		break;		case 'G': 		case 'g': 			if (!strcmp((char*)script1, "GUILD TYPE")) 			{ 				i = str2num(script2);  // Get the guild type 				if(i<-1||i>MAX_GUILDTYPE) 					i=-1;     // Default to no guild type 				pc->GuildType=i; 			} 			else if (!strcmp((char*)script1, "GUILD TRAITOR")) 			{ 				if(!strcmp((char*)script2, "YES")) 					pc->GuildTraitor=true; // yes this character has switch guilds 				else 					pc->GuildTraitor=false; 			} 			else if (!strcmp((char*)script1, "GUILDTOGGLE"))   pc->guildtoggle=str2num(script2);			else if (!strcmp((char*)script1, "GUILDNUMBER"))   pc->guildstone=str2num(script2);			else if (!strcmp((char*)script1, "GMRESTRICT"))    pc->gmrestrict=str2num(script2); 		    else if (!strcmp((char*)script1, "GUILDTITLE"))    pc->guildtitle = (char*)script2;		    else if (!strcmp((char*)script1, "GUILDFEALTY"))   pc->guildfealty=str2num(script2);			////////////////////////////////// 			// Reads in the Gm movement effect int 			// 			// 			else if (!strcmp((char*)script1, "GMMOVEEFF"))	   pc->gmMoveEff=str2num(script2);  			// 			// 			//Aldur 			////////////////////////////////// 		break;		case 'H':		case 'h':			if (!strcmp((char*)script1, "HITPOINTS"))			  pc->hp=str2num(script2);			else if (!strcmp((char*)script1, "HIDAMAGE"))		  pc->hidamage=str2num(script2);			else if (!strcmp((char*)script1, "HIDDEN"))			  pc->hidden=str2num(script2);			else if (!strcmp((char*)script1, "HUNGER"))			  pc->hunger=str2num(script2);			else if (!strcmp((char*)script1, "HOLDGOLD"))		  pc->holdg=str2num(script2);		break;		case 'I':		case 'i':			if (!strcmp((char*)script1, "INTELLIGENCE"))		  pc->in=str2num(script2);			else if (!strcmp((char*)script1, "INTELLIGENCE2"))	  pc->in2=str2num(script2);		break;		case 'J': 		case 'j': 			if (!strcmp((char*)script1, "JAILTIMER"))			  pc->jailtimer=uiCurrentTime+str2num(script2); 			else if(!strcmp((char*)script1, "JAILCELL"))		  { pc->cell=str2num(script2); jails[pc->cell].occupied = true;} 			else if(!strcmp((char*)script1, "JAILSECS"))		  pc->jailsecs=str2num(script2); 		break;		case 'K':		case 'k':			if (!strcmp((char*)script1, "KARMA"))				  pc->karma=str2num(script2);			else if (!strcmp((char*)script1, "KILLS"))			  pc->kills=str2num(script2);		break;		case 'L':		case 'l':			if (!strcmp((char*)script1, "LODAMAGE"))		      pc->lodamage=str2num(script2);		break;		case 'M':		case 'm':			if (!strcmp((char*)script1, "MENUPRIV"))			  pc->menupriv=str2num(script2);			else if (!strcmp((char*)script1, "MANA"))			  pc->mn=str2num(script2);		break;		case 'N':		case 'n':			if (!strcmp((char*)script1, "NPC"))					  pc->npc=str2num(script2);			else if (!strcmp((char*)script1, "NPCWANDER"))		  pc->npcWander=str2num(script2);			else if (!strcmp((char*)script1, "NOTRAIN"))		  pc->cantrain=false;			else if (!strcmp((char*)script1, "NPCTYPE"))		  pc->npc_type=str2num(script2);			else if (!strcmp((char*)script1, "NAME"))			  pc->name = (char*)script2;			else if (!strcmp((char*)script1, "NPCAITYPE"))		  pc->npcaitype=str2num(script2);		break;		case 'O':		case 'o':			if (!strcmp((char*)script1, "OLDNPCWANDER"))		  pc->oldnpcWander=str2num(script2);			else if (!strcmp((char*)script1, "OLDX"))			  jails[pc->cell].oldpos.x=str2num(script2);			else if (!strcmp((char*)script1, "OLDY"))			  jails[pc->cell].oldpos.y=str2num(script2);			else if (!strcmp((char*)script1, "OLDZ"))			  jails[pc->cell].oldpos.z=str2num(script2);			else if (!strcmp((char*)script1, "OWN"))			{				i=str2num(script2);				pc->SetOwnSerial(i);			}		break;		case 'P':		case 'p':			if (!strcmp((char*)script1, "PRIV"))				  pc->setPriv(str2num(script2));			else if (!strcmp((char*)script1, "PRIV3a"))			  pc->priv3[0]=str2num(script2);			else if (!strcmp((char*)script1, "PRIV3b"))			  pc->priv3[1]=str2num(script2);			else if (!strcmp((char*)script1, "PRIV3c"))			  pc->priv3[2]=str2num(script2);			else if (!strcmp((char*)script1, "PRIV3d"))			  pc->priv3[3]=str2num(script2);			else if (!strcmp((char*)script1, "PRIV3e"))			  pc->priv3[4]=str2num(script2);			else if (!strcmp((char*)script1, "PRIV3f"))			  pc->priv3[5]=str2num(script2);			else if (!strcmp((char*)script1, "PRIV3g"))			  pc->priv3[6]=str2num(script2);			else if (!strcmp((char*)script1, "POISON"))			  pc->poison=str2num(script2);			else if (!strcmp((char*)script1, "POISONED"))		  pc->poisoned=str2num(script2);		break;		case 'Q':		case 'q':			if (!strcmp((char*)script1, "QUESTTYPE"))			  pc->questType=str2num(script2);			else if (!strcmp((char*)script1, "QUESTDESTREGION"))  pc->questDestRegion=str2num(script2);			else if (!strcmp((char*)script1, "QUESTORIGREGION"))  pc->questOrigRegion=str2num(script2);			else if (!strcmp((char*)script1, "QUESTBOUNTYPOSTSERIAL")) pc->questBountyPostSerial=str2num(script2);			else if (!strcmp((char*)script1, "QUESTBOUNTYREWARD")) pc->questBountyReward=str2num(script2);		break;		case 'R':		case 'r':			if (!strcmp((char*)script1, "RACE"))		  pc->race=str2num(script2);			else if (!strcmp((char*)script1, "ROBE"))				pc->robe = str2num(script2);			else if (!strcmp((char*)script1, "REATTACKAT"))		  pc->reattackat=str2num(script2);		// no cells have been marked as -1, but no cell=0		// with that line its not necassairy to take it manually out.		break;		case 'S':		case 's':			if (!strcmp((char*)script1, "SERIAL"))			{				unsigned int i = str2num(script2);				pc->setSerial(i);			}			else if (!strcmp((char*)script1, "SAY"))				pc->saycolor = static_cast<UI16>(str2num(script2));			else if (!strcmp((char*)script1, "STRENGTH"))			pc->st=str2num(script2);			else if (!strcmp((char*)script1, "STRENGTH2"))			pc->st2=str2num(script2);			else if (!strcmp((char*)script1, "STAMINA"))			pc->stm=str2num(script2);			else if (!strcmp((char*)script1, "SUMMONREMAININGSECONDS"))			{//AntiChrist - let's restore remaining seconds!				i = str2num(script2);				pc->summontimer=uiCurrentTime+(i*MY_CLOCKS_PER_SEC);			}			else if (!strcmp((char*)script1, "SHOP"))			  pc->shop=str2num(script2);			else if (!strcmp((char*)script1, "SPEECH"))			  pc->speech=str2num(script2);			else if ((script1[0]=='S')&&(script1[1]=='K')&&(script1[2]=='I')&&				(script1[3]=='L')&&(script1[4]=='L'))			{				pc->baseskill[j=str2num(&script1[5])]=str2num(script2);				Skills->updateSkillLevel(pc, j);			}			else if (!strcmp((char*)script1, "SKIN"))			  pc->skin = static_cast<UI16>(str2num(script2));			else if (!strcmp((char*)script1, "SPATTACK"))		  pc->spattack=str2num(script2);			else if (!strcmp((char*)script1, "SPADELAY"))		  pc->spadelay=str2num(script2);			else if (!strcmp((char*)script1, "SPLIT"))			  pc->split=str2num(script2);			else if (!strcmp((char*)script1, "SPLITCHANCE"))	  pc->splitchnc=str2num(script2);			else if (!strncmp((char*)script1, "SKL", 3 ))		// for skill locking			{				pc->lockSkill[j=str2num(&script1[3])]=str2num(script2);			}			else if (!strcmp((char*)script1, "SPAWNREGION"))			{				pc->spawnregion = str2num(script2);				if (pc->spawnregion < 0 || pc->spawnregion >= spawnregion.size())				{					pc->spawnregion = 0;				} else					spawnregion[pc->spawnregion].current++;			}			else if (!strcmp((char*)script1, "SPAWN"))			{				pc->SetSpawnSerial(str2num(script2));			}			else if (!strcmp((char*)script1, "STABLEMASTER"))			{				pc->stablemaster_serial=str2num(script2);				if (pc->stablemaster_serial>0)					stablesp.insert(pc->stablemaster_serial, pc->serial);			}		break;		case 'T':		case 't':			if (!strcmp((char*)script1, "TITLE"))				  pc->title = (char*)script2;			else if (!strcmp((char*)script1, "TAMING"))			  pc->taming=str2num(script2);			else if (!strcmp((char*)script1, "TRIGGER"))		  pc->trigger=str2num(script2);			else if (!strcmp((char*)script1, "TRIGWORD"))		  pc->trigword = (char*)script2;			else if (!strcmp((char*)script1, "TIME_UNUSED"))	  pc->time_unused=str2num(script2);		break;		case 'X':		case 'x':			if (!strcmp((char*)script1, "X"))					  pc->pos.x=str2num(script2);			else if (!strcmp((char*)script1, "XBODY"))			{				i=str2num(script2);				pc->xid=i;			}			else if (!strcmp((char*)script1, "XSKIN"))			  pc->xskin = static_cast<UI16>(str2num(script2));		break;		case 'W':		case 'w':			if (!strcmp((char*)script1, "WAR"))					  pc->war=str2num(script2);		break;		case 'Y':		case 'y':			if (!strcmp((char*)script1, "Y"))					  pc->pos.y=str2num(script2);		break;		case 'Z':		case 'z':			if (!strcmp((char*)script1, "Z"))					  pc->dispz=pc->pos.z=str2num(script2);		break;		}		loops++;	}	while (strcmp((char*)script1, "}") && loops<=200);	if (pc->isNpc() && pc->war) pc->war=false;			////////////////////////////////////////////////////////////////////		// LB autocorrect for same faulty previous code	int zeta;	for (zeta = 0;zeta<ALLSKILLS;zeta++) if (pc->lockSkill[zeta]!=0 && pc->lockSkill[zeta]!=1 && pc->lockSkill[zeta]!=2) pc->lockSkill[zeta]=0;		//AntiChrist bugfix for hiding	pc->priv2 &= 0xf7; // unhide - AntiChrist	pc->hidden = 0;	pc->stealth = -1;		//AntiChrist bugfix for magic reflect	pc->priv2=pc->priv2&0xBF;			pc->region = calcRegionFromXY(pc->pos.x, pc->pos.y); //LB bugfix		pc->antispamtimer=0;//LB - AntiSpam -	pc->antiguardstimer=0; //AntiChrist - AntiSpam for "GUARDS" call - to avoid (laggy) guards multi spawn	// lord binarys body/skin autocorrection code	k = pc->id();	if (k<=0x3e1)	{		c1 = pc->skin;		b = c1&0x4000;		if ((b==16384 && (k >=0x0190 && k<=0x03e1)) || c1==0x8000)		{			if (c1!=0xf000)			{				pc->skin = pc->xskin = 0xF000;				clConsole.send("char/player: %s : %i correted problematic skin hue\n", pc->name.c_str(),pc->serial);			}		}	} else	// client crashing body --> delete if non player esle put onlx a warning on server screen		// we dont want to delete that char, dont we ?	{		if (pc->account==-1)		{			Npcs->DeleteChar(pc);		} else		{			pc->id1 = 0x01;			pc->id2 = 0x90;			clConsole.send("player: %s with bugged body-value detected, restored to male shape\n",pc->name.c_str());		}	}	//a = mapRegions->AddItem(x+CharacterOffset);	if(pc->stablemaster_serial == INVALID_SERIAL)	{ 		mapRegions->Add(pc); 	} 		// begin of meta gm stuff		for (int u=0;u<7;u++)	{		if (pc->isPlayer())		{			if (pc->priv3[u]==0) // dont overwrite alreday saved settings			{				if (!pc->isGMorCounselor()) pc->priv3[u]=metagm[2][u]; //normal player defaults				if (pc->isCounselor()) pc->priv3[u]=metagm[1][u]; // couscelor defaults				if (pc->isGM()) pc->priv3[u]=metagm[0][u]; // gm defaults				if (pc->account==0) pc->priv3[u]=0xffffffff;			}		}	}		if (pc->isPlayer() && pc->account==0) pc->menupriv=-1;			int max_x = cMapStuff::mapTileWidth(pc->pos)  * 8;	int max_y = cMapStuff::mapTileHeight(pc->pos) * 8;	if ((pc->pos.x < 100 && pc->pos.y < 100 && pc->account ==-1) || ((pc->pos.x>max_x || pc->pos.y>max_y) && pc->account == -1))		// if ((pc->pos.x < 100 && pc->pos.y < 100 && pc->account ==-1) || ((pc->pos.x>max_x || pc->pos.y>max_y || pc->pos.x<0 || pc->pos.y<0) && pc->account==-1))	{		Npcs->DeleteChar(pc); //character in an invalid location	}	if ((pc->pos.x < 100 && pc->pos.y < 100 && pc->account != -1) || (( pc->pos.x>max_x || pc->pos.y>max_y ) && pc->account !=-1))		// if ((pc->pos.x < 100 && pc->pos.y < 100 && pc->account !=-1) || ((pc->pos.x>max_x || pc->pos.y>max_y || pc->pos.x<0 || pc->pos.y<0) && pc->account!=-1))	{		Coord_cl pos(pc->pos);		pos.x = 900;		pos.y = 300;		pos.z = 30;		pc->moveTo(pos); //player in an invalid location	}	setcharflag(pc);//AntiChrist}