DMH-Online

Dungeon Masters Helper · Est. 2005

Creatures Scripts

NWN Script: spawn.htm

Author Sticky: Post Working Scripts Here
VorpalBlade Posted: Saturday, 27 July 11:52PM
****FIXED POST****

1. Script Name: Creature/NPC Respawn Scheduler

2. What it does: Schedules the Hiding and spawning of creatures or NPCs so that they are around at a chosen time of day or night.

3. Notes: Three scripts are involved. But if you want killed creatures to come back on the next scheduled spawn, you can leave dnr_death.nss out. If you want deminishing returns after kills, use all three scripts.

In OnSpawn:

NWScript:
//::///////////////////////////////////////////////
//:: Name Creature/NPC Spawn Scheduler
//:: FileName sched_spawn.nss
//:: Copyright (c) 2001 Bioware Corp.
//:://////////////////////////////////////////////
/*
Sets a time to respawn a templated creature or NPC.
To be used with sched_heart.nss and dnr_death.nss
*/
//:://////////////////////////////////////////////
//:: Created By: VorpalBlade
//:: Created On: 7/27/02
//:://////////////////////////////////////////////
// Create a Template of an NPC or creature and set the
// Tag to be identical to its ResRef. Place this in
// the OnSpawn event and place sched_heart.nss in the
// OnHeartbeat.
// One script will work for multible templates, but for
// a different spawn schedule you will need to copy this
// script and the sched_heart.nss to a new name and edit
// spawn and hide times on the copy.
// The dnr_death.nss (Do Not Rez) script is for those who
// like less of a Permanent World type environment. If you
// add it to the OnDeath event, what ever is killed will
// not come back on the next scheduled spawn. Leave it out
// if you want the spawn replenished for each scheduled
// spawn. The same dnr_death.nss script can be used for
// all schedules no duplicate needed.
// To change the spawn hour just change the first line in
// main().
int ReserveQueueNumber();
float GetSecondsTillSpawn(int nSpawnHour);
void InitiateRespawn(string sQueueNum, string sTemp, location lSpawnPoint);
void main()
{
    int nSpawnHour = 19; //           *****Set the hour for the respawn here*****
    SetLocalInt(OBJECT_SELF, "spawnhour", nSpawnHour);
    int nQueue = ReserveQueueNumber(); // Get a unique number for DNR
    float fSecToWait = GetSecondsTillSpawn(nSpawnHour);
    string sMyTemplate = GetTag(OBJECT_SELF);
    string sMyQueueNum = sMyTemplate + IntToString(nQueue);
    location lMyLoc = GetLocation(OBJECT_SELF);
// Make available the Queue number for use in the DNR (Do Not Res) flag
// which is set OnDeath.
    SetLocalString(OBJECT_SELF, "myqueuenum", sMyQueueNum);
    AssignCommand(GetModule(), DelayCommand(fSecToWait, InitiateRespawn(sMyQueueNum, sMyTemplate, lMyLoc)));
}
// This function is sent to the Module(). Waits until the next
// spawn time before executing. In the case of the DoNotRes set
// to true OnDeath, will not execute.
void InitiateRespawn(string sQueueNum, string sTemp, location lSpawnPoint)
{
    int bDoNotRes = GetLocalInt(GetModule(), "DNR" + sQueueNum);
    if (bDoNotRes){
        return;
        }
    CreateObject(OBJECT_TYPE_CREATURE, sTemp, lSpawnPoint);
}
// calculates the time in seconds, to delay the respawn.
float GetSecondsTillSpawn(int nSpawnHour)
{
    int nHour = GetTimeHour();
    int nTimeLeft = nSpawnHour - nHour;
    if (nTimeLeft <= 0){
        nTimeLeft = nTimeLeft + 24;
    }
    return(HoursToSeconds(nTimeLeft));
}
// This creates a unique number for each creature to be used as
// part of a name for the LocalInt in the Module() that serves as
// the DNR (Do Not Res) flag.
int ReserveQueueNumber()
{
    int nQueue = GetLocalInt(GetModule(), "queuenumber");
    if (nQueue == 0){   // Make the first number in the queue 1.
        SetLocalInt(GetModule(), "queuenumber", 1);
        nQueue = 1;
    }
    SetLocalInt(GetModule(), "queuenumber", nQueue + 1);
    return(nQueue);
}



In OnHeartbeat:

NWScript:
//::///////////////////////////////////////////////
//:: Name Creature/NPC Spawn Scheduler
//:: FileName sched_heart.nss
//:: Copyright (c) 2001 Bioware Corp.
//:://////////////////////////////////////////////
/*
Puts the creature or NPC into hiding at the sheduled hour.
To be used with sched_spawn.nss and dnr_death.nss
*/
//:://////////////////////////////////////////////
//:: Created By: VorpalBlade
//:: Created On: 7/27/02
//:://////////////////////////////////////////////
// Change the first line in main() to set the Hide time.
void main()
{
    int nHideHour = 18;    // ******************Set Hide Time Here*************
    int nSpawnHour = GetLocalInt(OBJECT_SELF, "spawnhour");
    int nTime = GetTimeHour();
    if ((nHideHour <= nTime) && (nTime < nSpawnHour)){
        DestroyObject(OBJECT_SELF);
    }
}



In OnDeath (Non persistant world type spawns only):

NWScript:
//::///////////////////////////////////////////////
//:: Name Creature/NPC Spawn Scheduler
//:: FileName dnr_death.nss
//:: Copyright (c) 2001 Bioware Corp.
//:://////////////////////////////////////////////
/*
Sets the DNR (Do Not Rez) flag.
To be used with sched_spawn.nss and sched_heart.nss
*/
//:://////////////////////////////////////////////
//:: Created By: VorpalBlade
//:: Created On: 7/27/02
//:://////////////////////////////////////////////
void main()
{
    string sQueueNum = GetLocalString(OBJECT_SELF, "myqueuenum");
    SetLocalInt(GetModule(), "DNR" + sQueueNum, TRUE);
}



_________________
Am I a vast community of cells, or a cell in a vast community?

⌂ 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