This is a script to create an automatic
TrashCan object that will keep your areas clean of unwanted loot that people
didn't pick up (such as countless fire beetle bellies, etc.).
To use it, create a blueprint of an invisible object and put it in your
palette. Name it "TrashCan". Then, attach the following script to
onHeartbeat event, and the TrashCan is ready.
Now, simply put an instance of this TrashCan on every zone that you want to
keep clean, and you're done. If you read the script you can easily adjust
how long loot stays on the ground. Currently it defaults to 20 heartbeats.
NWScript:
void TrashObject(object obj)
{
if (GetHasInventory(obj) == FALSE) {
DestroyObject(obj);
} else {
object oItem = GetFirstItemInInventory(obj);
while (oItem != OBJECT_INVALID)
{
TrashObject(oItem);
oItem = GetNextItemInInventory(obj);
}
DestroyObject(obj);
}
}
void main()
{
int iItemDropLifeSpan = 20;
int iCounterMax = 1000;
string sTrashMark = "iTrashMark";
int iCounter = GetLocalInt(OBJECT_SELF, "iCounter");
iCounter++;
iCounter = iCounter % iCounterMax;
if (iCounter == 0) { iCounter++; }
SetLocalInt(OBJECT_SELF, "iCounter", iCounter);
object obj = GetFirstObjectInArea();
while (obj != OBJECT_INVALID)
{
int iObjType = GetObjectType(obj);
if (iObjType == OBJECT_TYPE_PLACEABLE)
{
string sTag = GetTag(obj);
if (sTag == "Body Bag")
{
int iTrashMark = GetLocalInt(obj, sTrashMark);
if (iTrashMark == 0) {
SetLocalInt(obj, sTrashMark, iCounter);
} else {
int iTimeAlive = 0;
if (iCounter >= iTrashMark) {
iTimeAlive = iCounter - iTrashMark;
} else {
iTimeAlive = iCounterMax - iTrashMark + iCounter - 1;
}
if (iTimeAlive > iItemDropLifeSpan) {
TrashObject(obj);
}
}
}
}
obj = GetNextObjectInArea();
}
}
|