///////////////////////////////////////////////////////////////////////////// // Maranth Online - Generic Area Transition Script //=========================================================================== // By Deva Bryson Winblood and Dukar Rizulin. 02/28/2003 ///////////////////////////////////////////////////////////////////////////// string fnParse(string sIn) { // parse _ string sRet=""; string sWork=sIn; while(GetStringLength(sWork)>0&&GetStringLeft(sWork,1)!="_") { sRet=sRet+GetStringLeft(sWork,1); sWork=GetStringRight(sWork,GetStringLength(sWork)-1); } return sRet; } // fnParse() string fnRemParsed(string sO,string sP) { // return remainder of parsed string string sRet=""; if (GetStringLength(sO)>=GetStringLength(sP)) { // make sure valid request sRet=GetStringRight(sO,GetStringLength(sO)-GetStringLength(sP)); if (GetStringLeft(sRet,1)=="_") sRet=GetStringRight(sRet,GetStringLength(sRet)-1); } // make sure valid request return sRet; } // fnRemParsed() object fnGetDestinationWaypoint(object oArea,string sNum,string sDir) { // return the waypoint to go to object oRet=OBJECT_INVALID; string sWPName="MTRANS_"+sDir+sNum; int nCenter=StringToInt(sNum); int nTop=nCenter; int nBottom=nCenter; oRet=GetNearestObjectByTag(sWPName,oArea,1); if (oRet==OBJECT_INVALID) { // going to have to expand search while(nTop>1||nBottom<32&&oRet==OBJECT_INVALID) { // search for that waypoint nTop--; if (nTop<1) nTop=1; nBottom++; if (nBottom>32) nBottom=32; sWPName="MTRANS_"+sDir+IntToString(nTop); oRet=GetNearestObjectByTag(sWPName,oArea,1); if (oRet==OBJECT_INVALID) { // check bottom sWPName="MTRANS_"+sDir+IntToString(nBottom); oRet=GetNearestObjectByTag(sWPName,oArea,1); } // check bottom } // search for that waypoint } // going to have to expand search return oRet; } // fnGetDestinationWaypoint() //=================================================[ M A I N ]================= void main() { object oPC=GetClickingObject(); object oSourceWP=GetNearestObject(OBJECT_TYPE_WAYPOINT,oPC,1); int nC=1; int nCX,nCY,nCZ; // current area coordinates int nDX,nDY,nDZ; // destination area coordinates int nXX,nYY,nZZ; // Displacement values object oThisArea=GetArea(oPC); object oDestArea; object oDest; string sTag; string sATag; // area tag string sParsed; string sOpDir; // opposite direction // make sure you actually grabbed a MTRANS_ waypoint while(GetStringLeft(GetTag(oSourceWP),7)!="MTRANS_"&&nC<20) { // not a transition point get another nC++; oSourceWP=GetNearestObject(OBJECT_TYPE_WAYPOINT,oPC,nC); } // not a transition point get another sTag=GetTag(oSourceWP); if (GetStringLeft(sTag,7)=="MTRANS_") { // this is a valid tag sATag=GetTag(oThisArea); sParsed=fnParse(sATag); sATag=fnRemParsed(sATag,sParsed); nCX=StringToInt(sParsed); sParsed=fnParse(sATag); sATag=fnRemParsed(sATag,sParsed); nCY=StringToInt(sParsed); sParsed=fnParse(sATag); sATag=fnRemParsed(sATag,sParsed); nCZ=StringToInt(sParsed); sTag=GetStringRight(sTag,GetStringLength(sTag)-7); // strip MTRANS_ sParsed=GetStringLeft(sTag,1); if (sParsed=="W") nXX=-1; else if (sParsed=="E") { nXX=1; sOpDir="W"; } else if (sParsed=="N") { nYY=-1; sOpDir="S"; } else if (sParsed=="S") { nYY=1; sOpDir="N"; } else if (sParsed=="U") { nZZ=1; sOpDir="D"; } else if (sParsed=="D") { nZZ=-1; sOpDir="U"; } nDX=nXX+nCX; // get theoretical coordinates of adjacent area nDY=nYY+nCY; nDZ=nZZ+nCZ; sParsed=IntToString(nDX)+"_"+IntToString(nDY)+"_"+IntToString(nDZ); oDestArea=GetObjectByTag(sParsed); if (oDestArea!=OBJECT_INVALID) { // destination exists oDestArea=GetArea(oDestArea); // just in case it is not actually an area sTag=GetStringRight(sTag,GetStringLength(sTag)-1); // only need number now oDest=fnGetDestinationWaypoint(oDestArea,sTag,sOpDir); if (oDest!=OBJECT_INVALID) { // we have determined the destination AssignCommand(oPC,ClearAllActions()); AssignCommand(oPC,JumpToObject(oDest)); if (sOpDir=="W") AssignCommand(oPC,SetFacing(DIRECTION_EAST)); else if (sOpDir=="E") AssignCommand(oPC,SetFacing(DIRECTION_WEST)); else if (sOpDir=="S") AssignCommand(oPC,SetFacing(DIRECTION_NORTH)); else if (sOpDir=="N") AssignCommand(oPC,SetFacing(DIRECTION_SOUTH)); } // we have determined the destination } // destination exists } // this is a valid tag }