void main()
{

// register individual mobs

string sMob1="group01"; // RESREF OF MOB 1;
int MinMob1=1; // minimum number of mobs
int MaxMob1=3; // Maximum number of mobs

string sMob2="group02"; // RESREF OF MOB 2;
int MinMob2=1; // minimum number of mobs
int MaxMob2=3; // Maximum number of mobs

string sMob3="jw_darkenbeast"; // RESREF OF MOB 3;
int MinMob3=3; // minimum number of mobs
int MaxMob3=4; // Maximum number of mobs

string sMob4="group01"; // RESREF OF MOB 4;
int MinMob4=1; // minimum number of mobs
int MaxMob4=3; // Maximum number of mobs

string sMob5="group03"; // RESREF OF MOB 5;
int MinMob5=1; // minimum number of mobs
int MaxMob5=3; // Maximum number of mobs

string sMob6="jw_slasrath"; // RESREF OF MOB 6;
int MinMob6=2; // minimum number of mobs
int MaxMob6=5; // Maximum number of mobs

// register groups

if (GetLocalInt(OBJECT_SELF,"nDone")!=2)
{

SetLocalString(OBJECT_SELF, "group01_1", "jw_yun1");
SetLocalString(OBJECT_SELF, "group01_2", "jw_yun2");
SetLocalString(OBJECT_SELF, "group01_3", "jw_yun3");
SetLocalString(OBJECT_SELF, "group01_4", "jw_yun4");
SetLocalString(OBJECT_SELF, "group01_5", "jw_yun5");
/*
# Orcs 1
*/
SetLocalString(OBJECT_SELF, "group02_1", "jw_earth_nasty");
SetLocalString(OBJECT_SELF, "group02_2", "jw_elder_wat");
SetLocalString(OBJECT_SELF, "group02_3", "jw_elder_air");

SetLocalString(OBJECT_SELF, "group03_1", "jw_earth_nasty");
SetLocalString(OBJECT_SELF, "group03_2", "jw_elder_wat");
SetLocalString(OBJECT_SELF, "group03_3", "jw_elder_air");
SetLocalString(OBJECT_SELF, "group03_4", "jw_earth_nasty");
SetLocalString(OBJECT_SELF, "group03_5", "jw_earth_nasty");

SetLocalInt(OBJECT_SELF,"nDone",2);
}



object oPC=GetEnteringObject();

if ((!GetIsPC(oPC))&&(!GetIsPC(GetMaster(oPC))))
  {
   return;
  }

int nCurrentMinute = (GetCalendarYear()-1)*12*28*24 +
    (GetCalendarMonth()-1)*28*24 +
    (GetCalendarDay()-1)*24 +
    GetTimeHour();
    int nLastSpawnMinute = GetLocalInt(OBJECT_SELF,"LAST_SPAWN_MINUTE");

    // spawn delay is in real time minutes for some reason

    int nSpawnDelay = 0;
    if (nCurrentMinute > (nLastSpawnMinute + nSpawnDelay))
    {
       SetLocalInt(OBJECT_SELF,"NW_DO_ONCE",0);
    }

    //return if time has not passed yet
    if (GetLocalInt(OBJECT_SELF,"NW_DO_ONCE") != 0)
    {
       //SendMessageToAllDMs("Timer not yet done "+IntToString(nLastSpawnMinute)+" "+IntToString(nCurrentMinute));
       return;
    }





string sCounter;
int nIdx;
object oMob;
int nMobsexist=0;
string sMob="sMob";
string sCheckstring;
int nRandom;
string sMobtype;
int nMobMax; // maximum number of mobs
int nMobMin; // minimum number of mobs

// every trigger has a spawnpoint which is its own tag plus _SP

object oSpawnpoint=GetWaypointByTag(GetTag(OBJECT_SELF)+"_SP");
location lLoc=GetLocation(oSpawnpoint);

int nNumber=GetLocalInt(OBJECT_SELF,"nNumber");
// nNumber is the number of mobs spawned last time;


// if this is not the first time we have done it, check if any of our mobs are there
if (nNumber>0)

  {
       // start counting through the mobs
       for (nIdx=1; nIdx<=nNumber; nIdx++)
       {
         sCheckstring=sMob+IntToString(nIdx);

         // cycle through the local objects
         if (GetIsObjectValid(GetLocalObject(OBJECT_SELF,sCheckstring)))

           {
             // if one is valid, set nMobsexist to 1
             nMobsexist=1;
           }

       }

// if any of the old mobs still exist, return

if (nMobsexist==1)
   {
    // reset the counter, as players have entered the area while mobs are still present, and return
    SetLocalInt(OBJECT_SELF,"NW_DO_ONCE",1);
    SetLocalInt(OBJECT_SELF,"LAST_SPAWN_MINUTE",nCurrentMinute);
   //SendMessageToAllDMs("I have a mob already");
    return;
   }

  }

// a player has entered, no existing mobs exist and the timer is not yet complete. Therefore, make mobs.

// choose what type of mob to create

nRandom=Random(6);

switch (nRandom)
  {
   case 0: sMobtype=sMob1;
           nMobMax=MaxMob1;
           nMobMin=MinMob1;
           break;

   case 1: sMobtype=sMob2;
           nMobMax=MaxMob2;
           nMobMin=MinMob2;
           break;

   case 2: sMobtype=sMob3;
           nMobMax=MaxMob3;
           nMobMin=MinMob3;
           break;

    case 3: sMobtype=sMob4;
           nMobMax=MaxMob4;
           nMobMin=MinMob4;
           break;

    case 4: sMobtype=sMob5;
           nMobMax=MaxMob5;
           nMobMin=MinMob5;
           break;

    case 5: sMobtype=sMob6;
           nMobMax=MaxMob6;
           nMobMin=MinMob6;
           break;


  }
 /// set the number of mobs we are making
if (GetStringLeft(sMobtype,5)=="group")
{ // this is the section for making groups


int nMobnumber=0;
int nIdx=1;
int nValid=TRUE;
string sGroupname=GetStringLeft(sMobtype,7);
string sResRef;



while (nValid==TRUE)
       {
         sMobtype=sGroupname+"_"+IntToString(nIdx);
         sResRef=GetLocalString(OBJECT_SELF,sMobtype);



         if (sResRef=="")
         {
         nValid=FALSE;
         }
         else
         {
         // create the mob
         oMob=CreateObject(OBJECT_TYPE_CREATURE,sResRef,lLoc,FALSE);


         // make the mob act like an encounter creature
         SetLocalInt(oMob,"norw",2);

         // make the mob our new local object

         sCheckstring=sMob+IntToString(nIdx);
         SetLocalObject(OBJECT_SELF,sCheckstring,oMob);
         nIdx=nIdx+1;
         }
       }

 //set the time
    SetLocalInt(OBJECT_SELF,"NW_DO_ONCE",1);
    SetLocalInt(OBJECT_SELF,"LAST_SPAWN_MINUTE",nCurrentMinute);
    SetLocalInt(OBJECT_SELF,"nNumber",nIdx);

}


else {  // this is the section for making individual mobs
// choose how many mobs to create
int nRandomnumber=Random((nMobMax-nMobMin)+1);
int nMobnumber=nMobMin+nRandomnumber;



SetLocalInt(OBJECT_SELF,"nNumber",nMobnumber);

//SendMessageToAllDMs("Making my mobs now");

// start making the mobs
       for (nIdx=1; nIdx<=nMobnumber; nIdx++)
       {
         // create the mob
         oMob=CreateObject(OBJECT_TYPE_CREATURE,sMobtype,lLoc,FALSE);


         // make the mob act like an encounter creature
         SetLocalInt(oMob,"norw",2);

         // make the mob our new local object

         sCheckstring=sMob+IntToString(nIdx);
         SetLocalObject(OBJECT_SELF,sCheckstring,oMob);

       }

    //set the time
    SetLocalInt(OBJECT_SELF,"NW_DO_ONCE",1);
    SetLocalInt(OBJECT_SELF,"LAST_SPAWN_MINUTE",nCurrentMinute);

  // that is it
}

}