#include "re_custom0"
#include "re_custom1"
#include "re_custom2"
#include "re_custom3"
#include "re_custom4"
#include "re_custom5"
#include "re_custom6"
#include "re_custom7"
#include "re_custom8"
#include "re_custom9"
string GetRndEncCreature(float fMinCR = 0.0, float fMaxCR = 9999.0, string sCreatureTable = "")
{
// IF NOT INITIALIZED THEN DO SO
    if(!GetLocalInt(GetModule(), "bInitialized"))
        {
        //SetRndEncProperties();
        }

// DECLARE AND INTIALIZE VARIABLES
    object oMod = GetModule();
    if(sCreatureTable == "" || GetStringLowerCase(sCreatureTable) == "random")
        {
        sCreatureTable = GetStringLowerCase(GetLocalString(oMod, "sCreatureTable"));
        }
    string sChoice = "nil";
    int iCounter1;
    int iCounter2 = 0;
    int iCounter3;
    int iVarNum;
    float fCR;
    if (fMinCR > 18.0) fMinCR = 18.0;
    sCreatureTable = GetStringLowerCase(sCreatureTable);


// PICK RANDOM ANIMAL
    for(iCounter1 = 0; iCounter1 <= GetStringLength(sCreatureTable); iCounter1++)
        {
        if(GetSubString(sCreatureTable, iCounter1, 1) == "a")
            {
            while(sChoice != "")
                {
                switch(iCounter2)
                    {
                    case 0:sChoice = "NW_BEARDIREBOSS";
                    fCR = 19.0;
                    break;

                    case 1:sChoice = "NW_BEARBLCK";
                    fCR = 2.0;
                    break;

                    case 2:sChoice = "NW_BEARBRWN";
                    fCR = 5.0;
                    break;

                    case 3:sChoice = "NW_BEARDIRE";
                    fCR = 9.0;
                    break;

                    case 4:sChoice = "NW_BEARKODIAK";
                    fCR = 6.0;
                    break;

                    case 5:sChoice = "NW_BEARPOLAR";
                    fCR = 6.0;
                    break;

                    case 6:sChoice = "NW_CHICKEN";
                    fCR = 0.33;
                    break;

                    case 7:sChoice = "NW_RAPTOR001";
                    fCR = 0.5;
                    break;

                    case 8:sChoice = "NW_RAVEN";
                    fCR = 0.5;
                    break;

                    case 9:sChoice = "NW_DIREWOLF";
                    fCR = 5.0;
                    break;

                    case 10:sChoice = "NW_DOG";
                    fCR = 1.0;
                    break;

                    case 11:sChoice = "NW_WOLFDIREBOSS";
                    fCR = 15.0;
                    break;

                    case 12:sChoice = "NW_WOLFWINT";
                    fCR = 5.0;
                    break;

                    case 13:sChoice = "NW_WOLF";
                    fCR = 1.0;
                    break;

                    case 14:sChoice = "NW_WORG";
                    fCR = 3.0;
                    break;

                    case 15:sChoice = "NW_COUGAR";
                    fCR = 2.0;
                    break;

                    case 16:sChoice = "NW_CRAGCAT";
                    fCR = 3.0;
                    break;

                    case 17:sChoice = "NW_DIRETIGER";
                    fCR = 11.0;
                    break;

                    case 18:sChoice = "NW_JAGUAR";
                    fCR = 3.0;
                    break;

                    case 19:sChoice = "NW_CAT";
                    fCR = 2.0;
                    break;

                    case 20:sChoice = "NW_LION";
                    fCR = 4.0;
                    break;

                    case 21:sChoice = "NW_PANTHER";
                    fCR = 2.0;
                    break;

                    case 22:sChoice = "NW_BADGER";
                    fCR = 0.5;
                    break;

                    case 23:sChoice = "NW_BAT";
                    fCR = 0.33;
                    break;

                    case 24:sChoice = "NW_BOAR";
                    fCR = 03.0;
                    break;

                    case 25:sChoice = "NW_COW";
                    fCR = 0.25;
                    break;

                    case 26:sChoice = "NW_DEER";
                    fCR = 0.33;
                    break;

                    case 27:sChoice = "NW_DIREBADG";
                    fCR = 3.0;
                    break;

                    case 28:sChoice = "NW_BOARDIRE";
                    fCR = 5.0;
                    break;

                    case 29:sChoice = "NW_OX";
                    fCR = 0.5;
                    break;

                    case 30:sChoice = "NW_DEERSTAG";
                    fCR = 0.33;
                    break;

                    case 31:sChoice = "";
                    fCR = 0.0;
                    break;
                    }
                if(fCR >= fMinCR && fCR <= fMaxCR && sChoice != "")
                    {
                    SetLocalString(oMod, "sCreatureList" + IntToString(iVarNum), sChoice);
                    iVarNum++;
                    }
                iCounter2++;
                }
            }
        }
// PICK RANDOM CONSTRUCT
    for(iCounter1 = 0; iCounter1 <= GetStringLength(sCreatureTable); iCounter1++)
        {
        if(GetSubString(sCreatureTable, iCounter1, 1) == "c")
            {
            iCounter2 = 0; //Reset the counter
            sChoice = "nil"; //Reset sChoice
            while(sChoice != "")
                {
                switch(iCounter2)
                    {
                    case 0:sChoice = "NW_BATHORROR";
                    fCR = 11.0;
                    break;

                    case 1:sChoice = "NW_GolBone";
                    fCR = 12.0;
                    break;

                    case 2:sChoice = "NW_GolClay";
                    fCR = 12.0;
                    break;

                    case 3:sChoice = "NW_GOLFLESH";
                    fCR = 8.0;
                    break;

                    case 4:sChoice = "NW_HELMHORR";
                    fCR = 10.0;
                    break;

                    case 5:sChoice = "NW_GOLIRON";
                    fCR = 15.0;
                    break;

                    case 6:sChoice = "NW_MINOGON";
                    fCR = 7.0;
                    break;

                    case 7:sChoice = "NW_SHGUARD";
                    fCR = 12.0;
                    break;

                    case 8:sChoice = "NW_GOLSTONE";
                    fCR = 13.0;
                    break;

                    case 9:sChoice = "";
                    fCR = 0.0;
                    break;
                    }
                if(fCR >= fMinCR && fCR <= fMaxCR && sChoice != "")
                    {
                    SetLocalString(oMod, "sCreatureList" + IntToString(iVarNum), sChoice);
                    iVarNum++;
                    }
                iCounter2++;
                }
            }
        }
// PICK RANDOM DRAGON
    for(iCounter1 = 0; iCounter1 <= GetStringLength(sCreatureTable); iCounter1++)
        {
        if(GetSubString(sCreatureTable, iCounter1, 1) == "d")
            {
            iCounter2 = 0; //Reset the counter
            sChoice = "nil"; //Reset sChoice
            while(sChoice != "")
                {
                switch(iCounter2)
                    {
                    case 0:sChoice = "NW_DRGBLACK001";
                    fCR = 13.0;
                    break;

                    case 1:sChoice = "NW_DRGBLUE001";
                    fCR = 14.0;
                    break;

                    case 2:sChoice = "NW_DRGGREEN001";
                    fCR = 14.0;
                    break;

                    case 3:sChoice = "NW_DRGRED001";
                    fCR = 15.0;
                    break;

                    case 4:sChoice = "NW_DRGWHITE001";
                    fCR = 12.0;
                    break;

                    case 5:sChoice = "NW_DRGBLACK002";
                    fCR = 17.0;
                    break;

                    case 6:sChoice = "NW_DRGBLUE002";
                    fCR = 18.0;
                    break;

                    case 7:sChoice = "NW_DRGGREEN002";
                    fCR = 18.0;
                    break;

                    case 8:sChoice = "NW_DRGRED002";
                    fCR = 19.0;
                    break;

                    case 9:sChoice = "NW_DRGWHITE002";
                    fCR = 16.0;
                    break;

                    case 10:sChoice = "NW_DRGBLACK003";
                    fCR = 21.0;
                    break;

                    case 11:sChoice = "NW_DRGBLUE003";
                    fCR = 23.0;
                    break;

                    case 12:sChoice = "NW_DRGGREEN003";
                    fCR = 23.0;
                    break;

                    case 13:sChoice = "NW_DRGRED003";
                    fCR = 25.0;
                    break;

                    case 14:sChoice = "NW_HALFDRA001";
                    fCR = 13.0;
                    break;

                    case 15:sChoice = "";
                    fCR = 0.0;
                    break;
                    }
                if(fCR >= fMinCR && fCR <= fMaxCR && sChoice != "")
                    {
                    SetLocalString(oMod, "sCreatureList" + IntToString(iVarNum), sChoice);
                    iVarNum++;
                    }
                iCounter2++;
                }
            }
        }
// PICK RANDOM ELEMENTAL
    for(iCounter1 = 0; iCounter1 <= GetStringLength(sCreatureTable); iCounter1++)
        {
        if(GetSubString(sCreatureTable, iCounter1, 1) == "e")
            {
            iCounter2 = 0; //Reset the counter
            sChoice = "nil"; //Reset sChoice
            while(sChoice != "")
                {
                switch(iCounter2)
                    {
                    case 0:sChoice = "NW_AIR";
                    fCR = 4.0;
                    break;

                    case 1:sChoice = "NW_Earth";
                    fCR = 3.0;
                    break;

                    case 2:sChoice = "NW_AIRELDER";
                    fCR = 20.0;
                    break;

                    case 3:sChoice = "NW_EARTHELD";
                    fCR = 16.0;
                    break;

                    case 4:sChoice = "NW_FIREELDER";
                    fCR = 18.0;
                    break;

                    case 5:sChoice = "NW_WATELDER";
                    fCR = 17.0;
                    break;

                    case 6:sChoice = "NW_FIRE";
                    fCR = 3.0;
                    break;

                    case 7:sChoice = "NW_AIRGREAT";
                    fCR = 17.0;
                    break;

                    case 8:sChoice = "NW_EARTHGREAT";
                    fCR = 14.0;
                    break;

                    case 9:sChoice = "NW_FIREGREAT";
                    fCR = 16.0;
                    break;

                    case 10:sChoice = "NW_WATERGREAT";
                    fCR = 15.0;
                    break;

                    case 11:sChoice = "NW_AIRHUGE";
                    fCR = 13.0;
                    break;

                    case 12:sChoice = "NW_EARTHHUGE";
                    fCR = 11.0;
                    break;

                    case 13:sChoice = "NW_FIREHUGE";
                    fCR = 12.0;
                    break;

                    case 14:sChoice = "NW_WATERHUGE";
                    fCR = 12.0;
                    break;

                    case 15:sChoice = "NW_INVSTALK";
                    fCR = 6.0;
                    break;

                    case 16:sChoice = "NW_WATER";
                    fCR = 3.0;
                    break;

                    case 17:sChoice = "";
                    fCR = 0.0;
                    break;
                    }
                if(fCR >= fMinCR && fCR <= fMaxCR && GetStringLowerCase(sChoice) != "")
                    {
                    SetLocalString(oMod, "sCreatureList" + IntToString(iVarNum), sChoice);
                    iVarNum++;
                    }
                iCounter2++;
                }
            }
        }
// PICK RANDOM GIANT
    for(iCounter1 = 0; iCounter1 <= GetStringLength(sCreatureTable); iCounter1++)
        {
        if(GetSubString(sCreatureTable, iCounter1, 1) == "g")
            {
            iCounter2 = 0; //Reset the counter
            sChoice = "nil"; //Reset sChoice
            while(sChoice != "")
                {
                switch(iCounter2)
                    {
                    case 0:sChoice = "NW_ETTIN";
                    fCR = 8.0;
                    break;

                    case 1:sChoice = "NW_GNTHILL";
                    fCR = 10.0;
                    break;

                    case 2:sChoice ="NW_GNTMOUNT";
                    fCR = 10.0;
                    break;

                    case 3:sChoice = "NW_GNTFIRE";
                    fCR = 12.0;
                    break;

                    case 4:sChoice = "NW_GNTFROST";
                    fCR = 10.0;
                    break;

                    case 5:sChoice = "NW_OGRE01";
                    fCR = 3.0;
                    break;

                    case 6:sChoice = "NW_OGRE02";
                    fCR = 3.0;
                    break;

                    case 7:sChoice = "NW_OGRECHIEF01";
                    fCR = 6.0;
                    break;

                    case 8:sChoice = "NW_OGRECHIEF02";
                    fCR = 6.0;
                    break;

                    case 9:sChoice = "nw_ogreboss";
                    fCR = 9.0;
                    break;

                    case 10:sChoice = "NW_OGREMAGEBOSS";
                    fCR = 21.0;
                    break;

                    case 11:sChoice = "NW_OGREMAGE01";
                    fCR = 5.0;
                    break;

                    case 12:sChoice = "NW_OGREMAGE02";
                    fCR = 5.0;
                    break;

                    case 13:sChoice = "NW_TROLL";
                    fCR = 5.0;
                    break;

                    case 14:sChoice = "NW_TROLLCHIEF";
                    fCR = 8.0;
                    break;

                    case 15:sChoice = "NW_TROLLBOSS";
                    fCR = 9.0;
                    break;

                    case 16:sChoice = "NW_TROLLWIZ";
                    fCR = 8.0;
                    break;

                    case 17:sChoice = "";
                    fCR = 0.0;
                    break;
                    }
                if(fCR >= fMinCR && fCR <= fMaxCR && GetStringLowerCase(sChoice) != "")
                    {
                    SetLocalString(oMod, "sCreatureList" + IntToString(iVarNum), sChoice);
                    iVarNum++;
                    }
                iCounter2++;
                }
            }
        }
// PICK RANDOM HUMANOID
    for(iCounter1 = 0; iCounter1 <= GetStringLength(sCreatureTable); iCounter1++)
        {
        if(GetSubString(sCreatureTable, iCounter1, 1) == "h")
            {
            iCounter2 = 0; //Reset the counter
            sChoice = "nil"; //Reset sChoice
            while(sChoice != "")
                {
                switch(iCounter2)
                    {
                    case 0:sChoice = "NW_BUGBEARA";
                    fCR = 2.0;
                    break;

                    case 1:sChoice = "NW_BUGBEARB";
                    fCR = 2.0;
                    break;

                    case 2:sChoice = "nw_bugbearboss";
                    fCR = 10.0;
                    break;

                    case 3:sChoice = "NW_BUGCHIEFA";
                    fCR = 5.0;
                    break;

                    case 4:sChoice = "NW_BUGCHIEFB";
                    fCR = 5.0;
                    break;

                    case 5:sChoice = "NW_BUGCHIEFB";
                    fCR = 4.0;
                    break;

                    case 6:sChoice = "NW_BUGCHIEFB";
                    fCR = 4.0;
                    break;

                    case 7:sChoice = "NW_GRIG";
                    fCR = 2.0;
                    break;

                    case 8:sChoice = "NW_PIXIE";
                    fCR = 2.0;
                    break;

                    case 9:sChoice = "NW_GOBLINA";
                    fCR = 0.25;
                    break;

                    case 10:sChoice = "NW_GOBLINB";
                    fCR = 0.25;
                    break;

                    case 11:sChoice = "NW_GOBLINBOSS";
                    fCR = 11.0;
                    break;

                    case 12:sChoice = "NW_GOBCHIEFA";
                    fCR = 4.0;
                    break;

                    case 13:sChoice = "NW_GOBCHIEFB";
                    fCR = 3.0;
                    break;

                    case 14:sChoice = "NW_GOBWIZA";
                    fCR = 3.0;
                    break;

                    case 15:sChoice = "NW_GOBWIZB";
                    fCR = 3.0;
                    break;

                    case 16:sChoice = "NW_OLDCHIEFA";
                    fCR = 4.0;
                    break;

                    case 17:sChoice = "NW_OLDCHIEFB";
                    fCR = 4.0;
                    break;

                    case 19:sChoice = "NW_OLDMAGEA";
                    fCR = 4.0;
                    break;

                    case 20:sChoice = "NW_OLDMAGEB";
                    fCR = 4.0;
                    break;

                    case 21:sChoice = "NW_OLDWARB";
                    fCR = 2.0;
                    break;

                    case 22:sChoice = "NW_OLDWARRA";
                    fCR = 2.0;
                    break;

                    case 23:sChoice = "NW_YUAN_TI001";
                    fCR = 5.0;
                    break;

                    case 24:sChoice = "NW_YUAN_TI003";
                    fCR = 6.0;
                    break;

                    case 25:sChoice = "NW_YUAN_TI002";
                    fCR = 5.0;
                    break;

                    case 26:sChoice = "NW_MINOTAUR";
                    fCR = 4.0;
                    break;

                    case 27:sChoice = "NW_MinChief";
                    fCR = 8.0;
                    break;

                    case 28:sChoice = "NW_MINOTAURBOSS";
                    fCR = 14.0;
                    break;

                    case 29:sChoice = "NW_MINWIZ";
                    fCR = 9.0;
                    break;

                    case 30:sChoice = "NW_ORCA";
                    fCR = 0.25;
                    break;

                    case 31:sChoice = "NW_ORCB";
                    fCR = 0.25;
                    break;

                    case 32:sChoice = "NW_OrcChiefA";
                    fCR = 3.0;
                    break;

                    case 33:sChoice = "NW_ORCCHIEFB";
                    fCR = 3.0;
                    break;

                    case 34:sChoice = "nw_orcboss";
                    fCR = 10.0;
                    break;

                    case 35:sChoice = "NW_ORCWIZA";
                    fCR = 4.0;
                    break;

                    case 36:sChoice = "NW_ORCWIZB";
                    fCR = 4.0;
                    break;

                    case 37:sChoice = "";
                    fCR = 0.0;
                    break;
                    }
                if(fCR >= fMinCR && fCR <= fMaxCR && GetStringLowerCase(sChoice) != "")
                    {
                    SetLocalString(oMod, "sCreatureList" + IntToString(iVarNum), sChoice);
                    iVarNum++;
                    }
                iCounter2++;
                }
            }
        }
// PICK RANDOM INSECT
    for(iCounter1 = 0; iCounter1 <= GetStringLength(sCreatureTable); iCounter1++)
        {
        if(GetSubString(sCreatureTable, iCounter1, 1) == "i")
            {
            iCounter2 = 0; //Reset the counter
            sChoice = "nil"; //Reset sChoice
            while(sChoice != "")
                {
                switch(iCounter2)
                    {
                    case 0:sChoice = "NW_BTLBOMB";
                    fCR = 3.0;
                    break;

                    case 1:sChoice = "NW_BTLFIRE";
                    fCR = 0.25;
                    break;

                    case 2:sChoice = "nw_beetleboss";
                    fCR = 15.0;
                    break;

                    case 3:sChoice = "NW_BTLFIRE02";
                    fCR = 2.0;
                    break;

                    case 4:sChoice = "NW_BTLSTAG";
                    fCR = 5.0;
                    break;

                    case 5:sChoice = "NW_BTLSTINK";
                    fCR = 3.0;
                    break;

                    case 6:sChoice = "NW_SPIDDIRE";
                    fCR = 7.0;
                    break;

                    case 7:sChoice = "NW_SPIDGIANT";
                    fCR = 3.0;
                    break;

                    case 8:sChoice = "NW_SPIDPHASE";
                    fCR = 4.0;
                    break;

                    case 9:sChoice = "NW_SPIDERBOSS";
                    fCR = 13.0;
                    break;

                    case 10:sChoice = "NW_SPIDSWRD";
                    fCR = 4.0;
                    break;

                    case 11:sChoice = "NW_SPIDWRA";
                    fCR = 4.0;
                    break;

                    case 12:sChoice = "";
                    fCR = 0.0;
                    break;
                    }
                if(fCR >= fMinCR && fCR <= fMaxCR && GetStringLowerCase(sChoice) != "")
                    {
                    SetLocalString(oMod, "sCreatureList" + IntToString(iVarNum), sChoice);
                    iVarNum++;
                    }
                iCounter2++;
                }
            }
        }
// PICK RANDOM MISCELLANEOUS
    for(iCounter1 = 0; iCounter1 <= GetStringLength(sCreatureTable); iCounter1++)
        {
        if(GetSubString(sCreatureTable, iCounter1, 1) == "m")
            {
            iCounter2 = 0; //Reset the counter
            sChoice = "nil"; //Reset sChoice
            while(sChoice != "")
                {
                switch(iCounter2)
                    {
                    case 0:sChoice = "NW_BATTDEVOUR";
                    fCR = 11.0;
                    break;

                    case 1:sChoice = "NW_ETTERCAP";
                    fCR = 4.0;
                    break;

                    case 2:sChoice = "NW_GARGOYLE";
                    fCR = 3.0;
                    break;

                    case 3:sChoice = "NW_GRAYREND";
                    fCR = 8.0;
                    break;

                    case 4:sChoice = "NW_HORROR";
                    fCR = 4.0;
                    break;

                    case 5:sChoice = "NW_DEVOUR";
                    fCR = 6.0;
                    break;

                    case 6:sChoice = "NW_KRENSHAR";
                    fCR = 2.0;
                    break;

                    case 7:sChoice = "NW_STIRGE";
                    fCR = 0.33;
                    break;

                    case 8:sChoice = "NW_UMBERHULK";
                    fCR = 7.0;
                    break;

                    case 9:sChoice = "NW_WILLOWISP";
                    fCR = 8.0;
                    break;

                    case 10:sChoice = "";
                    fCR = 0.0;
                    break;
                    }
                if(fCR >= fMinCR && fCR <= fMaxCR && GetStringLowerCase(sChoice) != "")
                    {
                    SetLocalString(oMod, "sCreatureList" + IntToString(iVarNum), sChoice);
                    iVarNum++;
                    }
                iCounter2++;
                }
            }
        }
// PICK RANDOM PLANAR
    for(iCounter1 = 0; iCounter1 <= GetStringLength(sCreatureTable); iCounter1++)
        {
        if(GetSubString(sCreatureTable, iCounter1, 1) == "p")
            {
            iCounter2 = 0; //Reset the counter
            sChoice = "nil"; //Reset sChoice
            while(sChoice != "")
                {
                switch(iCounter2)
                    {
                    case 0:sChoice = "NW_DEMON";
                    fCR = 18.0;
                    break;

                    case 1:sChoice = "NW_HALFFND001";
                    fCR = 12.0;
                    break;

                    case 2:sChoice = "NW_HELLHOUND";
                    fCR = 3.0;
                    break;

                    case 3:sChoice = "NW_BEASTXVIM";
                    fCR = 5.0;
                    break;

                    case 4:sChoice = "NW_RAKSHASA";
                    fCR = 8.0;
                    break;

                    case 5:sChoice = "NW_SHMASTIF";
                    fCR = 0.0;
                    break;

                    case 6:sChoice = "NW_DMSUCUBUS";
                    fCR = 7.0;
                    break;

                    case 7:sChoice = "NW_DMVROCK";
                    fCR = 11.0;
                    break;

                    case 8:sChoice = "NW_MEPAIR";
                    fCR = 3.0;
                    break;

                    case 9:sChoice = "NW_MEPDUST";
                    fCR = 2.0;
                    break;

                    case 10:sChoice = "NW_MEPEARTH";
                    fCR = 3.0;
                    break;

                    case 11:sChoice = "NW_MEPFIRE";
                    fCR = 3.0;
                    break;

                    case 12:sChoice = "NW_MEPICE";
                    fCR = 3.0;
                    break;

                    case 13:sChoice = "NW_IMP";
                    fCR = 3.0;
                    break;

                    case 14:sChoice = "NW_MEPMAGMA";
                    fCR = 3.0;
                    break;

                    case 15:sChoice = "NW_MEPOOZE";
                    fCR = 3.0;
                    break;

                    case 16:sChoice = "NW_DMQUASIT";
                    fCR = 3.0;
                    break;

                    case 17:sChoice = "NW_MEPSALT";
                    fCR = 3.0;
                    break;

                    case 19:sChoice = "NW_MEPSTEAM";
                    fCR = 3.0;
                    break;

                    case 20:sChoice = "NW_MEPWATER";
                    fCR = 3.0;
                    break;

                    case 21:sChoice = "NW_TIEFLING02";
                    fCR = 0.5;
                    break;

                    case 22:sChoice = "NW_SLAADBL";
                    fCR = 7.0;
                    break;

                    case 23:sChoice = "NW_SLAADDETH";
                    fCR = 15.0;
                    break;

                    case 24:sChoice = "NW_SLAADDTHBOSS";
                    fCR = 15.0;
                    break;

                    case 25:sChoice = "NW_SLAADGRAY";
                    fCR = 10.0;
                    break;

                    case 26:sChoice = "NW_SLAADGRYBOSS";
                    fCR = 10.0;
                    break;

                    case 27:sChoice = "NW_SLAADGRN";
                    fCR = 8.0;
                    break;

                    case 28:sChoice = "NW_SLAADRED";
                    fCR = 6.0;
                    break;

                    case 29:sChoice = "";
                    fCR = 0.0;
                    break;
                    }
                if(fCR >= fMinCR && fCR <= fMaxCR && GetStringLowerCase(sChoice) != "")
                    {
                    SetLocalString(oMod, "sCreatureList" + IntToString(iVarNum), sChoice);
                    iVarNum++;
                    }
                iCounter2++;
                }
            }
        }
// PICK RANDOM SHAPECHANGER
    for(iCounter1 = 0; iCounter1 <= GetStringLength(sCreatureTable); iCounter1++)
        {
        if(GetSubString(sCreatureTable, iCounter1, 1) == "s")
            {
            iCounter2 = 0; //Reset the counter
            sChoice = "nil"; //Reset sChoice
            while(sChoice != "")
                {
                switch(iCounter2)
                    {
                    case 0:sChoice = "NW_ARANEA";
                    fCR = 3.0;
                    break;

                    case 1:sChoice = "NW_WERECAT";
                    fCR = 5.0;
                    break;

                    case 2:sChoice = "NW_WERERAT001";
                    fCR = 0.5;
                    break;

                    case 3:sChoice = "NW_WEREWOLF";
                    fCR = 2.0;
                    break;

                    case 4:sChoice = "NW_WERERAT";
                    fCR = 0.5;
                    break;

                    case 5:sChoice = "";
                    fCR = 0.0;
                    break;
                    }
                if(fCR >= fMinCR && fCR <= fMaxCR && GetStringLowerCase(sChoice) != "")
                    {
                    SetLocalString(oMod, "sCreatureList" + IntToString(iVarNum), sChoice);
                    iVarNum++;
                    }
                iCounter2++;
                }
            }
        }
// PICK RANDOM UNDEAD
    for(iCounter1 = 0; iCounter1 <= GetStringLength(sCreatureTable); iCounter1++)
        {
        if(GetSubString(sCreatureTable, iCounter1, 1) == "u")
            {
            iCounter2 = 0; //Reset the counter
            sChoice = "nil"; //Reset sChoice
            while(sChoice != "")
                {
                switch(iCounter2)
                    {
                    case 0:sChoice = "NW_GHAST";
                    fCR = 4.0;
                    break;

                    case 1:sChoice = "NW_GHOUL";
                    fCR = 2.0;
                    break;

                    case 2:sChoice = "NW_GHOULLORD";
                    fCR = 5.0;
                    break;

                    case 3:sChoice = "NW_GHOULBOSS";
                    fCR = 9.0;
                    break;

                    case 4:sChoice = "NW_MUMCLERIC";
                    fCR = 12.0;
                    break;

                    case 5:sChoice = "NW_MUMMY";
                    fCR = 6.0;
                    break;

                    case 6:sChoice = "NW_MUMMYBOSS";
                    fCR = 13.0;
                    break;

                    case 7:sChoice = "NW_MUMFIGHT";
                    fCR = 12.0;
                    break;

                    case 8:sChoice = "NW_LICH002";
                    fCR = 19.0;
                    break;

                    case 9:sChoice = "NW_Bodak";
                    fCR = 9.0;
                    break;

                    case 10:sChoice = "NW_CURST004";
                    fCR = 7.0;
                    break;

                    case 11:sChoice = "NW_CURST003";
                    fCR = 4.0;
                    break;

                    case 12:sChoice = "NW_CURST002";
                    fCR = 5.0;
                    break;

                    case 13:sChoice = "NW_CURST001";
                    fCR = 6.0;
                    break;

                    case 14:sChoice = "NW_DOOMKGHT";
                    fCR = 9.0;
                    break;

                    case 15:sChoice = "NW_DOOMKGHTBOSS";
                    fCR = 12.0;
                    break;

                    case 16:sChoice = "NW_LICH001";
                    fCR = 27.0;
                    break;

                    case 17:sChoice = "NW_LICH003";
                    fCR = 18.0;
                    break;

                    case 19:sChoice = "NW_LICHBOSS";
                    fCR = 21.0;
                    break;

                    case 20:sChoice = "NW_MOHRG";
                    fCR = 10.0;
                    break;

                    case 21:sChoice = "NW_REVENANT001";
                    fCR = 11.0;
                    break;

                    case 22:sChoice = "NW_SKELDEVOUR";
                    fCR = 13.0;
                    break;

                    case 23:sChoice = "NW_VAMPIRE";
                    fCR = 7.0;
                    break;

                    case 24:sChoice = "NW_VAMPIRE003";
                    fCR = 12.0;
                    break;

                    case 25:sChoice = "NW_VAMPIRE004";
                    fCR = 13.0;
                    break;

                    case 26:sChoice = "NW_VAMPIRE002";
                    fCR = 10.0;
                    break;

                    case 27:sChoice = "NW_VAMPIRE001";
                    fCR = 12.0;
                    break;

                    case 28:sChoice = "NW_WIGHT";
                    fCR = 3.0;
                    break;

                    case 29:sChoice = "NW_VAMPIRE_SHAD";
                    fCR = 3.0;
                    break;

                    case 30:sChoice = "NW_SHADOW";
                    fCR = 3.0;
                    break;

                    case 31:sChoice = "NW_SHFIEND";
                    fCR = 7.0;
                    break;

                    case 32:sChoice = "NW_SKELETON";
                    fCR = 0.5;
                    break;

                    case 33:sChoice = "NW_SKELCHIEF";
                    fCR = 9.0;
                    break;

                    case 34:sChoice = "NW_SKELMAGE";
                    fCR = 4.0;
                    break;

                    case 35:sChoice = "NW_SKELPRIEST";
                    fCR = 4.0;
                    break;

                    case 36:sChoice = "NW_SKELWARR01";
                    fCR = 8.0;
                    break;

                    case 37:sChoice = "NW_SKELWARR02";
                    fCR = 8.0;
                    break;

                    case 38:sChoice = "NW_ALLIP";
                    fCR = 4.0;
                    break;

                    case 39:sChoice = "NW_SPECTRE";
                    fCR = 6.0;
                    break;

                    case 40:sChoice = "NW_WRAITH";
                    fCR = 5.0;
                    break;

                    case 41:sChoice = "NW_ZOMBTYRANT";
                    fCR = 3.0;
                    break;

                    case 42:sChoice = "NW_ZOMBIE01";
                    fCR = 1.0;
                    break;

                    case 43:sChoice = "NW_ZOMBIE02";
                    fCR = 1.0;
                    break;

                    case 44:sChoice = "NW_ZOMBIEBOSS";
                    fCR = 6.0;
                    break;

                    case 45:sChoice = "NW_ZOMBWARR01";
                    fCR = 3.0;
                    break;

                    case 46:sChoice = "NW_ZOMBWARR02";
                    fCR = 3.0;
                    break;

                    case 47:sChoice = "";
                    fCR = 0.0;
                    break;
                    }
                if(fCR >= fMinCR && fCR <= fMaxCR && GetStringLowerCase(sChoice) != "")
                    {
                    SetLocalString(oMod, "sCreatureList" + IntToString(iVarNum), sChoice);
                    iVarNum++;
                    }
                iCounter2++;
                }
            }
        }
// PICK RANDOM BANDIT
    for(iCounter1 = 0; iCounter1 <= GetStringLength(sCreatureTable); iCounter1++)
        {
        if(GetSubString(sCreatureTable, iCounter1, 1) == "b")
            {
            iCounter2 = 0; //Reset the counter
            sChoice = "nil"; //Reset sChoice
            while(sChoice != "")
                {
                switch(iCounter2)
                    {
                    case 0:sChoice = "NW_DUECLER001";
                    fCR = 1.0;
                    break;

                    case 1:sChoice = "NW_DUECLER005";
                    fCR = 5.0;
                    break;

                    case 2:sChoice = "NW_DUECLER010";
                    fCR = 8.0;
                    break;

                    case 3:sChoice = "NW_DUECLER015";
                    fCR = 10.0;
                    break;

                    case 4:sChoice = "NW_DUECLER020";
                    fCR = 15.0;
                    break;

                    case 5:sChoice = "NW_DUEMAGE001";
                    fCR = 1.0;
                    break;

                    case 6:sChoice = "NW_DUEMAGE005";
                    fCR = 4.0;
                    break;

                    case 7:sChoice = "NW_DUEMAGE010";
                    fCR = 7.0;
                    break;

                    case 8:sChoice = "NW_DUEMAGE015";
                    fCR = 11.0;
                    break;

                    case 9:sChoice = "NW_DUEMAGE020";
                    fCR = 14.0;
                    break;

                    case 10:sChoice = "NW_DUEROGUE001";
                    fCR = 1.0;
                    break;

                    case 11:sChoice = "NW_DUEROGUE005";
                    fCR = 4.0;
                    break;

                    case 12:sChoice = "NW_DUEROGUE010";
                    fCR = 7.0;
                    break;

                    case 13:sChoice = "NW_DUEROGUE015";
                    fCR = 10.0;
                    break;

                    case 14:sChoice = "NW_DUEROGUE020";
                    fCR = 13.0;
                    break;

                    case 15:sChoice = "NW_DUEFIGHT001";
                    fCR = 1.0;
                    break;

                    case 16:sChoice = "NW_DUEFIGHT005";
                    fCR = 4.0;
                    break;

                    case 17:sChoice = "NW_DUEFIGHT010";
                    fCR = 7.0;
                    break;

                    case 19:sChoice = "NW_DUEFIGHT015";
                    fCR = 11.0;
                    break;

                    case 20:sChoice = "NW_DUEFIGHT020";
                    fCR = 14.0;
                    break;

                    case 21:sChoice = "NW_DWARFMERC001";
                    fCR = 0.5;
                    break;

                    case 22:sChoice = "NW_DWARFMERC002";
                    fCR = 2.0;
                    break;

                    case 23:sChoice = "NW_DWARFMERC003";
                    fCR = 4.0;
                    break;

                    case 24:sChoice = "NW_DWARFMERC004";
                    fCR = 7.0;
                    break;

                    case 25:sChoice = "NW_DWARFMERC005";
                    fCR = 9.0;
                    break;

                    case 26:sChoice = "NW_DWARFMERC006";
                    fCR = 13.0;
                    break;

                    case 27:sChoice = "NW_DROWROGUE001";
                    fCR = 1.0;
                    break;

                    case 28:sChoice = "NW_DROWROGUE005";
                    fCR = 3.0;
                    break;

                    case 29:sChoice = "NW_DROWROGUE010";
                    fCR = 7.0;
                    break;

                    case 30:sChoice = "NW_DROWROGUE015";
                    fCR = 10.0;
                    break;

                    case 31:sChoice = "NW_DROWROGUE020";
                    fCR = 13.0;
                    break;

                    case 33:sChoice = "NW_DROWMAGE001";
                    fCR = 1.0;
                    break;

                    case 34:sChoice = "NW_DROWMAGE005";
                    fCR = 4.0;
                    break;

                    case 35:sChoice = "NW_DROWMAGE010";
                    fCR = 7.0;
                    break;

                    case 36:sChoice = "NW_DROWMAGE015";
                    fCR = 11.0;
                    break;

                    case 37:sChoice = "NW_DROWMAGE020";
                    fCR = 15.0;
                    break;

                    case 38:sChoice = "NW_DROWFIGHT001";
                    fCR = 1.0;
                    break;

                    case 39:sChoice = "NW_DROWFIGHT005";
                    fCR = 4.0;
                    break;

                    case 40:sChoice = "NW_DROWFIGHT010";
                    fCR = 8.0;
                    break;

                    case 41:sChoice = "NW_DROWFIGHT015";
                    fCR = 11.0;
                    break;

                    case 42:sChoice = "NW_DROWFIGHT020";
                    fCR = 15.0;
                    break;

                    case 43:sChoice = "NW_DROWCLER001";
                    fCR = 1.0;
                    break;

                    case 44:sChoice = "NW_DROWCLER005";
                    fCR = 4.0;
                    break;

                    case 45:sChoice = "NW_DROWCLER010";
                    fCR = 8.0;
                    break;

                    case 46:sChoice = "NW_DROWCLER015";
                    fCR = 12.0;
                    break;

                    case 47:sChoice = "NW_DROWCLER020";
                    fCR = 16.0;
                    break;

                    case 48:sChoice = "NW_HALFMERC001";
                    fCR = 1.0;
                    break;

                    case 49:sChoice = "NW_HALFMERC002";
                    fCR = 3.0;
                    break;

                    case 50:sChoice = "NW_HALFMERC003";
                    fCR = 5.0;
                    break;

                    case 51:sChoice = "NW_HALFMERC004";
                    fCR = 7.0;
                    break;

                    case 52:sChoice = "NW_HALFMERC005";
                    fCR = 10.0;
                    break;

                    case 53:sChoice = "NW_HALFMERC006";
                    fCR = 13.0;
                    break;

                    case 54:sChoice = "NW_BANDIT006";
                    fCR = 7.0;
                    break;

                    case 55:sChoice = "NW_BANDIT001";
                    fCR = 0.5;
                    break;

                    case 56:sChoice = "NW_BANDIT002";
                    fCR = 0.5;
                    break;

                    case 57:sChoice = "NW_BANDIT007";
                    fCR = 11.0;
                    break;

                    case 58:sChoice = "NW_BANDIT004";
                    fCR = 3.0;
                    break;

                    case 59:sChoice = "NW_BANDIT005";
                    fCR = 4.0;
                    break;

                    case 60:sChoice = "NW_BANDIT003";
                    fCR = 1.0;
                    break;

                    case 61:sChoice = "NW_GYPSY006";
                    fCR = 11.0;
                    break;

                    case 62:sChoice = "NW_GYPSY005";
                    fCR = 8.0;
                    break;

                    case 63:sChoice = "NW_GYPSY004";
                    fCR = 4.0;
                    break;

                    case 64:sChoice = "NW_GYPSY007";
                    fCR = 10.0;
                    break;

                    case 65:sChoice = "NW_GYPSY002";
                    fCR = 0.5;
                    break;

                    case 66:sChoice = "NW_GYPSY001";
                    fCR = 0.5;
                    break;

                    case 67:sChoice = "NW_GYPSY003";
                    fCR = 4.0;
                    break;

                    case 68:sChoice = "NW_GYPFEMALE";
                    fCR = 0.25;
                    break;

                    case 69:sChoice = "NW_GYPMALE";
                    fCR = 0.25;
                    break;

                    case 70:sChoice = "NW_HUMANMERC001";
                    fCR = 2.0;
                    break;

                    case 71:sChoice = "NW_HUMANMERC002";
                    fCR = 3.0;
                    break;

                    case 72:sChoice = "NW_HUMANMERC003";
                    fCR = 6.0;
                    break;

                    case 73:sChoice = "NW_HUMANMERC004";
                    fCR = 9.0;
                    break;

                    case 74:sChoice = "NW_HUMANMERC005";
                    fCR = 12.0;
                    break;

                    case 75:sChoice = "NW_HUMANMERC006";
                    fCR = 15.0;
                    break;

                    case 76:sChoice = "";
                    fCR = 0.0;
                    break;
                    }
                if(fCR >= fMinCR && fCR <= fMaxCR && GetStringLowerCase(sChoice) != "")
                    {
                    SetLocalString(oMod, "sCreatureList" + IntToString(iVarNum), sChoice);
                    iVarNum++;
                    }
                iCounter2++;
                }
            }
        }
// PICK RANDOM CREATURE FROM CUSTOM TABLE 0
    for(iCounter1 = 0; iCounter1 <= GetStringLength(sCreatureTable); iCounter1++)
        {
        if(GetSubString(sCreatureTable, iCounter1, 1) == "0")
            {
            iVarNum = Custom0(iVarNum, fMinCR, fMaxCR);
            }
        }
// PICK RANDOM CREATURE FROM CUSTOM TABLE 1
    for(iCounter1 = 0; iCounter1 <= GetStringLength(sCreatureTable); iCounter1++)
        {
        if(GetSubString(sCreatureTable, iCounter1, 1) == "1")
            {
            iVarNum = Custom1(iVarNum, fMinCR, fMaxCR);
            }
        }
// PICK RANDOM CREATURE FROM CUSTOM TABLE 2
    for(iCounter1 = 0; iCounter1 <= GetStringLength(sCreatureTable); iCounter1++)
        {
        if(GetSubString(sCreatureTable, iCounter1, 1) == "2")
            {
            iVarNum = Custom2(iVarNum, fMinCR, fMaxCR);
            }
        }
// PICK RANDOM CREATURE FROM CUSTOM TABLE 3
    for(iCounter1 = 0; iCounter1 <= GetStringLength(sCreatureTable); iCounter1++)
        {
        if(GetSubString(sCreatureTable, iCounter1, 1) == "3")
            {
            iVarNum = Custom3(iVarNum, fMinCR, fMaxCR);
            }
        }
// PICK RANDOM CREATURE FROM CUSTOM TABLE 4
    for(iCounter1 = 0; iCounter1 <= GetStringLength(sCreatureTable); iCounter1++)
        {
        if(GetSubString(sCreatureTable, iCounter1, 1) == "4")
            {
            iVarNum = Custom4(iVarNum, fMinCR, fMaxCR);
            }
        }
// PICK RANDOM CREATURE FROM CUSTOM TABLE 5
    for(iCounter1 = 0; iCounter1 <= GetStringLength(sCreatureTable); iCounter1++)
        {
        if(GetSubString(sCreatureTable, iCounter1, 1) == "5")
            {
            iVarNum = Custom5(iVarNum, fMinCR, fMaxCR);
            }
        }
// PICK RANDOM CREATURE FROM CUSTOM TABLE 6
    for(iCounter1 = 0; iCounter1 <= GetStringLength(sCreatureTable); iCounter1++)
        {
        if(GetSubString(sCreatureTable, iCounter1, 1) == "6")
            {
            iVarNum = Custom6(iVarNum, fMinCR, fMaxCR);
            }
        }
// PICK RANDOM CREATURE FROM CUSTOM TABLE 7
    for(iCounter1 = 0; iCounter1 <= GetStringLength(sCreatureTable); iCounter1++)
        {
        if(GetSubString(sCreatureTable, iCounter1, 1) == "7")
            {
            iVarNum = Custom7(iVarNum, fMinCR, fMaxCR);
            }
        }
// PICK RANDOM CREATURE FROM CUSTOM TABLE 8
    for(iCounter1 = 0; iCounter1 <= GetStringLength(sCreatureTable); iCounter1++)
        {
        if(GetSubString(sCreatureTable, iCounter1, 1) == "8")
            {
            iVarNum = Custom8(iVarNum, fMinCR, fMaxCR);
            }
        }
// PICK RANDOM CREATURE FROM CUSTOM TABLE 9
    for(iCounter1 = 0; iCounter1 <= GetStringLength(sCreatureTable); iCounter1++)
        {
        if(GetSubString(sCreatureTable, iCounter1, 1) == "9")
            {
            iVarNum = Custom9(iVarNum, fMinCR, fMaxCR);
            }
        }

// SELECT THE RANDOM CREATURE
    int iRnd = Random(iVarNum);
    string sCreature = GetLocalString(oMod, "sCreatureList" + IntToString(iRnd));
    // Copy the Min and Max number of creatures from the corresponding simulated "array" to the
    // root variable in the module object.
    SetLocalInt(oMod, "iMinNumberOfCreatures", GetLocalInt(oMod, "iMinNumberOfCreatures" + IntToString(iRnd)));
    SetLocalInt(oMod, "iMaxNumberOfCreatures", GetLocalInt(oMod, "iMaxNumberOfCreatures" + IntToString(iRnd)));
    // Reset the local module variables that store min and max number of creatures
    // so we don't use old numbers at a later time.
    for(iCounter3 = 1; iCounter3 <= iVarNum; iCounter3++)
        {
        SetLocalInt(oMod, "iMinNumberOfCreatures" + IntToString(iCounter3), 0);
        SetLocalInt(oMod, "iMaxNumberOfCreatures" + IntToString(iCounter3), 0);
        }
    return sCreature;
}
