Area cleanup script?

Does anyone know of an easy to use area cleanup system/script? I been working on a PW and looking for an easy to use area clean-up script/system so there can be no possible clutter of loot etc!

thanks all in advance! <3

1 Like

Area cleanup could be everything - most commonly creating or deleting stuff, moving NPC’s, activating/deactivating traps and encounters.
I just add a few lines of individual code here, that isn’t a great deal. A strict naming convention is helpful with this. If the changes are too complex, maybe It’s a good idea, to have a copy of the area where the changes alredy made in the toolset.

vg, mm

uhhh what? Sorry I did not get that at all…

Basically what I am looking for is something that simply destroys everything in the area, or at least the things that was not there since start!

You can write something like that yourself. Will probably be easier and with better support for your module. Starting points (pick one):

GetFirstObjectInArea()
GetFirstObjectInShape() // note: use huge radius and nObjectFilter

Loop through the objects and decide what to do with them. [1]

In fact, you could delete everything the area if no player will ever visit it again.

You can mark such “native” objects with a local variable (string, tag of the area). You could run a script at the module’s start to do that for you.


[1] I haven’t tested with approach is more efficient.

A word of caution here. I tried that approach and got a tmi (too many instructions) error. The thing that causes this is deleting objects screws up finding the next object. I solved it by using SetLocalObject() on the area first and looping through until all objects were identified and stored. Only then did I go through the stored objects and delete them. As an example of this in action, here is a simplified version of the function I created for this.

void DeleteTagged(object oArea)
{
    object oTestObject = GetFirstObjectInArea(oArea);
    int iDigit = 1;
    int iIndex;

    while(GetIsObjectValid(oTestObject))
    {
        if(GetTag(oTestObject) == "ThisTag")
            SetLocalObject(oArea, "oTemp" + IntToString(iDigit++), oTestObject);

        oTestObject = GetNextObjectInArea(oArea);
    }
    for(iIndex = 1 ; iIndex < iDigit ; iIndex++)
        DestroyObject(GetLocalObject(oArea, "oTemp" + IntToString(iIndex)));
}

Just change the tag “ThisTag” to whatever tag you use to mark the objects to destroy.

TR

1 Like

That’s odd. Destroying the object should not effect the loop. The objects won’t be destroyed until the script is done so the objects in the area won’t be changing. It is true though that creating objects in a loop like that is an easy way to break the loop and hit TMI.

Beyond that observation that’s a good work around.

In your script, how did you manage deleted creature & plc inventories?

Because when the owner is outright destroyed, BodyBag (remains) may appear on ground. And BodyBags are “undestroyable”: when not empty, they respawn automatically after DestroyObject is applied (to clarify: a BodyBag of a BodyBag appears - new object with new ID and same contents). So, if the main script was called again to verify nothing is left in the area, it may see a BodyBag and…

I figured that after turning the PC off last night. In the original script (I did say that was a simplified version), it called a function (that was also called by a number of other functions separately) that did a number of other things along with the actual deletion.

TR

I didn’t. The above script is just a minimal one to show the general idea. If I were to take account of inventories, I would add code to that script to check if an object had anything in an inventory and if found pass control to a second function to do the actual destruction of any such contents. What can I say - I like small single purpose functions.

TR