Wandering Monster on Rest

What it does

Allows module creators to setup a table of wandering monsters, number to spawn in (max random), and a percentage chance for the adventurers to come across that monster that those monsters will spawn in during resting for each AREA in a module.


Basically, the "wandering" script goes in the OnRest() event for the MODULE. The "area_setup" script goes in the OnEnter() event for each area that you want to setup to have wandering monsters.

I have to give thanks to all the other scripters I have stolen from and pieced this together from. Namely, Matt Hawk had a great start on a similar script and that provided the base for my changes ****

Script, Part 1

wandering script (goes in OnRest event in module)

void main()
  object oPC = GetFirstPC();
  location lPCLoc = GetLocation(oPC);
  object oArea = GetAreaFromLocation(lPCLoc);

    // Get the AREA local variable with the chance of wandering monster encouter setting (against a D100 check)
  int nChanceofEncounter = GetLocalInt(oArea,"chance_encounter");
    if (d100() <= nChanceofEncounter)
         //Get the AREA number of monster types
        int nNumMonsterTypes = GetLocalInt(oArea,"num_monster_types");
         // Get random monster type
        int nMonsterType = Random(nNumMonsterTypes) + 1;

         //nMonsters is the number of monsters appearing; sMonsterType is the type
         //of monster appearing.  Use the BlueprintResRef for the monster you desire
         //to change this.  Should be stored in AREA local variables.
        string sVar = "monster_num" + IntToString(nMonsterType);
        int nMonsters = Random(GetLocalInt(oArea,sVar)) + 1;
        sVar = "monster_type" + IntToString(nMonsterType);
        string sMonsterType = GetLocalString(oArea,sVar);
   string sDebug = "Passed check on " + GetTag(oArea) + "\\\\\\\\n";
   sDebug += "The area has been set to have " + IntToString(GetLocalInt(oArea,"chance_encounter")) + "% wandering encounter\\\\\\\\n";
   sDebug += "The request is for " + IntToString(nNumMonsterTypes) + " different monster types\\\\\\\\n";
   sDebug += "Spawning " + IntToString(nMonsters) + " Monsters of type #" + IntToString(nMonsterType) + ": " + sMonsterType +"\\\\\\\\n";
   AssignCommand(oPC, ActionSpeakString(sDebug, TALKVOLUME_TALK));
         // Provide DEFAULT monster if non are set in the area
        if  (sMonsterType == "")
           sMonsterType = "goblina001";
         // Provide DEFAULT max number of monsters if non are set in the area
        if (nMonsters == 0)
           object oPartyMember = oPC;
           while (GetIsObjectValid(oPartyMember) == TRUE)
               // Set max default number to max number of PC's in party
              oPartyMember = GetNextPC();
         //This loop coming up creates as many monsters as nMonsters tells it to; they
         //appear within arm's reach of the rester and immediately attack.
         //The monsters appear immediately next to the PC, though they could appear
         //elsewhere.  Within the area would be more ideal, but I'm not sure how
         //you'd do it.
        while (nMonsters > 0)
            object oEnemy = CreateObject(OBJECT_TYPE_CREATURE, sMonsterType, lPCLoc, FALSE);
            AssignCommand(oEnemy, ActionAttack(oPC));
         //Whatever you put here appears in nice, floaty white text above the player who is attacked.
        AssignCommand(oPC, ActionSpeakString("Awaken!!!  We are under attack!!!", TALKVOLUME_TALK));

Script, Part 2

area_setup script (goes in OnEnter event for each area)

void InitializeArea()
   string sAreaName = GetTag(OBJECT_SELF);
   string sMonTypeVar = "monster_type";
   string sMonNumVar = "monster_num";
       // chance_encounter  is the % chance (d100) of an encounter in each area
       // num_monster_types  is the number of monster types that may randomly encounter
       // monster_type#  is the BLUEPRINT type in this area for each entry (1..num_monster_types)
       // monster_num#  is the max number of monsters to randomly spawn in on encounter
       // Place as many "area" tag checks as you need
   if (sAreaName == "OutsideStronghold") {
      SetLocalInt(OBJECT_SELF, "chance_encounter", 25);
      SetLocalInt(OBJECT_SELF, "num_monster_types", 3);
      SetLocalString(OBJECT_SELF, sMonTypeVar + "1", "ettin001");
      SetLocalInt(OBJECT_SELF, sMonNumVar + "1", 3);
      SetLocalString(OBJECT_SELF, sMonTypeVar + "2", "gnthill011");
      SetLocalInt(OBJECT_SELF, sMonNumVar + "2", 3);
      SetLocalString(OBJECT_SELF, sMonTypeVar + "3", "gnthill002");
      SetLocalInt(OBJECT_SELF, sMonNumVar + "3", 3);
   } else if (sAreaName == "UnderStronghold") {
      SetLocalInt(OBJECT_SELF, "chance_encounter", 55);
      SetLocalInt(OBJECT_SELF, "num_monster_types", 2);
      SetLocalString(OBJECT_SELF, sMonTypeVar + "1", "ettin001");
      SetLocalInt(OBJECT_SELF, sMonNumVar + "1", 6);
      SetLocalString(OBJECT_SELF, sMonTypeVar + "2", "gnthill011");
      SetLocalInt(OBJECT_SELF, sMonNumVar + "2", 6);
   object oPC = GetFirstPC();
   string sDebug = "This area is " + sAreaName + "\\\\\\\\n";
   sDebug += "The area has been set to have " + IntToString(GetLocalInt(OBJECT_SELF, "chance_encounter")) + "% wandering encounter\\\\\\\\n";
   AssignCommand(oPC, ActionSpeakString(sDebug, TALKVOLUME_TALK));
void main()

Ad blocker interference detected!

Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.