void main() { object oPC = GetEnteringObject(); if (GetIsPC(oPC) != TRUE) return; //:: Get own ID number string sSelf = GetTag(OBJECT_SELF); int iLength = GetStringLength(sSelf); string sID; int iChosen = 0; switch (iLength) { case 6: sID = GetStringRight(sSelf,1); break; case 7: sID = GetStringRight(sSelf,2); break; case 8: sID = GetStringRight(sSelf,3); break; } //SendMessageToPC(oPC,"my area ID is "+sID); int iMatch = GetLocalInt(OBJECT_SELF,"match"); //:: Current door's match string sEntryDir = GetStringLeft(GetTag(OBJECT_SELF),1); //:: Current door's direction string sExitDir; //:: This inverts the directions if (sEntryDir == "n") sExitDir="s"; else if (sEntryDir == "s") sExitDir="n"; else if (sEntryDir == "w") sExitDir="e"; else if (sEntryDir == "e") sExitDir="w"; //SendMessageToPC(oPC,"i should be on the "+sExitDir+" side of the map"); //:: Now determine if there is already a match if (iMatch != 0) //:: Door already has a match, teleport PC { //SendMessageToPC(oPC,"door has a match"); string sTag = "area4_"+IntToString(iMatch); object oArea = GetObjectByTag(sTag); object oTarget = GetObjectByTag("wp4_"+IntToString(iMatch)+sExitDir); location lTarget = GetLocation(oTarget); float fFace = GetFacing(oPC); AssignCommand(oPC,ActionJumpToLocation(lTarget)); AssignCommand(oPC,SetFacing(fFace)); iChosen = 1; return; } int iRand = Random(41)+1; //:: Random # for area selection string sTag = "area4_"+IntToString(iRand); object oArea = GetObjectByTag(sTag); int iUsed = GetLocalInt(oArea,"ispop"); float fFace = GetFacing(oPC); while (iChosen == 0)//selecting new areas { iRand = Random(41)+1; sTag = "area4_"+IntToString(iRand); oArea = GetObjectByTag(sTag); iUsed = GetLocalInt(oArea,"ispop"); if (iUsed == 0) { // SendMessageToPC(oPC,"unused area chosen"); object oTarget = GetObjectByTag("wp4_"+IntToString(iRand)+sExitDir); location lTarget = GetLocation(oTarget); AssignCommand(oPC,ActionJumpToLocation(lTarget)); AssignCommand(oPC,SetFacing(fFace)); SetLocalInt(oArea,"ispop",1); object oDoor = GetObjectByTag(sExitDir+"door"+IntToString(iRand)); SetLocalInt(OBJECT_SELF,"match",iRand); SetLocalInt(oDoor,"match",StringToInt(sID)); iChosen = 1; break; } //choose new area and try again until successful or TMI error } }