void main()
{
    // Wandering Monster Script as an OnEnter event
    // in a generic trigger

    // An object to hold the last player who entered the trigger
    object oPlayer = GetEnteringObject();
    location lHere = GetLocation(oPlayer);

    if (!GetIsPC(oPlayer)) return;

    int DoOnce = GetLocalInt(OBJECT_SELF, GetTag(OBJECT_SELF));

    if (DoOnce==TRUE) return;

    int nEnemyType = d10(); //Number of enemy monster types

    int nEnemy;
    object oEnemy;
    string sCreature;

    //Determine where the encounter will spawn (relative to the PC)
    int nDirection = d4();
    float fX;
    float fY;
    if (nDirection == 1)
     {
     fX=0.0;
     fY=5.0;
     }
    if (nDirection == 2)
     {
     fX=5.0;
     fY=0.0;
     }
    if (nDirection == 3)
     {
     fX=0.0;
     fY=-5.0;
     }
    if (nDirection == 4)
     {
     fX=-5.0;
     fY=0.0;;
     }

     vector vStart = GetPosition(oPlayer);
     vector vOffset = Vector(fX,fY);
     vector vEndvector = vStart + vOffset;
     lHere=Location(GetArea(oPlayer),vEndvector,GetFacing(oPlayer));

            //And here are the monsters in the Dungeon Level:
            if (nEnemyType == 1)
             {
             nEnemy = (d6()*3);
             sCreature = "giantcentipede";
             }
            else if (nEnemyType == 2)
             {
             nEnemy = 1;
             sCreature = "x2_gelcube";
             }
            else if (nEnemyType == 3)
             {
             nEnemy = d6();
             sCreature = "giantbadger";
             }
            else if (nEnemyType == 4)
             {
             nEnemy = d8();
             sCreature = "ghoul_wander";
             }
            else if (nEnemyType == 5)
             {
             nEnemy = d3();
             sCreature = "greenslimesmall";
             }
            else if (nEnemyType == 6)
             {
             nEnemy = d3();
             sCreature = "nw_grayooze";
             }
            else if (nEnemyType == 7)
             {
             nEnemy = d2();
             sCreature = "leucrotta";
             }
            else if (nEnemyType == 8)
             {
             nEnemy = d2();
             sCreature = "rustmonster";
             }
            else if (nEnemyType == 9)
             {
             nEnemy = 1;
             sCreature = "basilisk_wander";
             }
            else if (nEnemyType == 10)
             {
             nEnemy = d2();
             sCreature = "ogremage_wander";
             }
             // Create the monster(s) at the PC's location  and spawn as many
             // monsters at that location as is dictated by nEnemy
             int i;
             for (i = 1; i < (nEnemy+1); i++)
              {
              //FloatingTextStringOnCreature("In 'nEnemy' Loop", oPlayer);
              oEnemy = CreateObject(OBJECT_TYPE_CREATURE, sCreature, lHere, FALSE);
              }
SetLocalInt(OBJECT_SELF, GetTag(OBJECT_SELF), TRUE);
}
