Skip to content

Heartbeat script question

How taxing would this script be on an area?
// Tinmans Heartbeat area respawner test script
// Created 12\8\2023
void main()
{
// Get the object type of the object that runs the script
int nObjectType = GetObjectType(OBJECT_SELF);

// Check if the object is a placeable
if (nObjectType == OBJECT_TYPE_PLACEABLE)
{
    // Use the Tag of a Standard Creature
    // Use the resref of a Custom Creature
    string sTag = GetTag(OBJECT_SELF);

    // Check if the object has a local variable named “DO_ONCE”
    if (GetLocalInt(OBJECT_SELF, "DO_ONCE") == 0)
    {
        // Set the variable to 1, so the script will not fire again
        SetLocalInt(OBJECT_SELF, "DO_ONCE", 1);

        // We run this section only once
        CreateObject (OBJECT_TYPE_CREATURE, sTag, GetLocation (OBJECT_SELF), FALSE);
    }

// Check if the object is an area
if (nObjectType == OBJECT_TYPE_PLACEABLE)
{
     nObjectType = GetObjectType(OBJECT_SELF);

    // Get the area object
    object oArea = GetArea(OBJECT_SELF);

    // Get the first creature in the area
    object oCreature = GetFirstObjectInArea(oArea);

    // The delay time for the spawner script
    float fDelay = 20.0;

    // Loop through all creatures in the area
    while (GetIsObjectValid(oCreature))
    {
        // Check if the creature is dead
        if (GetIsDead(oCreature))
        {
            // Increment the delay time by 7 seconds
            //fDelay += 7.0;//Not sure i will use this option

            // Get the tag of the creature
            string sTag = GetTag(oCreature);

            // Find the closest placeable with the same tag as the creature
            object oClosestPlaceable = GetNearestObjectByTag(sTag, oCreature);

            // Check if the placeable is valid
            if (GetIsObjectValid(oClosestPlaceable))
            {
                // Reset the variable of the closest placeable to 0
                DelayCommand(fDelay, SetLocalInt(oClosestPlaceable, "DO_ONCE", 0));
            }
        }

        // Get the next creature in the area
        oCreature = GetNextObjectInArea(oArea);
    }
}

}
}
Sign In or Register to comment.