DMH-Online

Dungeon Masters Helper · Est. 2005

Creatures Scripts

NWN Script: random_enc_onrest.htm

Author Sticky: Post Working Scripts Here
mindtakerr Posted: Tuesday, 25 June 04:30AM
Name: Occasionally spawn in monster on rest

Script Creator: Michael Ham (mindtakerr)

Notes: I think I finally have a script good enough to put on here. It's long, but it's good (I think). It will make it so that there is a 50% chance of a monster attacking while you rest. The monster will spawn randomly based on the resting PC's level. It's long, but I think it's pretty cool.

Here is an update to my earlier monster_rest script which sometimes calls a monster to attack you while you are resting.

EDIT - Changes made:
Fixed a bug (hopefully) that sometimes caused 2 monsters to spawn instead of one.
Change the monster spawn rate from 50% to 33%.
Added a delay when the monster spawns in so that the player has time to get ready for the fight.

In the module's OnPlayerRest script:

NWScript:
void main()
{
    // Sometimes spawn monster during rest
    // An object to hold the last player who rested
    object oPlayer = GetLastPCRested();
    // Check to see whether resting has started or is over
    int nRestTurn = GetLocalInt(oPlayer, "nRestTurns");
    SetLocalInt(oPlayer, "nRestTurns", nRestTurn + 1);
    nRestTurn = GetLocalInt(oPlayer, "nRestTurns");
    if (nRestTurn == 1) {
        // Determine whether rest will be peaceful or not
        int nRestType = d6();
        int nEnemyType = d3();
        object oEnemy;
        // A string to hold the creature's tag
        string sCreature;
        // Set a location for where the PC is
        location lHere = GetLocation(oPlayer);
        // Set the level of the monster to spawn
        int iLevel = 0;
        iLevel += GetLevelByPosition(1, oPlayer);
        iLevel += GetLevelByPosition(2, oPlayer);
        iLevel += GetLevelByPosition(3, oPlayer);
        // A roll of 4 causes the monster to be even harder
        if (nRestType == 4) {
            iLevel++;
            nRestType = 3;
        }
        // Script only has 15 places for monster levels
        if (iLevel > 15) {
            iLevel = 15;
        }
        // Bad luck, a monster is coming
        if (nRestType == 3)  {
            // Decide which monster to spawn, based on CR
            switch (iLevel) {
                case 1:
                    if (nEnemyType == 1)
                        sCreature = "NW_ORCA";
                    else if (nEnemyType == 2)
                        sCreature = "NW_WOLF";
                    else
                        sCreature = "NW_ZOMBIE01";
                    break;
                case 2:
                    if (nEnemyType == 1)
                        sCreature = "NW_BEARBLCK";
                    else if (nEnemyType == 2)
                        sCreature = "NW_BUGBEARA";
                    else
                        sCreature = "NW_KRENSHAR";
                    break;
                case 3:
                    if (nEnemyType == 1)
                        sCreature = "NW_MEPAIR";
                    else if (nEnemyType == 2)
                        sCreature = "NW_BTLBOMB";
                    else
                        sCreature = "NW_DIREBADG";
                    break;
                case 4:
                    if (nEnemyType == 1)
                        sCreature = "NW_GHAST";
                    else if (nEnemyType == 2)
                        sCreature = "NW_AIR";
                    else
                        sCreature = "NW_MINOTAUR";
                    break;
                case 5:
                    if (nEnemyType == 1)
                        sCreature = "NW_OGREMAGE01";
                    else if (nEnemyType == 2)
                        sCreature = "NW_BUGBEARA";
                    else
                        sCreature = "NW_KRENSHAR";
                    break;
                case 6:
                    if (nEnemyType == 1)
                        sCreature = "NW_OGRECHIEF01";
                    else if (nEnemyType == 2)
                        sCreature = "NW_TROLL";
                    else
                        sCreature = "NW_DEVOUR";
                    break;
                case 7:
                    if (nEnemyType == 1)
                        sCreature = "NW_SLAADBL";
                    else if (nEnemyType == 2)
                        sCreature = "NW_UMBERHULK";
                    else
                        sCreature = "NW_MUMMY";
                    break;
                case 8:
                    if (nEnemyType == 1)
                        sCreature = "NW_GOLFLESH";
                    else if (nEnemyType == 2)
                        sCreature = "NW_ETTIN";
                    else
                        sCreature = "NW_TROLLCHIEF";
                    break;
                case 9:
                    if (nEnemyType == 1)
                        sCreature = "NW_BEARDIRE";
                    else if (nEnemyType == 2)
                        sCreature = "NW_MINWIZ";
                    else
                        sCreature = "NW_RAKSHASA";
                    break;
                case 10:
                    if (nEnemyType == 1)
                        sCreature = "NW_GNTFROST";
                    else if (nEnemyType == 2)
                        sCreature = "nw_bugbearboss";
                    else
                        sCreature = "NW_GNTHILL";
                    break;
                case 11:
                    if (nEnemyType == 1)
                        sCreature = "NW_GOBLINBOSS";
                    else if (nEnemyType == 2)
                        sCreature = "NW_BATTDEVOUR";
                    else
                        sCreature = "NW_REVENANT001";
                    break;
                case 12:
                    if (nEnemyType == 1)
                        sCreature = "NW_GolClay";
                    else if (nEnemyType == 2)
                        sCreature = "NW_SHGUARD";
                    else
                        sCreature = "NW_DRGBLACK001";
                    break;
                case 13:
                    if (nEnemyType == 1)
                        sCreature = "NW_SPIDERBOSS";
                    else if (nEnemyType == 2)
                        sCreature = "NW_DRGBLACK001";
                    else
                        sCreature = "NW_GNTFIRE";
                    break;
                case 14:
                    if (nEnemyType == 1)
                        sCreature = "NW_MUMMYBOSS";
                    else if (nEnemyType == 2)
                        sCreature = "drgblue002";
                    else
                        sCreature = "NW_GOLIRON";
                    break;
                case 15:
                    if (nEnemyType == 1)
                        sCreature = "nw_beetleboss";
                    else if (nEnemyType == 2)
                        sCreature = "NW_FIREGREAT";
                    else
                        sCreature = "NW_DRGGREEN002";
                    break;
            }
            // Create the enemy at the PC's location
            oEnemy = CreateObject(OBJECT_TYPE_CREATURE, sCreature, lHere, FALSE);
            // The PC alerts of danger
            AssignCommand(oPlayer, ActionSpeakString("I'm under attack!"));
            // Wait a moment so that the PC might get ready
            AssignCommand(oEnemy, ActionWait(3.0));
            // Tell the enemy to attack the player
            AssignCommand(oEnemy, ActionAttack(oPlayer));
            SetLocalInt(oPlayer, "nRestTurns", -1);
        }
    }
    if(nRestTurn != 1)
        SetLocalInt(oPlayer, "nRestTurns", 0);
}



_________________
Michael Ham
Check out The Six Realms of Bel'Abourd; a fantasy RPG work in progress.
www.bakedhamgames.com

⌂ All Scripts ← PreviousNext → 👁 Category List

All Creatures Scripts

📄 apply_spell_effect 📄 aurak_draconian 📄 baaz_draconian 📄 boss_spawner 📄 change_light_spawn_pt_on_death 📄 clone_mob 📄 collect_loot 📄 create_unique_objectIDs 📄 creature_proc 📄 explode_ondeath 📄 explode_ondeath_002 📄 explode_ondeath_003 📄 exploding_chickens 📄 fire_death 📄 inverse_mob 📄 iron_statue 📄 lich 📄 lootable_corpse 📄 lootable_corpse_002 📄 lootable_corpse_002a 📄 lootable_corpse_oo2 📄 mob_respawn 📄 mob_respawn_002 📄 multi_creature_spawn 📄 night_time 📄 random_death_effect 📄 random_drops 📄 random_drops_002 📄 random_drops_003 📄 random_enc_onrest 📄 random_hps 📄 sivac_draconian 📄 spawn 📄 spawn_on_hearbeat 📄 summon_last_hostile 📄 summon_mob 📄 trolls 📄 trolls_002 📄 vampire_coffin 📄 werewolf