Creatures respawn after a set amount of time
From NWNWiki
The simplest way is to use the options in an Encounter trigger. Build your Encouter trigger, right-click on it, and select Properties.
- In the Basic TAB, select "Continuous".
- In the Advanced TAB, select "Encounter Respawns"
- Set the "Respawn Time", "Number Of Times To Respawn", or select "Infinite Respawn".
This will cause your encounters to respawn the creatures. Be sure to play around with the shape of the trigger. You can make the trigger the same size of your map if you want.
[edit] As a Script
A different way, but a bit more complicated, is to script it all. This however will allow you to place the creatures where you want them beforehand.
- Add this line to the bottom of the NPC OnSpawn script. Be sure to add it to the script that is on the blueprint of the creature, not just the one on the map.
SetLocalLocation(OBJECT_SELF,"LOC",GetLocation(OBJECT_SELF));
- Add This to the start of the Creatures OnDeath Script. Again, be sure to add it to the creature in the pallet, not just the one on the map. This will keep track of what creature died and how long before respawn. Change the time in sec for fDelaySpawn to what you need. This can be set differently for each creature. Just be sure to save it as a different name so you don't overwrite previous ones.
// Set Time to Respawn
float fDelaySpawn = 90.0f;
object oMod = GetModule();
int nDOA = GetLocalInt(oMod,"DOA")+1;
SetLocalInt(oMod,"DOA",nDOA);
SetLocalString(oMod,IntToString(nDOA)+"ResRef",GetResRef(OBJECT_SELF));
SetLocalLocation(oMod,"Location",GetLocalLocation(OBJECT_SELF,"LOC"));
SetLocalFloat(oMod,"Float",fDelaySpawn);
ExecuteScript("respawn",oMod);
- Copy and this script and paste it into the script editor. Save it with the name "respawn". Don't attach it to any handle, just be sure it is saved to your module.
void ActionCreateCreature(string sCreature, location lLoc)
{
CreateObject(OBJECT_TYPE_CREATURE, sCreature, lLoc);
}
void main()
{
object oMod = GetModule();
int nDOA = GetLocalInt(oMod,"DOA");
location lLoc = GetLocalLocation(oMod,"Location");
float fDelay = GetLocalFloat(oMod,"Float");
DelayCommand(fDelay,ActionCreateCreature(GetLocalString(oMod,IntToString(nDOA)+"ResRef"),lLoc));
}
This simple method will survive Games Saves as well
