****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:
int ReserveQueueNumber();
float GetSecondsTillSpawn(int nSpawnHour);
void InitiateRespawn(string sQueueNum, string sTemp, location lSpawnPoint);
void main()
{
int nSpawnHour = 19;
SetLocalInt(OBJECT_SELF, "spawnhour", nSpawnHour);
int nQueue = ReserveQueueNumber();
float fSecToWait = GetSecondsTillSpawn(nSpawnHour);
string sMyTemplate = GetTag(OBJECT_SELF);
string sMyQueueNum = sMyTemplate + IntToString(nQueue);
location lMyLoc = GetLocation(OBJECT_SELF);
SetLocalString(OBJECT_SELF, "myqueuenum", sMyQueueNum);
AssignCommand(GetModule(), DelayCommand(fSecToWait, InitiateRespawn(sMyQueueNum, sMyTemplate, lMyLoc)));
}
void InitiateRespawn(string sQueueNum, string sTemp, location lSpawnPoint)
{
int bDoNotRes = GetLocalInt(GetModule(), "DNR" + sQueueNum);
if (bDoNotRes){
return;
}
CreateObject(OBJECT_TYPE_CREATURE, sTemp, lSpawnPoint);
}
float GetSecondsTillSpawn(int nSpawnHour)
{
int nHour = GetTimeHour();
int nTimeLeft = nSpawnHour - nHour;
if (nTimeLeft <= 0){
nTimeLeft = nTimeLeft + 24;
}
return(HoursToSeconds(nTimeLeft));
}
int ReserveQueueNumber()
{
int nQueue = GetLocalInt(GetModule(), "queuenumber");
if (nQueue == 0){
SetLocalInt(GetModule(), "queuenumber", 1);
nQueue = 1;
}
SetLocalInt(GetModule(), "queuenumber", nQueue + 1);
return(nQueue);
}
In OnHeartbeat:
NWScript:
void main()
{
int nHideHour = 18;
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:
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?
|