Author Sticky: Post Working Scripts Here
Arckon Posted: Friday, 05 July 06:35AM
This is all derived from work dont by LuckDragon and others in the following thread:

Click Here

Thanks for all the trail blazing you guys do.

I have implemented the use of area encounter files to help make the system more maitainable and altered the generation code to allow for multiple monster types in a spawn.

This has been tested in a multiple area module built specifically for testing it. Beyond that, I can only say to use it at your own risk. I will help out however I can if bugs result, but I have little time.

This set up uses a module heartbeat script, an OnEnter event script placed in each area, and an included encounter file specific to each area.

The following goes into the module heartbeat script:

Code:
///////

//Module Heartbeat script

//:  

//: Based on work by LuckDragon and others, modified by RG Cheek 7-4-02

//////

#include "NW_O2_CONINCLUDE"

#include "AREA_1_TEST_ENC"    // Include all the area encounter files, one for each

void DoEncCheck (object oPlayer) {

  SpeakString( "Entered DoEncCheck", TALKVOLUME_TALK);

  if (!GetIsPC(oPlayer) || GetIsInCombat(oPlayer)) {

    return;

  }

  object thisplayArea = GetArea( oPlayer );

   // Test to see which area the player is in and call its encounter spawn proc

   // The tag is case sensitive.

  if ( thisplayArea == GetArea( GetObjectByTag( "Area_1_test" ))) {

          Area_1_test_Chk( oPlayer );

      }

}

void main() {

/// This is added to the end of any existing module heartbeat script, 

/// or just used as is for the module heart beat script



  object pc = GetFirstPC();

  int myCounter = GetLocalInt( pc, "EncChkCntr" );

// RNDS_TILL_ENC is DM defined to set how many rounds pass before checking for a respawn.

  int RNDS_TILL_ENC = 3;

  if (myCounter > RNDS_TILL_ENC) {

    myCounter = 0;

  }

  myCounter = myCounter + 1;

  SetLocalInt( pc, "EncChkCntr", myCounter);

  if (RNDS_TILL_ENC == myCounter) {

    myCounter=1;

    while (GetIsObjectValid(pc)) {

      DoEncCheck(pc);

      pc = GetNextPC();

    }

  }

}



The next part is an example of what goes into the area on entry event script:

Code:
///////

//: Area Entry script, put in OnEnter event for area.

//:  

//: Based on work by LuckDragon and others, modified by RG Cheek 7-4-02

///////

#include "NW_O2_CONINCLUDE"

#include "AREA_1_TEST_ENC"  // Include only the specific encounter file for this area



void main() {

  int count_areas = 0;

  object pc = GetFirstPC( );

  if ( GetIsPC( GetEnteringObject ( ) ) )   {  //Makes sure it's a PC entering the area (don't want looping scripts)

  //SpeakString( "Entered Main ", TALKVOLUME_SHOUT);

    while ( GetIsObjectValid( pc ) ) {

      object thisplayArea = GetArea( pc );

      if ( thisplayArea == GetArea( GetObjectByTag ("Area_1_test") ) ) {

      count_areas ++;

      }

      pc = GetNextPC();

    }

    if ( count_areas <= 1 ) {

      Area_1_test_Chk( pc );

    }

  }

}




The next is an area encounter file that is included by both the module heartbeat script and the area on entry script.

The following thread discusses how to use include files:

Click Here

Code:
/////////

//: This is the include file for generating the encounters for the specific area named.

//: It is capable of creating multiple creature types in each spawn. This script only 

//:  allows for up to 99 spawn points, the var NUM_SPAWNPOINTS is DM defined and 

//:  must exactly equal the number of spawn points used. 

//:  

//: Based on work by LuckDragon and others, modified by RG Cheek 7-4-02

void Area_1_test_Chk (object oPlayer) {

  int nNumMons, i;

  string creaturetype;

  int NUM_SPAWNPOINTS = 6;

  int SP_cntr;

  for ( SP_cntr=0; SP_cntr < NUM_SPAWNPOINTS; SP_cntr ++ )  {

    string SP_Num  =   IntToString (SP_cntr);

    if ( GetStringLength( SP_Num ) == 1 )

         SP_Num = "0" + SP_Num;

     //  "SP_Area_1_Test_" + SP_Num  is a simple convention for 

     //     distinguishing the spawn points

     //  "SP_Area_1_Test" is the area name

     //  SP_Num is the distinguishing spawn point number.

    string sSpawnPoint = "SP_Area_1_Test_" + SP_Num;

    object oTarget = GetWaypointByTag( sSpawnPoint );

    location lTargLoc =  GetLocation(oTarget);

      int nIsEncounter = d4(1);

      if (nIsEncounter == 1) {

        int nWhichMon = d2(1);  // max value should correspond to the number 

                                //   of case statements

        switch (nWhichMon) {

          case 1:

            nNumMons = d4(2);

            creaturetype = "nw_mepsalt";

            for (i=0;i<nNumMons;i++) {

              object oCreated = CreateObject( OBJECT_TYPE_CREATURE, creaturetype, lTargLoc, FALSE);

            }

            break;

          case 2:

            nNumMons = d4(1);

            creaturetype = "nw_bearblck";

            for (i=0;i<nNumMons;i++) {

              object oCreated = CreateObject( OBJECT_TYPE_CREATURE, creaturetype, lTargLoc, FALSE);

            }

            nNumMons = d2(1);

            creaturetype = "nw_boar";

            for (i=0;i<nNumMons;i++) {

              object oCreated = CreateObject( OBJECT_TYPE_CREATURE, creaturetype, lTargLoc, FALSE);

            }

            break;

        }

      }

  }  // End of While Loop



}