I use a similar principle in my campaign (depending on previous actions by the PC), but to achieve the results I wanted I use a trigger (which executes when the party tries to open the dear leading out).
I guess in your case you could use a script like the following one, executed when the PC enters a trigger located at the
void main()
{
object oPC = GetFirstPC();
object oArea = GetArea(oPC);
string sAreaTag = GetTag(oArea);
int nJustArrived = GetLocalInt(oArea, "nJustArrived");
// if we enter the trigger area coming from Area2, of course we don't want to go back to Area1. So let's just flag we arrived and do nothing else.
if (nJustArrived == 0)
{
SetLocalInt(oArea, "nJustArrived", 1);
}
else
{
if (sAreaTag == "Area3") // shouldn't be needed, since the trigger is only in Area3.
{
SetLocalInt(oArea, "nJustArrived", 0); // moving back to Area1, we tell the engine we're not in Area3 any more
object oWaypoint = GetObjectByTag("WP_Arrival_From_Area3"); // of course, this means there's a waypoint in Area1 where the party can go to!
AssignCommand(oPC, ActionJumpToLocation(GetLocation(oWaypoint)));
}
}
}
But maybe this one is more re-useable:
void main()
{
object oPC = GetEnteringObject();
if (oPC != GetFirstPC()) return; // we don't want other creatures wandering to Area1!
object oArea = GetArea(oPC);
int nJustArrived = GetLocalInt(oArea, "nJustArrived");
// if we enter the trigger area coming from Area2, of course we don't want to go back to Area1. So let's just flag we arrived and do nothing else.
if (nJustArrived == 0)
{
SetLocalInt(oArea, "nJustArrived", 1);
}
else
{
SetLocalInt(oArea, "nJustArrived", 0); // moving back to Area1, we tell the engine we're not in Area3 any more
string sLeadsTo = GetLocalString(oArea ,"sLeadsTo");
object oWaypoint = GetObjectByTag("sLeadsTo"); AssignCommand(oPC, ActionJumpToLocation(GetLocation(oWaypoint)))
}
}
Of course, it means the string variable sLeadsTo is defined in the area's properties, and set to the name of the waypoint to go to from Area3.