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 */
}
}