//::////////////////////////////////////////////// //:: FileName behav_day_night //::////////////////////////////////////////////// //::////////////////////////////////////////////// //:: Created By: Miles Eon : trsell@gmail.com //:: Created On: 2004/12/15 //:: Last Modified by: Miles Eon : trsell@gmail.com //:: Modified on: 2004/12/23 //::////////////////////////////////////////////// //:: For the OnEnter event for the area or any triggers you want to //:: make check and adjust the behaviour of all encounters in an area. //:: //:: For diurnal encounter behaviour, the encounter must have local int //:: ENCOUNTER_DIURNAL set to 1 //:: For nocturnal encounter behaviour, the encounter must have local int //:: ENCOUNTER_NOCTURNAL set to 1 //:: If both are set to one the behavior will be diurnal. //:: If neither are set the encounter will spawn at all times of the day //:: as per normal. //:: //:: If you want to have the creatures removed when they are no longer active //:: (if any are about) give the encounter local strings with the tags of the //:: creatures to be destroyed. For example if you have BIG_GOBLIN and //:: LITTLE_GOBLIN tags. Set local strings on the encounter: //:: CREATURE_TAG1 | BIG_GOBLIN //:: CREATURE_TAG2 | LITTLE_GOBLIN //:: etc. //:: This will only remove those creatures with those tags, in the same area //:: as the pc that fired this script. It will remove all of them, not just //:: the ones that came from encounters. //::////////////////////////////////////////////// #include "nw_o0_itemmaker" const string ENCOUNTER_CYCLE_LAST_ACTIVE_LOCAL_INT = "ENCOUNTER_CYCLE_LAST_ACTIVE"; const string PREFIX_FOR_CREATURE_TAG_LOCAL_STRING = "CREATURE_TAG"; const string ENCOUNTER_SET_DIURNAL_LOCAL_INT= "ENCOUNTER_DIURNAL"; const string ENCOUNTER_SET_NOCTURNAL_LOCAL_INT= "ENCOUNTER_NOCTURNAL"; const string ENCOUNTER_EXIT_WAYPOINT_LOCAL_STRING = "ENCOUNTER_EXIT_WAYPOINT"; void PurgeDayNight(object oPC, object oEncounter); void RemoveCreatures(string sCreatureTag, object oLocalObject); void main() { object oPC = GetEnteringObject(); if (!GetIsPC(oPC)) return; object oEncounter; int iCounter; // cycle through all the encounters in the area. iCounter = 1; oEncounter = GetNearestObject(OBJECT_TYPE_ENCOUNTER, oPC, iCounter); while (oEncounter != OBJECT_INVALID) { PurgeDayNight(oPC, oEncounter); iCounter++; oEncounter = GetNearestObject(OBJECT_TYPE_ENCOUNTER, oPC, iCounter); } } // Does the purging for one encounter. void PurgeDayNight(object oPC, object oEncounter) { int iEncounterActive = GetEncounterActive(oEncounter); int iEncounterCycleActive = GetLocalInt(oEncounter, ENCOUNTER_CYCLE_LAST_ACTIVE_LOCAL_INT); int IsActiveTime; int iCounter; string sCreatureTag; string sWaypointTag; object oExitWP = OBJECT_INVALID; if (GetLocalInt(oEncounter, ENCOUNTER_SET_DIURNAL_LOCAL_INT)) { // Day animals which dissappear at night. IsActiveTime = GetIsDay(); } else if (GetLocalInt(oEncounter, ENCOUNTER_SET_NOCTURNAL_LOCAL_INT)) { // Nocturnal encounters have the active cycle reversed. IsActiveTime = GetIsNight(); } else // Encounters not specified with these local integers will { // behave as the default. return; } if (IsActiveTime) // encounter cycle should be active { if (!iEncounterCycleActive) { SetEncounterActive(TRUE, oEncounter); SetLocalInt(oEncounter, ENCOUNTER_CYCLE_LAST_ACTIVE_LOCAL_INT, TRUE); } // else encounter is already active, nothing to worry about. } else // encounter cycle should be inactive { if (iEncounterCycleActive || iEncounterActive) // or iEnouncterActive, so that if this is checked before the local variable has been given any setting it will get one here. { SetEncounterActive(FALSE, oEncounter); SetLocalInt(oEncounter, ENCOUNTER_CYCLE_LAST_ACTIVE_LOCAL_INT, FALSE); } // This removes all creatures of the encounters type in the area, // not just ones spawned by oEncounter. iCounter = 1; sCreatureTag = GetLocalArrayString(oEncounter, PREFIX_FOR_CREATURE_TAG_LOCAL_STRING, iCounter); while (sCreatureTag != "") { RemoveCreatures(sCreatureTag, oPC); iCounter++; sCreatureTag = GetLocalArrayString(oEncounter, PREFIX_FOR_CREATURE_TAG_LOCAL_STRING, iCounter); } } } // Removes all the creature with tag sCreatureTag, in the same area as oLocalObject // should work with oLocalObject as any creature or placeable, but not if it's // an area. void RemoveCreatures(string sCreatureTag, object oLocalObject) { object oCreature; int iCounter; iCounter = 1; oCreature = GetNearestObjectByTag(sCreatureTag, oLocalObject, iCounter); while (oCreature != OBJECT_INVALID) { DestroyObject(oCreature); iCounter++; oCreature = GetNearestObjectByTag(sCreatureTag, oLocalObject, iCounter); } }