DMH-Online

Dungeon Masters Helper · Est. 2005

Areas Scripts

NWN Script: despawn_mobs.htm

Author
Aviston
This is a Despawner script that I wrote for people who have areas comprised mainly of Encounter spawned creatures. The script runs from OnExit in Area Properties thus not requiring a CPU eating HeartBeat script. In general terms, when a PC exits an area, the area checks to see if there are any other PCs left in it, and if not, goes through and destroys all creatures that spawned from an encounter.

NWScript:
// Despawner Script - Used in OnExit in Area Properties
//
// The purpose of this script is to DestroyObject() all occurences of 
// encounter spawned creatures when no PCs are left in the current
// area.
//
// -Aviston-
void main()
{
    // First check to see if the ExitingObject is a PC or not
    object oPC = GetExitingObject();
    // If not, we'll just exit
    if (!GetIsPC(oPC))
        return;
    // Start up the loop, setting oPC now to the first PC
    oPC = GetFirstPC();
    // Continue looping until there are no more PCs left
    while (oPC != OBJECT_INVALID)
    {
        // Check the Area against the Area of the current PC
        // If they are the same, exit the function, as we do not need to
        // check anymore PCs
        if (OBJECT_SELF == GetArea(oPC))
            return;
        // If not, continue to the next PC
        else oPC = GetNextPC();
    }
    // If we've made it this far, we know that there aren't any PCs in the area
    // Set oObject to the first object in the Area
    object oObject = GetFirstObjectInArea(OBJECT_SELF);
    // Continue looping until there are no more objects left
    while (oObject != OBJECT_INVALID)
    {
        // Test to see if oObject is a creature spawned from an encounter
        // If so, destroy the object
        if (GetIsEncounterCreature(oObject))
            DestroyObject(oObject);
        // Move on to the next object
        oObject = GetNextObjectInArea(OBJECT_SELF);
    }
}
⌂ All Scripts ← PreviousNext → 👁 Category List

All Areas Scripts

📄 ambient_npc_ani 📄 area_spawner 📄 change_lighting 📄 clean_trash_001 📄 clean_trash_002 📄 clean_trash_003 📄 despawn_mobs 📄 despawn_mobs_002 📄 disable_sound 📄 full_edge_transition_001 📄 full_edge_transition_002 📄 full_edge_transition_003 📄 full_edge_transition_004 📄 full_edge_transition_004a 📄 get_pcs 📄 guard_patrols 📄 keyed_transitions 📄 random_enc_001 📄 random_enc_002 📄 random_enc_003 📄 random_enc_004 📄 random_enc_006 📄 random_enc_009 📄 random_encounter_005 📄 random_interiors 📄 random_interiors_001a 📄 restrict_access 📄 sitting_area