Server Totals
Mikona - (1)
Elysia - (1)
Le'Or - (0)
Ferrell - (0)
M'Chek - (0)
Deglos - (0)
Wilderness - (0)
Visimontium - (0)
Underdark - (0)
Total players: 2
Gallery

Links Menu

Trash cleaner

Moderators: Nighthawk4, Dungeon Masters

Trash cleaner

PostAuthor: Papillon » Sun Oct 20, 2002 11:06 am

Got this code from nwvault, checked it, and modified it a bit. It's an efficient implementation we can use instead of the stray dogs (which need heartbeat and are not too efficient).

This first version checks the area for trash every time a PC enters, which can be a bit much for some frequent visited areas. Therefore, I will add some code that waits at least five minutes between checks.

We should discuss if we need to exclude some areas (i.e. have we got areas in the module that should not be cleaned ?).

Code: Select all
//::////////////////////////////////////////////
//:: Name:  s_cleartrash - Clear trash on ground
//::////////////////////////////////////////////
/*

This script is intended to be called by or incorporated into the
Area:OnEntered event (script). Every time a PC enters an area, all
items and monster drop bags on the ground are checked for a destruct
time. If the object does not have a destruct time, one is set. If the
destruct time has already passed, the object is destroyed.

The constant iObjectsToDestroy is a throttle control. Adjust it lower
to reduce burst server load, higher if objects are accumulating.

*/
//:://////////////////////////////////////////////
//:: Author: Scott Thorne
//:: E-mail: Thornex2@wans.net
//:: Updated: August 09, 2002
//:://////////////////////////////////////////////

// Modified: October 20, 2002 by Ingmar Stieger
// changed formatting, removed useless brackets
// and modified iObjectsToDestroy check

void TrashObject(object oObject)
{
     /* search and destroy contents of body bag's, others just destroy */
    if (GetObjectType(oObject) == OBJECT_TYPE_PLACEABLE) {

        object oItem = GetFirstItemInInventory(oObject);

        /* recursively trash all items inside container */
        while (GetIsObjectValid(oItem))
        {
            TrashObject(oItem);
            oItem = GetNextItemInInventory(oObject);
        }
    }
    DestroyObject(oObject);
}

void main()
{
    /* bypass if currently in-progress (blocked) or ClearTrash is disabled */
    if ((GetLocalInt(OBJECT_SELF, "CT_IN_PROGRESS") != TRUE) &&
        (GetLocalInt(GetModule(), "CT_DISABLED") != TRUE))
    {
        // set a flag to block
        SetLocalInt(OBJECT_SELF, "CT_IN_PROGRESS", TRUE);

        int iItemDestructTime;

        int iObjectsDestroyed = 0;
        int iObjectsToDestroy = 20;  /* adjust as desired */
        int iNow = (GetCalendarMonth()*10000) + (GetCalendarDay()*100) + GetTimeHour();
        int iAreaDestructTime = iNow + 2;  /* destroy items in 'n' game hours from now */

        object oItem = GetFirstObjectInArea();

        while ((GetIsObjectValid(oItem)) && (iObjectsDestroyed < iObjectsToDestroy))
        {
            switch (GetObjectType(oItem))
            {
                case OBJECT_TYPE_PLACEABLE:
                    /* monster drop containers are tagged placeables */
                    if (GetTag(oItem) != "Body Bag")
                        break;

                    /* note: no break here, allow fall-through */

                case OBJECT_TYPE_ITEM:
                    iItemDestructTime = GetLocalInt(oItem, "CT_DESTRUCT_TIME");
                    // If destruct time set, check it; if not, set it
                    if (iItemDestructTime > 0)
                    {
                        if (iItemDestructTime <= iNow)
                        {
                            // destruct time has passed, trash the object
                            TrashObject(oItem);
                            iObjectsDestroyed++;
                        }
                    }
                    else
                        SetLocalInt(oItem, "CT_DESTRUCT_TIME", iAreaDestructTime);
            }
            oItem = GetNextObjectInArea();
        }

        SetLocalInt(OBJECT_SELF, "CT_IN_PROGRESS", FALSE);  /* done, release */
    }
}

Papillon
Team Member; Retired with Honors
 
Posts: 3155
Joined: Thu Jul 18, 2002 11:17 pm

PostAuthor: Papillon » Mon Oct 21, 2002 9:36 pm

*Bump ?*

Papillon
Team Member; Retired with Honors
 
Posts: 3155
Joined: Thu Jul 18, 2002 11:17 pm

PostAuthor: Orleron » Tue Oct 22, 2002 7:23 pm

Looks cool, wanna try it out in the Warzone first to see if it works well? Go ahead and try that.
"Truth has no form."
--Idries Shah

World of Avlis Page

Avlis Project FAQ
User avatar
Orleron
World Advisor, Co-founder
World Advisor, Co-founder
 
Posts: 14905
Joined: Fri Sep 14, 2001 9:48 pm
Timezone: GMT-5


Return to NWN Scripting

Who is online

Registered users: Bing [Bot], Google [Bot], Sunscream, Tel